Skip to content

Commit e4869ee

Browse files
committed
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.
1 parent 9932372 commit e4869ee

4 files changed

Lines changed: 55 additions & 2 deletions

File tree

test/link.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ fn addWasmCases(cases: *tests.StandaloneContext) void {
4242
.requires_stage2 = true,
4343
});
4444

45+
cases.addBuildFile("test/link/wasm/export/build.zig", .{
46+
.build_modes = true,
47+
.requires_stage2 = true,
48+
});
49+
4550
cases.addBuildFile("test/link/wasm/extern/build.zig", .{
4651
.build_modes = true,
4752
.requires_stage2 = true,

test/link/wasm/bss/build.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pub fn build(b: *Builder) void {
2626
check_lib.checkNext("name memory"); // as per linker specification
2727

2828
// since we are importing memory, ensure it's not exported
29-
check_lib.checkStart("Section export");
30-
check_lib.checkNext("entries 1"); // we're exporting function 'foo' so only 1 entry
29+
check_lib.checkNotPresent("Section export");
3130

3231
// validate the name of the stack pointer
3332
check_lib.checkStart("Section custom");

test/link/wasm/export/build.zig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.build.Builder) void {
4+
const mode = b.standardReleaseOptions();
5+
6+
const no_export = b.addSharedLibrary("no-export", "main.zig", .unversioned);
7+
no_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
8+
no_export.setBuildMode(mode);
9+
no_export.use_llvm = false;
10+
no_export.use_lld = false;
11+
12+
const dynamic_export = b.addSharedLibrary("dynamic", "main.zig", .unversioned);
13+
dynamic_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
14+
dynamic_export.setBuildMode(mode);
15+
dynamic_export.rdynamic = true;
16+
dynamic_export.use_llvm = false;
17+
dynamic_export.use_lld = false;
18+
19+
const force_export = b.addSharedLibrary("force", "main.zig", .unversioned);
20+
force_export.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
21+
force_export.setBuildMode(mode);
22+
force_export.export_symbol_names = &.{"foo"};
23+
force_export.use_llvm = false;
24+
force_export.use_lld = false;
25+
26+
const check_no_export = no_export.checkObject(.wasm);
27+
check_no_export.checkStart("Section export");
28+
check_no_export.checkNext("entries 1");
29+
check_no_export.checkNext("name memory");
30+
check_no_export.checkNext("kind memory");
31+
32+
const check_dynamic_export = dynamic_export.checkObject(.wasm);
33+
check_dynamic_export.checkStart("Section export");
34+
check_dynamic_export.checkNext("entries 2");
35+
check_dynamic_export.checkNext("name foo");
36+
check_dynamic_export.checkNext("kind function");
37+
38+
const check_force_export = force_export.checkObject(.wasm);
39+
check_force_export.checkStart("Section export");
40+
check_force_export.checkNext("entries 2");
41+
check_force_export.checkNext("name foo");
42+
check_force_export.checkNext("kind function");
43+
44+
const test_step = b.step("test", "Run linker test");
45+
test_step.dependOn(&check_no_export.step);
46+
test_step.dependOn(&check_dynamic_export.step);
47+
test_step.dependOn(&check_force_export.step);
48+
}

test/link/wasm/export/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export fn foo() void {}

0 commit comments

Comments
 (0)