zig/test/link/wasm/export/build.zig
Jakub Konka e8b613783f check-object: remove wildcard matchers as they are too clunky
Instead, we now have a looser helper called `checkContains(...)`
that will match on any occurrence similarly to `std.mem.indexOf()`.

While at it, I have cleaned up other combinators to make the entire
API more consistent, and so:
* `checkStart(phrase)` is now `checkStart()` followed by
`checkExact(phrase)`
* `checkNext(phrase)` if matching exactly is now `checkExact(phrase)`
* `checkNext(phrase)` if matching loosely is now `checkContains(phrase)`
* `checkNext(phrase)` if matching exactly with var extractors is now
`checkExtract(phrase)`

Finally, `ElfDumper` is now dumping contents of `.symtab` and `.dynsym`
symbol tables. I have also removed dumping of symtabs as optional - they
are now always dumped which cleaned up the implementation even more.
2023-07-20 20:01:06 +02:00

70 lines
2.4 KiB
Zig

const std = @import("std");
pub const requires_stage2 = true;
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);
add(b, test_step, .ReleaseFast);
add(b, test_step, .ReleaseSmall);
add(b, test_step, .ReleaseSafe);
}
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const no_export = b.addSharedLibrary(.{
.name = "no-export",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
no_export.use_llvm = false;
no_export.use_lld = false;
const dynamic_export = b.addSharedLibrary(.{
.name = "dynamic",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
dynamic_export.rdynamic = true;
dynamic_export.use_llvm = false;
dynamic_export.use_lld = false;
const force_export = b.addSharedLibrary(.{
.name = "force",
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
});
force_export.export_symbol_names = &.{"foo"};
force_export.use_llvm = false;
force_export.use_lld = false;
const check_no_export = no_export.checkObject();
check_no_export.checkStart();
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.checkStart();
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.checkStart();
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);
}