| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | pub fn build(b: *Build) void { |
| 2 | const test_step = b.step("test", "Test the new ELF linker"); |
| 3 | b.default_step = test_step; |
| 4 | |
| 5 | if (b.graph.host.result.cpu.arch == .x86_64 and b.graph.host.result.os.tag == .linux) { |
| 6 | addOne(b, test_step, b.graph.host, false, .static, "elf2-hello-native-selfhosted-static"); |
| 7 | addOne(b, test_step, b.graph.host, false, .dynamic, "elf2-hello-native-selfhosted-dynamic"); |
| 8 | addOne(b, test_step, b.graph.host, true, .static, "elf2-hello-native-llvm-static"); |
| 9 | addOne(b, test_step, b.graph.host, true, .dynamic, "elf2-hello-native-llvm-dynamic"); |
| 10 | } |
| 11 | |
| 12 | const x86_64_linux_target: Build.ResolvedTarget = b.resolveTargetQuery(.{ |
| 13 | .cpu_arch = .x86_64, |
| 14 | .os_tag = .linux, |
| 15 | }); |
| 16 | addOne(b, test_step, x86_64_linux_target, false, .static, "elf2-hello-selfhosted-static"); |
| 17 | addOne(b, test_step, x86_64_linux_target, true, .static, "elf2-hello-llvm-static"); |
| 18 | } |
| 19 | |
| 20 | fn addOne( |
| 21 | b: *Build, |
| 22 | test_step: *Build.Step, |
| 23 | target: Build.ResolvedTarget, |
| 24 | use_llvm: bool, |
| 25 | link_mode: std.lang.LinkMode, |
| 26 | name: []const u8, |
| 27 | ) void { |
| 28 | const mod = b.createModule(.{ |
| 29 | .root_source_file = b.path("hello.zig"), |
| 30 | .target = target, |
| 31 | .optimize = .Debug, |
| 32 | .link_libc = link_mode == .dynamic, |
| 33 | }); |
| 34 | const exe = b.addExecutable(.{ |
| 35 | .name = name, |
| 36 | .root_module = mod, |
| 37 | .linkage = link_mode, |
| 38 | }); |
| 39 | exe.use_new_linker = true; |
| 40 | exe.use_llvm = use_llvm; |
| 41 | |
| 42 | const run = b.addRunArtifact(exe); |
| 43 | run.expectExitCode(0); |
| 44 | run.expectStdOutEqual("Hello, World!\n"); |
| 45 | run.skip_foreign_checks = true; |
| 46 | |
| 47 | test_step.dependOn(&run.step); |
| 48 | } |
| 49 | |
| 50 | const std = @import("std"); |
| 51 | const Build = std.Build; |