From 685f68450a375287010e59c31e0e7c0d0095e29a Mon Sep 17 00:00:00 2001 From: narpfel Date: Mon, 13 Oct 2025 21:16:01 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20add=20`--crate-type`=20to=20rus?= =?UTF-8?q?t=20compiler=20options=20when=20explicitly=20specified=20by=20u?= =?UTF-8?q?ser=20(#8191)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves #8186. --- etc/config/rust.defaults.properties | 1 + lib/compilers/rust.ts | 9 ++++--- test/base-compiler-tests.ts | 38 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/etc/config/rust.defaults.properties b/etc/config/rust.defaults.properties index 97f12bdc1..63cdf19f3 100644 --- a/etc/config/rust.defaults.properties +++ b/etc/config/rust.defaults.properties @@ -1,5 +1,6 @@ compilers=rustc supportsBinary=true +supportsBinaryObject=true compilerType=rust demangler=c++filt demanglerArgs=--format=rust diff --git a/lib/compilers/rust.ts b/lib/compilers/rust.ts index 39c48af5e..7f2ea559d 100644 --- a/lib/compilers/rust.ts +++ b/lib/compilers/rust.ts @@ -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; } diff --git a/test/base-compiler-tests.ts b/test/base-compiler-tests.ts index 59cb971f8..b1eaf0c84 100644 --- a/test/base-compiler-tests.ts +++ b/test/base-compiler-tests.ts @@ -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({