diff options
author | Rubén Rincón Blanco <ruben@rinconblanco.es> | 2022-04-26 15:24:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 15:24:40 +0200 |
commit | 4965bd6c8101001dd124df38b3da43cdc2c360a4 (patch) | |
tree | 4d7e8133219f88e3e6361cceea9bebb84b62ab02 /lib/compilers/zig.js | |
parent | e3b9039095333ae3cdec1b9f47419ebac33b6fec (diff) | |
download | compiler-explorer-4965bd6c8101001dd124df38b3da43cdc2c360a4.tar.gz compiler-explorer-4965bd6c8101001dd124df38b3da43cdc2c360a4.zip |
All semver comparisons now ensure it's safe to do so (#3562)
* All semver comparisons now ensure it's safe to do so
* Oops, use correct class
* Remove leftover import
* Leave the Zig fixes for another PR
* Fix linter
* Fix test issues
* Make linter happy, yet again
* What?
* Address PR review
Diffstat (limited to 'lib/compilers/zig.js')
-rw-r--r-- | lib/compilers/zig.js | 68 |
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) { |