authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-23 20:00:27+02:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-10-25 20:48:08+02:00
log2f41109cc445c450029ea81c0da6873f32fa0981
tree2f8af23b4d8fcf7ef4db73254a37340bfedef0b1
parentb14f605dd7b808d1e6d3ee1f8d545135ebe296ee
signaturelock-open Commit is signed but in an unrecognized format.

test/link: add Wasm linker tests for features

Adds a test for inferring features based on a different object file. Also provides a test case where cpu features are explicitly set on a library where the end result will output said target features.

6 files changed, 73 insertions(+), 0 deletions(-)

test/link.zig+8
......@@ -33,6 +33,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
3333 .requires_stage2 = true,
3434 });
3535
36 cases.addBuildFile("test/link/wasm/basic-features/build.zig", .{
37 .requires_stage2 = true,
38 });
39
3640 cases.addBuildFile("test/link/wasm/bss/build.zig", .{
3741 .build_modes = false,
3842 .requires_stage2 = true,
......@@ -44,6 +48,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
4448 .use_emulation = true,
4549 });
4650
51 cases.addBuildFile("test/link/wasm/infer-features/build.zig", .{
52 .requires_stage2 = true,
53 });
54
4755 cases.addBuildFile("test/link/wasm/producers/build.zig", .{
4856 .build_modes = true,
4957 .requires_stage2 = true,
test/link/wasm/basic-features/build.zig created+23
......@@ -0,0 +1,23 @@
1const std = @import("std");
2
3pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
5
6 // Library with explicitly set cpu features
7 const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
8 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
9 lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
10 lib.target.cpu_features_add.addFeature(0); // index 0 == atomics (see std.Target.wasm.Features)
11 lib.setBuildMode(mode);
12 lib.use_llvm = false;
13 lib.use_lld = false;
14
15 // Verify the result contains the features explicitly set on the target for the library.
16 const check = lib.checkObject(.wasm);
17 check.checkStart("name target_features");
18 check.checkNext("features 1");
19 check.checkNext("+ atomics");
20
21 const test_step = b.step("test", "Run linker test");
22 test_step.dependOn(&check.step);
23}
test/link/wasm/basic-features/main.zig created+1
......@@ -0,0 +1 @@
1export fn foo() void {}
test/link/wasm/infer-features/build.zig created+37
......@@ -0,0 +1,37 @@
1const std = @import("std");
2
3pub fn build(b: *std.build.Builder) void {
4 const mode = b.standardReleaseOptions();
5
6 // Wasm Object file which we will use to infer the features from
7 const c_obj = b.addObject("c_obj", null);
8 c_obj.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
9 c_obj.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge };
10 c_obj.addCSourceFile("foo.c", &.{});
11 c_obj.setBuildMode(mode);
12
13 // Wasm library that doesn't have any features specified. This will
14 // infer its featureset from other linked object files.
15 const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
16 lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
17 lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
18 lib.setBuildMode(mode);
19 lib.use_llvm = false;
20 lib.use_lld = false;
21 lib.addObject(c_obj);
22
23 // Verify the result contains the features from the C Object file.
24 const check = lib.checkObject(.wasm);
25 check.checkStart("name target_features");
26 check.checkNext("features 7");
27 check.checkNext("+ atomics");
28 check.checkNext("+ bulk-memory");
29 check.checkNext("+ mutable-globals");
30 check.checkNext("+ nontrapping-fptoint");
31 check.checkNext("+ sign-ext");
32 check.checkNext("+ simd128");
33 check.checkNext("+ tail-call");
34
35 const test_step = b.step("test", "Run linker test");
36 test_step.dependOn(&check.step);
37}
test/link/wasm/infer-features/foo.c created+3
......@@ -0,0 +1,3 @@
1int foo() {
2 return 5;
3}
test/link/wasm/infer-features/main.zig created+1
......@@ -0,0 +1 @@
1extern fn foo() c_int;