diff options
Diffstat (limited to 'lib/compilers/rust.ts')
-rw-r--r-- | lib/compilers/rust.ts | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/compilers/rust.ts b/lib/compilers/rust.ts index 09fba6952..98683f6d9 100644 --- a/lib/compilers/rust.ts +++ b/lib/compilers/rust.ts @@ -35,6 +35,8 @@ import type {BuildEnvDownloadInfo} from '../buildenvsetup/buildenv.interfaces.js import {parseRustOutput} from '../utils.js'; import {RustParser} from './argument-parsers.js'; +import {CompilerOverrideType} from '../../types/compilation/compiler-overrides.interfaces.js'; +import {SemVer} from 'semver'; export class RustCompiler extends BaseCompiler { linker: string; @@ -50,19 +52,60 @@ export class RustCompiler extends BaseCompiler { this.compiler.supportsLLVMOptPipelineView = true; this.compiler.supportsRustMirView = true; - const isNightly = info.name === 'nightly' || info.semver === 'nightly'; + const isNightly = this.isNightly(); // Macro expansion (-Zunpretty=expanded) and HIR (-Zunpretty=hir-tree) // are only available for Nightly this.compiler.supportsRustMacroExpView = isNightly; this.compiler.supportsRustHirView = isNightly; this.compiler.irArg = ['--emit', 'llvm-ir']; + this.compiler.minIrArgs = ['--emit=llvm-ir']; this.compiler.llvmOptArg = ['-C', 'llvm-args=-print-after-all -print-before-all']; this.compiler.llvmOptModuleScopeArg = ['-C', 'llvm-args=-print-module-scope']; this.compiler.llvmOptNoDiscardValueNamesArg = isNightly ? ['-Z', 'fewer-names=no'] : []; this.linker = this.compilerProps<string>('linker'); } + private isNightly() { + return ( + this.compiler.name === 'nightly' || + this.compiler.semver === 'nightly' || + this.compiler.semver === 'beta' || + this.compiler.semver.includes('master') || + this.compiler.semver.includes('trunk') + ); + } + + override async populatePossibleOverrides() { + const possibleEditions = await RustParser.getPossibleEditions(this); + if (possibleEditions.length > 0) { + let defaultEdition: undefined | string = undefined; + if (!this.compiler.semver || this.isNightly()) { + defaultEdition = '2021'; + } else { + const compilerVersion = new SemVer(this.compiler.semver); + if (compilerVersion.compare('1.56.0') >= 0) { + defaultEdition = '2021'; + } + } + + this.compiler.possibleOverrides?.push({ + name: CompilerOverrideType.edition, + display_title: 'Edition', + description: + 'The default edition for Rust compilers is usually 2015. ' + + 'Some editions might not be available for older compilers.', + flags: ['--edition', '<value>'], + values: possibleEditions.map(ed => { + return {name: ed, value: ed}; + }), + default: defaultEdition, + }); + } + + await super.populatePossibleOverrides(); + } + override getSharedLibraryPathsAsArguments(libraries, libDownloadPath) { return []; } |