diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b45b4e925..eafdadd86 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -152,3 +152,4 @@ From oldest to newest contributor, we would like to thank: - [Pierre Bayerl](https://github.com/goto40) - [James Touton](https://github.com/Bekenn) - [Waqar Ahmed](https://github.com/waqar144) +- [Niles Salter](https://github.com/Validark) diff --git a/compiler-args-app.ts b/compiler-args-app.ts index d866b0db9..e7a621215 100644 --- a/compiler-args-app.ts +++ b/compiler-args-app.ts @@ -61,6 +61,7 @@ const compilerParsers = { ghc: Parsers.GHCParser, tendra: Parsers.TendraParser, golang: Parsers.GolangParser, + zig: Parsers.ZigParser, }; class CompilerArgsApp { @@ -119,6 +120,8 @@ class CompilerArgsApp { console.log('supportsTargetIs'); } else if (parser.hasSupportStartsWith(options, '--target ')) { console.log('supportsTarget'); + } else if (parser.hasSupportStartsWith(options, '-target ')) { + console.log('supportsHyphenTarget'); } else if (parser.hasSupportStartsWith(options, '--march=')) { console.log('supportsMarch'); } else { diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 07c96d948..591b10985 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -3667,7 +3667,7 @@ but nothing was dumped. Possible causes are: if (this.compiler.supportsMarch) return [`-march=${c_value_placeholder}`]; if (this.compiler.supportsTargetIs) return [`--target=${c_value_placeholder}`]; if (this.compiler.supportsTarget) return ['--target', c_value_placeholder]; - + if (this.compiler.supportsHyphenTarget) return ['-target', c_value_placeholder]; return []; } @@ -3676,7 +3676,7 @@ but nothing was dumped. Possible causes are: if (this.compiler.supportsMarch) all.push([`-march=${c_value_placeholder}`]); if (this.compiler.supportsTargetIs) all.push([`--target=${c_value_placeholder}`]); if (this.compiler.supportsTarget) all.push(['--target', c_value_placeholder]); - + if (this.compiler.supportsHyphenTarget) all.push(['-target', c_value_placeholder]); return all; } diff --git a/lib/compilers/argument-parsers.ts b/lib/compilers/argument-parsers.ts index a919bdced..2e1600a44 100644 --- a/lib/compilers/argument-parsers.ts +++ b/lib/compilers/argument-parsers.ts @@ -1061,6 +1061,16 @@ export class WasmtimeParser extends BaseParser { } } +export class ZigParser extends GCCParser { + static override async parse(compiler: BaseCompiler) { + const results = await Promise.all([ZigParser.getOptions(compiler, 'build-obj --help')]); + const options = Object.assign({}, ...results); + await GCCParser.setCompilerSettingsFromOptions(compiler, options); + if (GCCParser.hasSupportStartsWith(options, '-target ')) compiler.compiler.supportsHyphenTarget = true; + return compiler; + } +} + export class ZigCxxParser extends ClangParser { static override getMainHelpOptions(): string[] { return ['c++', '--help']; diff --git a/lib/compilers/zig.ts b/lib/compilers/zig.ts index ce8a04303..4370fff2f 100644 --- a/lib/compilers/zig.ts +++ b/lib/compilers/zig.ts @@ -33,6 +33,7 @@ import type {SelectedLibraryVersion} from '../../types/libraries/libraries.inter import {BaseCompiler} from '../base-compiler.js'; import {CompilationEnvironment} from '../compilation-env.js'; import {asSafeVer} from '../utils.js'; +import {ZigParser} from './argument-parsers.js'; export class ZigCompiler extends BaseCompiler { private readonly self_hosted_cli: boolean; @@ -180,6 +181,10 @@ export class ZigCompiler extends BaseCompiler { return userOptions.filter(option => !forbiddenOptions.test(option)); } + protected override getArgumentParserClass() { + return ZigParser; + } + override isCfgCompiler(): boolean { return true; } diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index 99c90189f..fe99265b2 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -94,6 +94,7 @@ export type CompilerInfo = { supportsMarch?: boolean; supportsTarget?: boolean; supportsTargetIs?: boolean; + supportsHyphenTarget?: boolean; executionWrapper: string; executionWrapperArgs: string[]; postProcess: string[];