mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 07:04:04 -05:00
Don’t add --crate-type to rust compiler options when explicitly specified by user (#8191)
Resolves #8186.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
compilers=rustc
|
||||
supportsBinary=true
|
||||
supportsBinaryObject=true
|
||||
compilerType=rust
|
||||
demangler=c++filt
|
||||
demanglerArgs=--format=rust
|
||||
|
||||
@@ -271,19 +271,22 @@ export class RustCompiler extends BaseCompiler {
|
||||
let options = ['-C', 'debuginfo=2', '-o', this.filename(outputFilename)];
|
||||
|
||||
const userRequestedEmit = _.any(unwrap(userOptions), opt => opt.includes('--emit'));
|
||||
const userRequestedCrateType = _.any(unwrap(userOptions), opt => opt.includes('--crate-type'));
|
||||
const setCrateType = (options, type) =>
|
||||
userRequestedCrateType ? options : options.concat(['--crate-type', type]);
|
||||
if (filters.binary) {
|
||||
options = options.concat(['--crate-type', 'bin']);
|
||||
options = setCrateType(options, 'bin');
|
||||
if (this.amd64linker) {
|
||||
options = options.concat(`-Clinker=${this.amd64linker}`);
|
||||
}
|
||||
} else if (filters.binaryObject) {
|
||||
options = options.concat(['--crate-type', 'lib']);
|
||||
options = setCrateType(options, 'lib');
|
||||
} else {
|
||||
if (!userRequestedEmit) {
|
||||
options = options.concat('--emit', 'asm');
|
||||
}
|
||||
if (filters.intel) options = options.concat('-Cllvm-args=--x86-asm-syntax=intel');
|
||||
options = options.concat(['--crate-type', 'rlib']);
|
||||
options = setCrateType(options, 'rlib');
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -746,6 +746,44 @@ describe('Target hints', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Rust options', () => {
|
||||
let ce: CompilationEnvironment;
|
||||
const executingCompilerInfo = makeFakeCompilerInfo({
|
||||
remote: {
|
||||
target: '',
|
||||
path: '',
|
||||
cmakePath: '',
|
||||
basePath: '/',
|
||||
},
|
||||
semver: 'nightly',
|
||||
lang: 'rust',
|
||||
ldPath: [],
|
||||
libPath: [],
|
||||
supportsExecute: true,
|
||||
supportsBinary: true,
|
||||
options: '',
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
ce = makeCompilationEnvironment({
|
||||
languages,
|
||||
});
|
||||
props.initialize(path.resolve('./test/test-properties/rust'), ['local']);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
props.reset();
|
||||
});
|
||||
|
||||
it('does not pass `--crate-type` when specified by user', () => {
|
||||
const compiler = new RustCompiler(executingCompilerInfo, ce);
|
||||
const options = compiler.optionsForFilter({}, 'output.o', ['--crate-type=bin']);
|
||||
expect(options).not.toContain('--crate-type');
|
||||
const optionsTwoArgs = compiler.optionsForFilter({}, 'output.o', ['--crate-type', 'bin']);
|
||||
expect(optionsTwoArgs).not.toContain('--crate-type');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Rust overrides', () => {
|
||||
let ce: CompilationEnvironment;
|
||||
const executingCompilerInfo = makeFakeCompilerInfo({
|
||||
|
||||
Reference in New Issue
Block a user