authorgravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2022-12-31 15:29:02+01:00
committergravatar for luuk@degram.devLuuk de Gram <luuk@degram.dev> 2023-01-02 18:36:17+01:00
loge4869eeac11eccdbb6cf4d8a4e60a272ca179d55
tree85cc01bb74a01fdbdc7167a0e73ce61f78606f0c
parent9932372fae88a6dabdb3945d55556e373bd4bb45
signaturelock-open Commit is signed but in an unrecognized format.

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.

4 files changed, 55 insertions(+), 2 deletions(-)

test/link.zig+5
......@@ -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+1-2
......@@ -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 created+48
......@@ -0,0 +1,48 @@
1const std = @import("std");
2
3pub 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 created+1
......@@ -0,0 +1 @@
1export fn foo() void {}