[Zig] Fix target/arch parsing so assembly docs query the correct ISA (#7363)

This commit is contained in:
Niles Salter
2025-02-16 00:18:18 +00:00
committed by GitHub
parent 55cf8f519c
commit bbdad0fe8e
6 changed files with 22 additions and 2 deletions

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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;
}

View File

@@ -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'];

View File

@@ -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;
}

View File

@@ -94,6 +94,7 @@ export type CompilerInfo = {
supportsMarch?: boolean;
supportsTarget?: boolean;
supportsTargetIs?: boolean;
supportsHyphenTarget?: boolean;
executionWrapper: string;
executionWrapperArgs: string[];
postProcess: string[];