mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
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.
This commit is contained in:
parent
b14f605dd7
commit
2f41109cc4
@ -33,6 +33,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
|
||||
.requires_stage2 = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/basic-features/build.zig", .{
|
||||
.requires_stage2 = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/bss/build.zig", .{
|
||||
.build_modes = false,
|
||||
.requires_stage2 = true,
|
||||
@ -44,6 +48,10 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
|
||||
.use_emulation = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/infer-features/build.zig", .{
|
||||
.requires_stage2 = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/producers/build.zig", .{
|
||||
.build_modes = true,
|
||||
.requires_stage2 = true,
|
||||
|
23
test/link/wasm/basic-features/build.zig
Normal file
23
test/link/wasm/basic-features/build.zig
Normal file
@ -0,0 +1,23 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
// Library with explicitly set cpu features
|
||||
const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
|
||||
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
|
||||
lib.target.cpu_features_add.addFeature(0); // index 0 == atomics (see std.Target.wasm.Features)
|
||||
lib.setBuildMode(mode);
|
||||
lib.use_llvm = false;
|
||||
lib.use_lld = false;
|
||||
|
||||
// Verify the result contains the features explicitly set on the target for the library.
|
||||
const check = lib.checkObject(.wasm);
|
||||
check.checkStart("name target_features");
|
||||
check.checkNext("features 1");
|
||||
check.checkNext("+ atomics");
|
||||
|
||||
const test_step = b.step("test", "Run linker test");
|
||||
test_step.dependOn(&check.step);
|
||||
}
|
1
test/link/wasm/basic-features/main.zig
Normal file
1
test/link/wasm/basic-features/main.zig
Normal file
@ -0,0 +1 @@
|
||||
export fn foo() void {}
|
37
test/link/wasm/infer-features/build.zig
Normal file
37
test/link/wasm/infer-features/build.zig
Normal file
@ -0,0 +1,37 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
// Wasm Object file which we will use to infer the features from
|
||||
const c_obj = b.addObject("c_obj", null);
|
||||
c_obj.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
c_obj.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge };
|
||||
c_obj.addCSourceFile("foo.c", &.{});
|
||||
c_obj.setBuildMode(mode);
|
||||
|
||||
// Wasm library that doesn't have any features specified. This will
|
||||
// infer its featureset from other linked object files.
|
||||
const lib = b.addSharedLibrary("lib", "main.zig", .unversioned);
|
||||
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
lib.target.cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp };
|
||||
lib.setBuildMode(mode);
|
||||
lib.use_llvm = false;
|
||||
lib.use_lld = false;
|
||||
lib.addObject(c_obj);
|
||||
|
||||
// Verify the result contains the features from the C Object file.
|
||||
const check = lib.checkObject(.wasm);
|
||||
check.checkStart("name target_features");
|
||||
check.checkNext("features 7");
|
||||
check.checkNext("+ atomics");
|
||||
check.checkNext("+ bulk-memory");
|
||||
check.checkNext("+ mutable-globals");
|
||||
check.checkNext("+ nontrapping-fptoint");
|
||||
check.checkNext("+ sign-ext");
|
||||
check.checkNext("+ simd128");
|
||||
check.checkNext("+ tail-call");
|
||||
|
||||
const test_step = b.step("test", "Run linker test");
|
||||
test_step.dependOn(&check.step);
|
||||
}
|
3
test/link/wasm/infer-features/foo.c
Normal file
3
test/link/wasm/infer-features/foo.c
Normal file
@ -0,0 +1,3 @@
|
||||
int foo() {
|
||||
return 5;
|
||||
}
|
1
test/link/wasm/infer-features/main.zig
Normal file
1
test/link/wasm/infer-features/main.zig
Normal file
@ -0,0 +1 @@
|
||||
extern fn foo() c_int;
|
Loading…
Reference in New Issue
Block a user