aboutsummaryrefslogtreecommitdiff
path: root/test/link/wasm/export/build.zig
blob: a3fa2c345c46c3b4d4fe9e4b69d29e724f39ba0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const std = @import("std");

pub fn build(b: *std.Build) void {
    const test_step = b.step("test", "Test it");
    b.default_step = test_step;

    add(b, test_step, .Debug);
}

fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
    const no_export = b.addExecutable(.{
        .name = "no-export",
        .root_module = b.createModule(.{
            .root_source_file = b.path("main-hidden.zig"),
            .optimize = optimize,
            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
        }),
    });
    no_export.entry = .disabled;
    no_export.use_llvm = false;
    no_export.use_lld = false;
    // Don't pull in ubsan, since we're just expecting a very minimal executable.
    no_export.bundle_ubsan_rt = false;

    const dynamic_export = b.addExecutable(.{
        .name = "dynamic",
        .root_module = b.createModule(.{
            .root_source_file = b.path("main.zig"),
            .optimize = optimize,
            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
        }),
    });
    dynamic_export.entry = .disabled;
    dynamic_export.rdynamic = true;
    dynamic_export.use_llvm = false;
    dynamic_export.use_lld = false;
    // Don't pull in ubsan, since we're just expecting a very minimal executable.
    dynamic_export.bundle_ubsan_rt = false;

    const force_export = b.addExecutable(.{
        .name = "force",
        .root_module = b.createModule(.{
            .root_source_file = b.path("main-hidden.zig"),
            .optimize = optimize,
            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
        }),
    });
    force_export.entry = .disabled;
    force_export.root_module.export_symbol_names = &.{"foo"};
    force_export.use_llvm = false;
    force_export.use_lld = false;
    // Don't pull in ubsan, since we're just expecting a very minimal executable.
    force_export.bundle_ubsan_rt = false;

    const check_no_export = no_export.checkObject();
    check_no_export.checkInHeaders();
    check_no_export.checkExact("Section export");
    check_no_export.checkExact("entries 1");
    check_no_export.checkExact("name memory");
    check_no_export.checkExact("kind memory");

    const check_dynamic_export = dynamic_export.checkObject();
    check_dynamic_export.checkInHeaders();
    check_dynamic_export.checkExact("Section export");
    check_dynamic_export.checkExact("entries 2");
    check_dynamic_export.checkExact("name foo");
    check_dynamic_export.checkExact("kind function");

    const check_force_export = force_export.checkObject();
    check_force_export.checkInHeaders();
    check_force_export.checkExact("Section export");
    check_force_export.checkExact("entries 2");
    check_force_export.checkExact("name foo");
    check_force_export.checkExact("kind function");

    test_step.dependOn(&check_no_export.step);
    test_step.dependOn(&check_dynamic_export.step);
    test_step.dependOn(&check_force_export.step);
}