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.
This commit is contained in:
Luuk de Gram 2022-08-20 15:46:39 +02:00
parent 1544625df3
commit 7fe2a3d104
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
4 changed files with 39 additions and 6 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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);
}

View File

@ -0,0 +1,6 @@
export fn foo() void {
var a: f16 = 2.2;
// this will pull-in compiler-rt
var b = @trunc(a);
_ = b;
}