build(zig): support wasmtime in more archs

This commit is contained in:
ObserverOfTime 2025-08-29 12:44:18 +03:00
parent b57b7213a9
commit e6fe91e2e7
3 changed files with 70 additions and 57 deletions

View file

@ -60,7 +60,7 @@ pub fn wasmtimeDep(target: std.Target) []const u8 {
const arch = target.cpu.arch;
const os = target.os.tag;
const abi = target.abi;
return switch (os) {
return @as(?[]const u8, switch (os) {
.linux => switch (arch) {
.x86_64 => switch (abi) {
.gnu => "wasmtime_c_api_x86_64_linux",
@ -70,11 +70,26 @@ pub fn wasmtimeDep(target: std.Target) []const u8 {
},
.aarch64 => switch (abi) {
.gnu => "wasmtime_c_api_aarch64_linux",
.musl => "wasmtime_c_api_aarch64_musl",
.android => "wasmtime_c_api_aarch64_android",
else => null,
},
.s390x => "wasmtime_c_api_s390x_linux",
.riscv64 => "wasmtime_c_api_riscv64gc_linux",
.x86 => switch (abi) {
.gnu => "wasmtime_c_api_i686_linux",
else => null,
},
.arm => switch (abi) {
.gnueabi => "wasmtime_c_api_armv7_linux",
else => null,
},
.s390x => switch (abi) {
.gnu => "wasmtime_c_api_s390x_linux",
else => null,
},
.riscv64 => switch (abi) {
.gnu => "wasmtime_c_api_riscv64gc_linux",
else => null,
},
else => null,
},
.windows => switch (arch) {
@ -87,6 +102,10 @@ pub fn wasmtimeDep(target: std.Target) []const u8 {
.msvc => "wasmtime_c_api_aarch64_windows",
else => null,
},
.x86 => switch (abi) {
.msvc => "wasmtime_c_api_i686_windows",
else => null,
},
else => null,
},
.macos => switch (arch) {
@ -95,7 +114,7 @@ pub fn wasmtimeDep(target: std.Target) []const u8 {
else => null,
},
else => null,
} orelse std.debug.panic(
}) orelse std.debug.panic(
"Unsupported target for wasmtime: {s}-{s}-{s}",
.{ @tagName(arch), @tagName(os), @tagName(abi) },
);

View file

@ -27,11 +27,31 @@
.hash = "N-V-__8AAAO48QQf91w9RmmUDHTja8DrXZA1n6Bmc8waW3qe",
.lazy = true,
},
.wasmtime_c_api_aarch64_musl = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-aarch64-musl-c-api.tar.xz",
.hash = "N-V-__8AAI196wa9pwADoA2RbCDp5F7bKQg1iOPq6gIh8-FH",
.lazy = true,
},
.wasmtime_c_api_aarch64_windows = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-aarch64-windows-c-api.zip",
.hash = "N-V-__8AAC9u4wXfqd1Q6XyQaC8_DbQZClXux60Vu5743N05",
.lazy = true,
},
.wasmtime_c_api_armv7_linux = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-armv7-linux-c-api.tar.xz",
.hash = "N-V-__8AAHXe8gWs3s83Cc5G6SIq0_jWxj8fGTT5xG4vb6-x",
.lazy = true,
},
.wasmtime_c_api_i686_linux = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-i686-linux-c-api.tar.xz",
.hash = "N-V-__8AAN2pzgUUfulRCYnipSfis9IIYHoTHVlieLRmKuct",
.lazy = true,
},
.wasmtime_c_api_i686_windows = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-i686-windows-c-api.zip",
.hash = "N-V-__8AAJu0YAUUTFBLxFIOi-MSQVezA6MMkpoFtuaf2Quf",
.lazy = true,
},
.wasmtime_c_api_riscv64gc_linux = .{
.url = "https://github.com/bytecodealliance/wasmtime/releases/download/v33.0.2/wasmtime-v33.0.2-riscv64gc-linux-c-api.tar.xz",
.hash = "N-V-__8AAG8m-gc3E3AIImtTZ3l1c7HC6HUWazQ9OH5KACX4",

View file

@ -33,7 +33,7 @@ fn update_cargo(version: &Version) -> Result<()> {
fn zig_fetch(lines: &mut Vec<String>, version: &Version, url_suffix: &str) -> Result<()> {
let url = &format!("{WASMTIME_RELEASE_URL}/v{version}/wasmtime-v{version}-{url_suffix}");
println!(" Fetching {url}");
lines.push(format!(" .url = \"{url}\","));
lines.push(format!(" .url = \"{url}\","));
let output = Command::new("zig")
.arg("fetch")
@ -42,7 +42,7 @@ fn zig_fetch(lines: &mut Vec<String>, version: &Version, url_suffix: &str) -> Re
.with_context(|| format!("Failed to execute zig fetch {url}"))?;
let hash = String::from_utf8_lossy(&output.stdout);
lines.push(format!(" .hash = \"{}\",", hash.trim_end()));
lines.push(format!(" .hash = \"{}\",", hash.trim_end()));
Ok(())
}
@ -52,59 +52,33 @@ fn update_zig(version: &Version) -> Result<()> {
let mut old_lines = file.lines();
let new_lines = &mut Vec::with_capacity(old_lines.size_hint().0);
macro_rules! match_wasmtime_zig_dep {
($line:ident, {$($platform:literal => [$($arch:literal),*]),*,}) => {
match $line {
$($(concat!(" .wasmtime_c_api_", $arch, "_", $platform, " = .{") => {
let (_, _) = (old_lines.next(), old_lines.next());
let suffix = if $platform == "windows" || $platform == "mingw" {
concat!($arch, "-", $platform, "-c-api.zip")
} else {
concat!($arch, "-", $platform, "-c-api.tar.xz")
};
zig_fetch(new_lines, version, suffix)?;
})*)*
_ => {}
}
};
}
while let Some(line) = old_lines.next() {
new_lines.push(line.to_string());
match line {
" .wasmtime_c_api_aarch64_android = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "aarch64-android-c-api.tar.xz")?;
}
" .wasmtime_c_api_aarch64_linux = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "aarch64-linux-c-api.tar.xz")?;
}
" .wasmtime_c_api_aarch64_macos = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "aarch64-macos-c-api.tar.xz")?;
}
" .wasmtime_c_api_aarch64_windows = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "aarch64-windows-c-api.zip")?;
}
" .wasmtime_c_api_riscv64gc_linux = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "riscv64gc-linux-c-api.tar.xz")?;
}
" .wasmtime_c_api_s390x_linux = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "s390x-linux-c-api.tar.xz")?;
}
" .wasmtime_c_api_x86_64_android = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-android-c-api.tar.xz")?;
}
" .wasmtime_c_api_x86_64_linux = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-linux-c-api.tar.xz")?;
}
" .wasmtime_c_api_x86_64_macos = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-macos-c-api.tar.xz")?;
}
" .wasmtime_c_api_x86_64_mingw = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-mingw-c-api.zip")?;
}
" .wasmtime_c_api_x86_64_musl = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-musl-c-api.tar.xz")?;
}
" .wasmtime_c_api_x86_64_windows = .{" => {
let (_, _) = (old_lines.next(), old_lines.next());
zig_fetch(new_lines, version, "x86_64-windows-c-api.zip")?;
}
_ => {}
}
match_wasmtime_zig_dep!(line, {
"android" => ["aarch64", "x86_64"],
"linux" => ["aarch64", "armv7", "i686", "riscv64gc", "s390x", "x86_64"],
"macos" => ["aarch64", "x86_64"],
"mingw" => ["x86_64"],
"musl" => ["aarch64", "x86_64"],
"windows" => ["aarch64", "i686", "x86_64"],
});
}
std::fs::write("build.zig.zon", new_lines.join("\n") + "\n")?;