Use the same compiler stage for tests and executables

This commit is contained in:
Martin Wickham 2022-11-27 17:29:47 -06:00
parent 9b70de21c7
commit 6ddc9f5c19

View file

@ -2,19 +2,28 @@ const std = @import("std");
const Builder = std.build.Builder; const Builder = std.build.Builder;
const LibExeObjStep = std.build.LibExeObjStep; const LibExeObjStep = std.build.LibExeObjStep;
// set this to true to link libc const required_zig_version = std.SemanticVersion.parse("0.10.0") catch unreachable;
const padded_int_fix = std.SemanticVersion.parse("0.11.0-dev.331+304e82808") catch unreachable;
/// set this to true to link libc
const should_link_libc = false; const should_link_libc = false;
fn linkObject(b: *Builder, obj: *LibExeObjStep) void { fn linkObject(b: *Builder, obj: *LibExeObjStep) void {
if (should_link_libc) obj.linkLibC(); if (should_link_libc) obj.linkLibC();
_ = b; _ = b;
// Padded integers are buggy in 0.10.0, fixed in 0.11.0-dev.331+304e82808
// This is especially bad for AoC because std.StaticBitSet is commonly used.
// If your version is older than that, we use stage1 to avoid this bug.
// Issue: https://github.com/ziglang/zig/issues/13480
// Fix: https://github.com/ziglang/zig/pull/13637
if (comptime @import("builtin").zig_version.order(padded_int_fix) == .lt) {
obj.use_stage1 = true;
}
// Add linking for packages or third party libraries here // Add linking for packages or third party libraries here
} }
const required_zig_version = std.SemanticVersion.parse("0.10.0") catch unreachable;
const padded_int_fix = std.SemanticVersion.parse("0.11.0-dev.331+304e82808") catch unreachable;
pub fn build(b: *Builder) void { pub fn build(b: *Builder) void {
if (comptime @import("builtin").zig_version.order(required_zig_version) == .lt) { if (comptime @import("builtin").zig_version.order(required_zig_version) == .lt) {
std.debug.print( std.debug.print(
@ -59,16 +68,6 @@ pub fn build(b: *Builder) void {
exe.setTarget(target); exe.setTarget(target);
exe.setBuildMode(mode); exe.setBuildMode(mode);
linkObject(b, exe); linkObject(b, exe);
// Padded integers are buggy in 0.10.0, fixed in 0.11.0-dev.331+304e82808
// This is especially bad for AoC because std.StaticBitSet is commonly used.
// If your version is older than that, we use stage1 to avoid this bug.
// Issue: https://github.com/ziglang/zig/issues/13480
// Fix: https://github.com/ziglang/zig/pull/13637
if (comptime @import("builtin").zig_version.order(padded_int_fix) == .lt) {
exe.use_stage1 = true;
}
exe.install(); exe.install();
const install_cmd = b.addInstallArtifact(exe); const install_cmd = b.addInstallArtifact(exe);