Skip to content

support more than one "executor" and logic to detect which one is installed #3775

@andrewrk

Description

@andrewrk

The motivating case here, is that someone might want to run WASI unit tests with wasmer or wasmtime. Both fulfill the same dependency.

This code should probably be lifted out of std/target.zig and put into std/build.zig or subdirectories of that, since it relates to the zig build system, not targets in general.

zig/lib/std/target.zig

Lines 614 to 665 in 80f79cc

pub const Executor = union(enum) {
native,
qemu: []const u8,
wine: []const u8,
wasmtime: []const u8,
unavailable,
};
pub fn getExternalExecutor(self: Target) Executor {
if (@as(@TagType(Target), self) == .Native) return .native;
// If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture.
if (self.getOs() == builtin.os) {
return switch (self.getArch()) {
.aarch64 => Executor{ .qemu = "qemu-aarch64" },
.aarch64_be => Executor{ .qemu = "qemu-aarch64_be" },
.arm => Executor{ .qemu = "qemu-arm" },
.armeb => Executor{ .qemu = "qemu-armeb" },
.i386 => Executor{ .qemu = "qemu-i386" },
.mips => Executor{ .qemu = "qemu-mips" },
.mipsel => Executor{ .qemu = "qemu-mipsel" },
.mips64 => Executor{ .qemu = "qemu-mips64" },
.mips64el => Executor{ .qemu = "qemu-mips64el" },
.powerpc => Executor{ .qemu = "qemu-ppc" },
.powerpc64 => Executor{ .qemu = "qemu-ppc64" },
.powerpc64le => Executor{ .qemu = "qemu-ppc64le" },
.riscv32 => Executor{ .qemu = "qemu-riscv32" },
.riscv64 => Executor{ .qemu = "qemu-riscv64" },
.s390x => Executor{ .qemu = "qemu-s390x" },
.sparc => Executor{ .qemu = "qemu-sparc" },
.x86_64 => Executor{ .qemu = "qemu-x86_64" },
else => return .unavailable,
};
}
if (self.isWindows()) {
switch (self.getArchPtrBitWidth()) {
32 => return Executor{ .wine = "wine" },
64 => return Executor{ .wine = "wine64" },
else => return .unavailable,
}
}
if (self.getOs() == .wasi) {
switch (self.getArchPtrBitWidth()) {
32 => return Executor{ .wasmtime = "wasmtime" },
else => return .unavailable,
}
}
return .unavailable;
}

It should be made to return more than one possible executor. A global std.Builder field could override default priority. The build system code then needs to be improved to try executors in order, falling back to the next one, when it gets a file not found error (which one is installed is the best way to choose which one to use).

Another thing to do here, which could be in a follow-up issue, or in this issue, is a global function in std.Builder, something like enableExternalExecutors(); This function would enable auto-detection of what executors are installed, and automatically run them on all unit tests where applicable. Whether to enable this by default is a separate concern. It's useful, but we might want to have the policy that all system dependencies must be opt-in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions