can specify a wasm target in build

This commit is contained in:
Mitchell Hashimoto
2022-12-31 08:53:11 -08:00
parent 1093cf5254
commit ce490e21ea
11 changed files with 69 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
const std = @import("std");
const builtin = @import("builtin");
const options = @import("build_options");
const Target = @import("wasm/target.zig").Target;
comptime {
if (!builtin.target.isWasm()) {
@@ -13,6 +14,16 @@ comptime {
/// in JS will be backed by a SharedArrayBuffer and some behaviors change.
pub const shared_mem = options.wasm_shared;
/// Our specific target platform.
pub const target: ?Target = if (!builtin.target.isWasm()) null else target: {
const result = @intToEnum(Target, @enumToInt(options.wasm_target));
// This maybe isn't necessary but I don't know if enums without a specific
// tag type and value are guaranteed to be the same between build.zig
// compilation and our own source compilation so I have this just in case.
std.debug.assert(std.mem.eql(u8, @tagName(result), @tagName(options.wasm_target)));
break :target result;
};
/// The allocator to use in wasm environments.
///
/// The return values of this should NOT be sent to the host environment