mlugg 8aab222ffb Compilation: add missing link file options to cache manifest
Also add a standalone test which covers the `-fentry` case. It does this
by performing two reproducible compilations which are identical other
than having different entry points, and checking whether the emitted
binaries are identical (they should *not* be).

Resolves: #23869
2025-06-17 15:33:50 +01:00

47 lines
1.8 KiB
Zig

pub fn build(b: *std.Build) !void {
const mod = b.createModule(.{
// Setting the entry point doesn't work properly on all targets right now. Since we're
// really just trying to make sure that the compiler *frontend* respects `-fentry` and
// includes it in the cache manifest, just test for a target where it works.
.target = b.resolveTargetQuery(try .parse(.{
.arch_os_abi = "x86_64-linux",
})),
.optimize = .ReleaseFast, // non-Debug build for reproducible output
.root_source_file = b.path("main.zig"),
});
const exe_foo = b.addExecutable(.{
.name = "the_exe", // same name for reproducible output
.root_module = mod,
});
exe_foo.entry = .{ .symbol_name = "foo" };
const exe_bar = b.addExecutable(.{
.name = "the_exe", // same name for reproducible output
.root_module = mod,
});
exe_bar.entry = .{ .symbol_name = "bar" };
// Despite the output binary being reproducible, the `entry` differed, so the emitted binaries
// should be different. But the two compilations are otherwise identical, so if `entry` isn't
// being respected properly, we will see identical binaries.
const check_differ_exe = b.addExecutable(.{
.name = "check_differ",
.root_module = b.createModule(.{
.target = b.graph.host,
.optimize = .Debug,
.root_source_file = b.path("check_differ.zig"),
}),
});
const diff_cmd = b.addRunArtifact(check_differ_exe);
diff_cmd.addFileArg(exe_foo.getEmittedBin());
diff_cmd.addFileArg(exe_bar.getEmittedBin());
diff_cmd.expectExitCode(0);
const test_step = b.step("test", "Test it");
b.default_step = test_step;
test_step.dependOn(&diff_cmd.step);
}
const std = @import("std");