wasm: Enable C-ABI tests for self-hosted compiler

This commit is contained in:
Luuk de Gram 2022-07-20 21:51:18 +02:00
parent 6b4d4c70fd
commit a7417f7839
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
4 changed files with 78 additions and 1 deletions

View File

@ -484,7 +484,20 @@ pub fn build(b: *Builder) !void {
));
toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, enable_macos_sdk, target, omit_stage2));
toolchain_step.dependOn(tests.addStandaloneTests(
b,
test_filter,
modes,
skip_non_native,
enable_macos_sdk,
target,
omit_stage2,
b.enable_darling,
b.enable_qemu,
b.enable_rosetta,
b.enable_wasmtime,
b.enable_wine,
));
toolchain_step.dependOn(tests.addLinkTests(b, test_filter, modes, enable_macos_sdk, omit_stage2));
toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes));

View File

@ -0,0 +1,24 @@
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) void {
const rel_opts = b.standardReleaseOptions();
const target: std.zig.CrossTarget = .{ .cpu_arch = .wasm32, .os_tag = .wasi };
b.use_stage1 = false;
const c_obj = b.addObject("cfuncs", null);
c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
c_obj.setBuildMode(rel_opts);
c_obj.linkSystemLibrary("c");
c_obj.setTarget(target);
const main = b.addTest("main.zig");
main.setBuildMode(rel_opts);
main.addObject(c_obj);
main.setTarget(target);
const test_step = b.step("test", "Test the program");
test_step.dependOn(&main.step);
b.default_step.dependOn(test_step);
}

View File

@ -41,6 +41,12 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
if (builtin.cpu.arch == .x86_64) {
cases.addBuildFile("test/stage1/c_abi/build.zig", .{});
}
// C ABI tests only pass for the Wasm target when using stage2
cases.addBuildFile("test/stage1/c_abi/build_wasm.zig", .{
.requires_stage2 = true,
.use_emulation = true,
});
cases.addBuildFile("test/standalone/c_compiler/build.zig", .{
.build_modes = true,
.cross_targets = true,

View File

@ -463,6 +463,11 @@ pub fn addStandaloneTests(
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
omit_stage2: bool,
enable_darling: bool,
enable_qemu: bool,
enable_rosetta: bool,
enable_wasmtime: bool,
enable_wine: bool,
) *build.Step {
const cases = b.allocator.create(StandaloneContext) catch unreachable;
cases.* = StandaloneContext{
@ -475,6 +480,11 @@ pub fn addStandaloneTests(
.enable_macos_sdk = enable_macos_sdk,
.target = target,
.omit_stage2 = omit_stage2,
.enable_darling = enable_darling,
.enable_qemu = enable_qemu,
.enable_rosetta = enable_rosetta,
.enable_wasmtime = enable_wasmtime,
.enable_wine = enable_wine,
};
standalone.addCases(cases);
@ -962,6 +972,11 @@ pub const StandaloneContext = struct {
enable_macos_sdk: bool,
target: std.zig.CrossTarget,
omit_stage2: bool,
enable_darling: bool = false,
enable_qemu: bool = false,
enable_rosetta: bool = false,
enable_wasmtime: bool = false,
enable_wine: bool = false,
pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
self.addAllArgs(root_src, true);
@ -976,6 +991,7 @@ pub const StandaloneContext = struct {
cross_targets: bool = false,
requires_macos_sdk: bool = false,
requires_stage2: bool = false,
use_emulation: bool = false,
}) void {
const b = self.b;
@ -1007,6 +1023,24 @@ pub const StandaloneContext = struct {
zig_args.append(target_arg) catch unreachable;
}
if (features.use_emulation) {
if (self.enable_darling) {
zig_args.append("-fdarling") catch unreachable;
}
if (self.enable_qemu) {
zig_args.append("-fqemu") catch unreachable;
}
if (self.enable_rosetta) {
zig_args.append("-frosetta") catch unreachable;
}
if (self.enable_wasmtime) {
zig_args.append("-fwasmtime") catch unreachable;
}
if (self.enable_wine) {
zig_args.append("-fwine") catch unreachable;
}
}
const modes = if (features.build_modes) self.modes else &[1]Mode{.Debug};
for (modes) |mode| {
const arg = switch (mode) {