This commit is contained in:
agra
2026-03-02 21:00:55 +02:00
parent 2f4f898d54
commit bbb5426777
42 changed files with 483 additions and 9023 deletions

View File

@@ -58,6 +58,16 @@ pub const TargetConfig = struct {
return self.tripleHasPrefix("wasm32", "wasm64");
}
/// Check if target triple indicates wasm32 specifically (4-byte pointers, i32 size_t).
pub fn isWasm32(self: TargetConfig) bool {
return self.tripleHasPrefix("wasm32", "wasm32");
}
/// Check if target triple indicates wasm64 specifically (8-byte pointers, i64 size_t).
pub fn isWasm64(self: TargetConfig) bool {
return self.tripleHasPrefix("wasm64", "wasm64");
}
/// Check if target triple indicates macOS/Darwin.
pub fn isMacOS(self: TargetConfig) bool {
return self.tripleContains("darwin") or self.tripleContains("macos");
@@ -177,9 +187,26 @@ pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, ex
// Skip -l flags for Emscripten: libraries like SDL3 are provided via
// -sUSE_SDL=3, not -lSDL3. User provides everything via --lflags.
// Extra linker flags (e.g. -sUSE_SDL=3, -sUSE_WEBGL2=1, --preload-file)
// wasm64: automatically add -sMEMORY64 for the linker
if (target_config.isWasm64()) {
try argv.append(allocator, "-sMEMORY64");
}
// Use the built-in sx HTML shell template (write to temp file for emcc)
if (std.mem.endsWith(u8, output_bin, ".html")) {
const shell_html = @embedFile("wasm_shell.html");
const shell_path = try std.fmt.allocPrint(allocator, "{s}.shell.html", .{output_obj});
std.Io.Dir.writeFile(.cwd(), io, .{ .sub_path = shell_path, .data = shell_html }) catch {};
try argv.appendSlice(allocator, &.{ "--shell-file", shell_path });
}
// Extra linker flags (e.g. -sUSE_SDL=3, -sUSE_WEBGL2=1, --preload-file assets)
// Split space-separated flags into individual argv entries.
for (target_config.extra_link_flags) |flag| {
try argv.append(allocator, flag);
var it = std.mem.tokenizeScalar(u8, flag, ' ');
while (it.next()) |part| {
try argv.append(allocator, part);
}
}
} else if (target_config.isWindows()) {
// Windows: MSVC-style linker flags
@@ -219,9 +246,12 @@ pub fn link(allocator: std.mem.Allocator, io: std.Io, output_obj: []const u8, ex
try argv.append(allocator, try std.fmt.allocPrint(allocator, "-l{s}", .{lib}));
}
// Extra linker flags
// Extra linker flags — split space-separated flags into individual argv entries.
for (target_config.extra_link_flags) |flag| {
try argv.append(allocator, flag);
var it = std.mem.tokenizeScalar(u8, flag, ' ');
while (it.next()) |part| {
try argv.append(allocator, part);
}
}
}