| author | |
| committer | |
| log | 2f41109cc445c450029ea81c0da6873f32fa0981 |
| tree | 2f8af23b4d8fcf7ef4db73254a37340bfedef0b1 |
| parent | b14f605dd7b808d1e6d3ee1f8d545135ebe296ee |
| signature |
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 { | ... | @@ -33,6 +33,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { |
| 33 | .requires_stage2 = true, | 33 | .requires_stage2 = true, |
| 34 | }); | 34 | }); |
| 35 | 35 | ||
| 36 | cases.addBuildFile("test/link/wasm/basic-features/build.zig", .{ | ||
| 37 | .requires_stage2 = true, | ||
| 38 | }); | ||
| 39 | |||
| 36 | cases.addBuildFile("test/link/wasm/bss/build.zig", .{ | 40 | cases.addBuildFile("test/link/wasm/bss/build.zig", .{ |
| 37 | .build_modes = false, | 41 | .build_modes = false, |
| 38 | .requires_stage2 = true, | 42 | .requires_stage2 = true, |
| ... | @@ -44,6 +48,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { | ... | @@ -44,6 +48,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void { |
| 44 | .use_emulation = true, | 48 | .use_emulation = true, |
| 45 | }); | 49 | }); |
| 46 | 50 | ||
| 51 | cases.addBuildFile("test/link/wasm/infer-features/build.zig", .{ | ||
| 52 | .requires_stage2 = true, | ||
| 53 | }); | ||
| 54 | |||
| 47 | cases.addBuildFile("test/link/wasm/producers/build.zig", .{ | 55 | cases.addBuildFile("test/link/wasm/producers/build.zig", .{ |
| 48 | .build_modes = true, | 56 | .build_modes = true, |
| 49 | .requires_stage2 = true, | 57 | .requires_stage2 = true, |
test/link/wasm/basic-features/build.zig created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub 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 @@ | ||
| 1 | export fn foo() void {} | ||
test/link/wasm/infer-features/build.zig created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub 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 @@ | ||
| 1 | int foo() { | ||
| 2 | return 5; | ||
| 3 | } | ||
test/link/wasm/infer-features/main.zig created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | extern fn foo() c_int; | ||