motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 777215d78bd49597dc0b369c8b71765a0e5d338c (tree)
parent 26fdb81c16760b5aabbd1905ef96cefdf596fc3d
Author: Carl Ã…stholm <carl@astholm.se>
Date:   Sun, 23 Mar 2025 14:14:42 +0100

Use `-unknown` when converting WASI/Emscripten target triples into LLVM triples

The "musl" part of the Zig target triples `wasm32-wasi-musl` and
`wasm32-emscripten-musl` refers to the libc, not really the ABI.

For WASM, most LLVM-based tooling uses `wasm32-wasi`, which is
normalized into `wasm32-unknown-wasi`, with an implicit `-unknown` and
without `-musl`.

Similarly, Emscripten uses `wasm32-unknown-emscripten` without `-musl`.

By using `-unknown` instead of `-musl` we get better compatibility with
external tooling.

Diffstat:
Msrc/codegen/llvm.zig | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig @@ -264,7 +264,12 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { .eabihf => "eabihf", .android => "android", .androideabi => "androideabi", - .musl => "musl", + .musl => switch (target.os.tag) { + // For WASI/Emscripten, "musl" refers to the libc, not really the ABI. + // "unknown" provides better compatibility with LLVM-based tooling for these targets. + .wasi, .emscripten => "unknown", + else => "musl", + }, .muslabin32 => "musl", // Should be muslabin32 in LLVM 20. .muslabi64 => "musl", // Should be muslabi64 in LLVM 20. .musleabi => "musleabi",