aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/zig.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compilers/zig.js')
-rw-r--r--lib/compilers/zig.js68
1 files changed, 39 insertions, 29 deletions
diff --git a/lib/compilers/zig.js b/lib/compilers/zig.js
index a92f70f68..3903f7aa9 100644
--- a/lib/compilers/zig.js
+++ b/lib/compilers/zig.js
@@ -27,18 +27,22 @@ import path from 'path';
import Semver from 'semver';
import _ from 'underscore';
-import { BaseCompiler } from '../base-compiler';
+import {BaseCompiler} from '../base-compiler';
+import {asSafeVer} from '../utils';
export class ZigCompiler extends BaseCompiler {
- static get key() { return 'zig'; }
+ static get key() {
+ return 'zig';
+ }
constructor(info, env) {
super(info, env);
this.compiler.supportsIntel = true;
this.compiler.supportsIrView = true;
- this.self_hosted_cli = this.compiler.semver === 'trunk' ||
- (this.compiler.semver && Semver.gt(this.compiler.semver, '0.6.0'));
+ this.self_hosted_cli =
+ this.compiler.semver === 'trunk' ||
+ (this.compiler.semver && Semver.gt(asSafeVer(this.compiler.semver), '0.6.0', true));
if (this.self_hosted_cli) {
this.compiler.irArg = ['-femit-llvm-ir'];
@@ -52,25 +56,28 @@ export class ZigCompiler extends BaseCompiler {
}
preProcess(source) {
- const olderStdVersions = ['0.3.0', '0.4.0', '0.5.0', '0.6.0', '0.7.0', '0.7.1'];
- if (this.compiler.semver === '0.2.0') {
+ if (Semver.eq(asSafeVer(this.compiler.semver), '0.2.0', true)) {
source += '\n';
source += 'extern fn zig_panic() noreturn;\n';
- source += 'pub fn panic(msg: []const u8, error_return_trace: ' +
- '?&@import("builtin").StackTrace) noreturn {\n';
+ source +=
+ 'pub fn panic(msg: []const u8, error_return_trace: ?&@import("builtin").StackTrace) noreturn {\n';
source += ' zig_panic();\n';
source += '}\n';
- } else if (olderStdVersions.includes(this.compiler.semver)) {
+ } else if (
+ Semver.gte(asSafeVer(this.compiler.semver), '0.3.0', true) &&
+ Semver.lte(asSafeVer(this.compiler.semver), '0.7.1', true)
+ ) {
source += '\n';
source += 'extern fn zig_panic() noreturn;\n';
- source += 'pub fn panic(msg: []const u8, error_return_trace: ' +
- '?*@import("builtin").StackTrace) noreturn {\n';
+ source +=
+ 'pub fn panic(msg: []const u8, error_return_trace: ?*@import("builtin").StackTrace) noreturn {\n';
source += ' zig_panic();\n';
source += '}\n';
} else {
source += '\n';
source += 'extern fn zig_panic() noreturn;\n';
- source += 'pub fn panic(msg: []const u8, error_return_trace: ' +
+ source +=
+ 'pub fn panic(msg: []const u8, error_return_trace: ' +
'?*@import("std").builtin.StackTrace) noreturn {\n';
source += ' _ = msg;\n';
source += ' _ = error_return_trace;\n';
@@ -91,8 +98,7 @@ export class ZigCompiler extends BaseCompiler {
if (this.self_hosted_cli) {
// Versions after 0.6.0 use a different command line interface.
const outputDir = path.dirname(outputFilename);
- options.push('--cache-dir', outputDir,
- '--name', name);
+ options.push('--cache-dir', outputDir, '--name', name);
if (!filters.binary) {
options.push('-fno-emit-bin', '-femit-asm=' + desiredName);
@@ -102,16 +108,19 @@ export class ZigCompiler extends BaseCompiler {
return options;
}
- if (this.compiler.semver && Semver.gt(this.compiler.semver, '0.3.0')) {
+ if (this.compiler.semver && Semver.gt(asSafeVer(this.compiler.semver), '0.3.0', true)) {
const outputDir = path.dirname(outputFilename);
- options.push('--cache-dir', outputDir,
- '--output-dir', outputDir,
- '--name', name);
+ options.push('--cache-dir', outputDir, '--output-dir', outputDir, '--name', name);
} else {
// Older versions use a different command line interface (#1304)
- options.push('--cache-dir', path.dirname(outputFilename),
- '--output', this.filename(outputFilename),
- '--output-h', '/dev/null');
+ options.push(
+ '--cache-dir',
+ path.dirname(outputFilename),
+ '--output',
+ this.filename(outputFilename),
+ '--output-h',
+ '/dev/null'
+ );
}
if (!filters.binary) {
@@ -125,17 +134,18 @@ export class ZigCompiler extends BaseCompiler {
}
getIncludeArguments(libraries) {
- return _.flatten(_.map(libraries, (selectedLib) => {
- const foundVersion = this.findLibVersion(selectedLib);
- if (!foundVersion) return false;
- // Zig should not have more than 1 path
- return ['--pkg-begin', foundVersion.name, foundVersion.path, '--pkg-end'];
- }));
+ return _.flatten(
+ _.map(libraries, selectedLib => {
+ const foundVersion = this.findLibVersion(selectedLib);
+ if (!foundVersion) return false;
+ // Zig should not have more than 1 path
+ return ['--pkg-begin', foundVersion.name, foundVersion.path, '--pkg-end'];
+ })
+ );
}
getIrOutputFilename(inputFilename) {
- return this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase)
- .replace('.s', '.ll');
+ return this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase).replace('.s', '.ll');
}
filterUserOptions(userOptions) {