aboutsummaryrefslogtreecommitdiff
path: root/test/standalone/entry_point/build.zig
blob: 42ba6211ae24faefec2f69117f54a559d6373a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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");