From 7fe2a3d104319835127456d02ba73efc5fe5f207 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sat, 20 Aug 2022 15:46:39 +0200 Subject: [PATCH] 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. --- lib/std/build.zig | 7 +------ test/link.zig | 5 +++++ test/link/wasm/archive/build.zig | 27 +++++++++++++++++++++++++++ test/link/wasm/archive/main.zig | 6 ++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 test/link/wasm/archive/build.zig create mode 100644 test/link/wasm/archive/main.zig diff --git a/lib/std/build.zig b/lib/std/build.zig index 57f0d126d8..1cbf188d2c 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -1898,12 +1898,7 @@ pub const LibExeObjStep = struct { pub fn runEmulatable(exe: *LibExeObjStep) *EmulatableRunStep { assert(exe.kind == .exe or exe.kind == .test_exe); - const run_step = EmulatableRunStep.create(exe.builder.fmt("run {s}", .{exe.step.name}), exe); - if (exe.vcpkg_bin_path) |path| { - run_step.addPathDir(path); - } - - return run_step; + return EmulatableRunStep.create(exe.builder, exe.builder.fmt("run {s}", .{exe.step.name}), exe); } pub fn checkObject(self: *LibExeObjStep, obj_format: std.Target.ObjectFormat) *CheckObjectStep { diff --git a/test/link.zig b/test/link.zig index 88b370f343..215a0511fc 100644 --- a/test/link.zig +++ b/test/link.zig @@ -47,6 +47,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { .build_modes = true, .requires_stage2 = true, }); + + cases.addBuildFile("test/link/wasm/archive/build.zig", .{ + .build_modes = true, + .requires_stage2 = true, + }); } fn addMachOCases(cases: *tests.StandaloneContext) void { diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig new file mode 100644 index 0000000000..95ce444659 --- /dev/null +++ b/test/link/wasm/archive/build.zig @@ -0,0 +1,27 @@ +const std = @import("std"); +const Builder = std.build.Builder; + +pub fn build(b: *Builder) void { + const mode = b.standardReleaseOptions(); + + const test_step = b.step("test", "Test"); + test_step.dependOn(b.getInstallStep()); + + // The code in question will pull-in compiler-rt, + // and therefore link with its archive file. + const lib = b.addSharedLibrary("main", "main.zig", .unversioned); + lib.setBuildMode(mode); + lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); + lib.use_llvm = false; + lib.use_stage1 = false; + lib.use_lld = false; + + const check = lib.checkObject(.wasm); + check.checkStart("Section import"); + check.checkNext("entries 1"); // __truncsfhf2 should have been resolved, so only 1 import (compiler-rt's memcpy). + + check.checkStart("Section custom"); + check.checkNext("name __truncsfhf2"); // Ensure it was imported and resolved + + test_step.dependOn(&check.step); +} diff --git a/test/link/wasm/archive/main.zig b/test/link/wasm/archive/main.zig new file mode 100644 index 0000000000..29be3af0ac --- /dev/null +++ b/test/link/wasm/archive/main.zig @@ -0,0 +1,6 @@ +export fn foo() void { + var a: f16 = 2.2; + // this will pull-in compiler-rt + var b = @trunc(a); + _ = b; +}