mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 23:05:24 +00:00
test/link: linker tests for all export cases
Adds a linker test case for each possible export case. This means one where no exports are done (i.e. no flags set), when the -dynamic flag is set, and finally when --export=<value> flag(s) are set.
This commit is contained in:
parent
9932372fae
commit
e4869eeac1
@ -42,6 +42,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
|
||||
.requires_stage2 = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/export/build.zig", .{
|
||||
.build_modes = true,
|
||||
.requires_stage2 = true,
|
||||
});
|
||||
|
||||
cases.addBuildFile("test/link/wasm/extern/build.zig", .{
|
||||
.build_modes = true,
|
||||
.requires_stage2 = true,
|
||||
|
||||
@ -26,8 +26,7 @@ pub fn build(b: *Builder) void {
|
||||
check_lib.checkNext("name memory"); // as per linker specification
|
||||
|
||||
// since we are importing memory, ensure it's not exported
|
||||
check_lib.checkStart("Section export");
|
||||
check_lib.checkNext("entries 1"); // we're exporting function 'foo' so only 1 entry
|
||||
check_lib.checkNotPresent("Section export");
|
||||
|
||||
// validate the name of the stack pointer
|
||||
check_lib.checkStart("Section custom");
|
||||
|
||||
48
test/link/wasm/export/build.zig
Normal file
48
test/link/wasm/export/build.zig
Normal file
@ -0,0 +1,48 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const no_export = b.addSharedLibrary("no-export", "main.zig", .unversioned);
|
||||
no_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
no_export.setBuildMode(mode);
|
||||
no_export.use_llvm = false;
|
||||
no_export.use_lld = false;
|
||||
|
||||
const dynamic_export = b.addSharedLibrary("dynamic", "main.zig", .unversioned);
|
||||
dynamic_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
dynamic_export.setBuildMode(mode);
|
||||
dynamic_export.rdynamic = true;
|
||||
dynamic_export.use_llvm = false;
|
||||
dynamic_export.use_lld = false;
|
||||
|
||||
const force_export = b.addSharedLibrary("force", "main.zig", .unversioned);
|
||||
force_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
|
||||
force_export.setBuildMode(mode);
|
||||
force_export.export_symbol_names = &.{"foo"};
|
||||
force_export.use_llvm = false;
|
||||
force_export.use_lld = false;
|
||||
|
||||
const check_no_export = no_export.checkObject(.wasm);
|
||||
check_no_export.checkStart("Section export");
|
||||
check_no_export.checkNext("entries 1");
|
||||
check_no_export.checkNext("name memory");
|
||||
check_no_export.checkNext("kind memory");
|
||||
|
||||
const check_dynamic_export = dynamic_export.checkObject(.wasm);
|
||||
check_dynamic_export.checkStart("Section export");
|
||||
check_dynamic_export.checkNext("entries 2");
|
||||
check_dynamic_export.checkNext("name foo");
|
||||
check_dynamic_export.checkNext("kind function");
|
||||
|
||||
const check_force_export = force_export.checkObject(.wasm);
|
||||
check_force_export.checkStart("Section export");
|
||||
check_force_export.checkNext("entries 2");
|
||||
check_force_export.checkNext("name foo");
|
||||
check_force_export.checkNext("kind function");
|
||||
|
||||
const test_step = b.step("test", "Run linker test");
|
||||
test_step.dependOn(&check_no_export.step);
|
||||
test_step.dependOn(&check_dynamic_export.step);
|
||||
test_step.dependOn(&check_force_export.step);
|
||||
}
|
||||
1
test/link/wasm/export/main.zig
Normal file
1
test/link/wasm/export/main.zig
Normal file
@ -0,0 +1 @@
|
||||
export fn foo() void {}
|
||||
Loading…
x
Reference in New Issue
Block a user