| ... | @@ -0,0 +1,53 @@ |
| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub const requires_symlinks = true; |
| 4 | |
| 5 | pub fn build(b: *std.Build) void { |
| 6 | const test_step = b.step("test", "Test it"); |
| 7 | b.default_step = test_step; |
| 8 | |
| 9 | add(b, test_step, .Debug); |
| 10 | add(b, test_step, .ReleaseFast); |
| 11 | add(b, test_step, .ReleaseSmall); |
| 12 | add(b, test_step, .ReleaseSafe); |
| 13 | } |
| 14 | |
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const lib = b.addSharedLibrary(.{ |
| 17 | .name = "bootstrap", |
| 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, |
| 20 | }); |
| 21 | lib.addCSourceFile("bootstrap.c", &.{}); |
| 22 | lib.linkLibC(); |
| 23 | lib.linker_allow_shlib_undefined = true; |
| 24 | |
| 25 | const exe = b.addExecutable(.{ |
| 26 | .name = "main", |
| 27 | .optimize = optimize, |
| 28 | .target = .{ .os_tag = .macos }, |
| 29 | }); |
| 30 | exe.addCSourceFile("main.c", &.{}); |
| 31 | exe.linkLibrary(lib); |
| 32 | exe.linkLibC(); |
| 33 | exe.entry_symbol_name = "_bootstrap"; |
| 34 | |
| 35 | const check_exe = exe.checkObject(); |
| 36 | check_exe.checkStart("segname __TEXT"); |
| 37 | check_exe.checkNext("vmaddr {text_vmaddr}"); |
| 38 | |
| 39 | check_exe.checkStart("sectname __stubs"); |
| 40 | check_exe.checkNext("addr {stubs_vmaddr}"); |
| 41 | |
| 42 | check_exe.checkStart("cmd MAIN"); |
| 43 | check_exe.checkNext("entryoff {entryoff}"); |
| 44 | |
| 45 | check_exe.checkComputeCompare("text_vmaddr entryoff +", .{ |
| 46 | .op = .eq, |
| 47 | .value = .{ .variable = "stubs_vmaddr" }, // The entrypoint should be a synthetic stub |
| 48 | }); |
| 49 | |
| 50 | const run = check_exe.runAndCompare(); |
| 51 | run.expectStdOutEqual("Hello!\n"); |
| 52 | test_step.dependOn(&run.step); |
| 53 | } |