authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-20 15:46:39+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-08-20 15:46:39+02:00
log7fe2a3d104319835127456d02ba73efc5fe5f207
tree5a46464ed29f8e4f5a0654f9adeb3aaa9e10a8ac
parent1544625df3fb4732f2cd63d1e7c4c738d1b7d0c0
signaturelock-open Commit is signed but in an unrecognized format.

test/link: add wasm linker-test for archives

Adds a test case that will pull-in compiler-rt symbols, and therefore link with the compiler-rt archive file.

4 files changed, 39 insertions(+), 6 deletions(-)

lib/std/build.zig+1-6
......@@ -1898,12 +1898,7 @@ pub const LibExeObjStep = struct {
18981898 pub fn runEmulatable(exe: *LibExeObjStep) *EmulatableRunStep {
18991899 assert(exe.kind == .exe or exe.kind == .test_exe);
19001900
1901 const run_step = EmulatableRunStep.create(exe.builder.fmt("run {s}", .{exe.step.name}), exe);
1902 if (exe.vcpkg_bin_path) |path| {
1903 run_step.addPathDir(path);
1904 }
1905
1906 return run_step;
1901 return EmulatableRunStep.create(exe.builder, exe.builder.fmt("run {s}", .{exe.step.name}), exe);
19071902 }
19081903
19091904 pub fn checkObject(self: *LibExeObjStep, obj_format: std.Target.ObjectFormat) *CheckObjectStep {
test/link.zig+5
......@@ -47,6 +47,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
4747 .build_modes = true,
4848 .requires_stage2 = true,
4949 });
50
51 cases.addBuildFile("test/link/wasm/archive/build.zig", .{
52 .build_modes = true,
53 .requires_stage2 = true,
54 });
5055}
5156
5257fn addMachOCases(cases: *tests.StandaloneContext) void {
test/link/wasm/archive/build.zig created+27
......@@ -0,0 +1,27 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6
7 const test_step = b.step("test", "Test");
8 test_step.dependOn(b.getInstallStep());
9
10 // The code in question will pull-in compiler-rt,
11 // and therefore link with its archive file.
12 const lib = b.addSharedLibrary("main", "main.zig", .unversioned);
13 lib.setBuildMode(mode);
14 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
15 lib.use_llvm = false;
16 lib.use_stage1 = false;
17 lib.use_lld = false;
18
19 const check = lib.checkObject(.wasm);
20 check.checkStart("Section import");
21 check.checkNext("entries 1"); // __truncsfhf2 should have been resolved, so only 1 import (compiler-rt's memcpy).
22
23 check.checkStart("Section custom");
24 check.checkNext("name __truncsfhf2"); // Ensure it was imported and resolved
25
26 test_step.dependOn(&check.step);
27}
test/link/wasm/archive/main.zig created+6
......@@ -0,0 +1,6 @@
1export fn foo() void {
2 var a: f16 = 2.2;
3 // this will pull-in compiler-rt
4 var b = @trunc(a);
5 _ = b;
6}