Skip to content
/ zig Public
forked from ziglang/zig

Commit abb51dd

Browse files
committed
std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.
See: WebAssembly/tool-conventions#235 This is not *quite* using the same features as the spec'd lime1 model because LLVM 19 doesn't have the level of feature granularity that we need for that. This will be fixed once we upgrade to LLVM 20. Part of ziglang#21818.
1 parent faee4ba commit abb51dd

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

build.zig

+5-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,10 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
592592
.cpu_arch = .wasm32,
593593
.os_tag = .wasi,
594594
};
595-
target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
595+
// Not supported by the `wasm-opt` version in CI.
596+
target_query.cpu_features_add.removeFeature(@intFromEnum(std.Target.wasm.Feature.extended_const));
597+
// Not supported by `wasm2c`.
598+
target_query.cpu_features_add.removeFeature(@intFromEnum(std.Target.wasm.Feature.nontrapping_fptoint));
596599

597600
const exe = addCompilerStep(b, .{
598601
.optimize = .ReleaseSmall,
@@ -620,6 +623,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
620623
"wasm-opt",
621624
"-Oz",
622625
"--enable-bulk-memory",
626+
"--enable-mutable-globals",
623627
"--enable-sign-ext",
624628
});
625629
run_opt.addArtifactArg(exe);

lib/std/Target.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ pub const Cpu = struct {
20062006
else => generic(arch),
20072007
},
20082008
.xcore => &xcore.cpu.xs1b_generic,
2009-
.wasm32, .wasm64 => &wasm.cpu.generic,
2009+
.wasm32, .wasm64 => &wasm.cpu.lime1,
20102010

20112011
else => generic(arch),
20122012
};

lib/std/Target/wasm.zig

+12
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ pub const cpu = struct {
139139
.sign_ext,
140140
}),
141141
};
142+
pub const lime1: CpuModel = .{
143+
.name = "lime1",
144+
.llvm_name = null,
145+
.features = featureSet(&[_]Feature{
146+
.bulk_memory,
147+
.extended_const,
148+
.multivalue,
149+
.mutable_globals,
150+
.nontrapping_fptoint,
151+
.sign_ext,
152+
}),
153+
};
142154
pub const mvp: CpuModel = .{
143155
.name = "mvp",
144156
.llvm_name = "mvp",

src/Compilation.zig

-5
Original file line numberDiff line numberDiff line change
@@ -4004,14 +4004,9 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
40044004
.os_tag = .freestanding,
40054005
.cpu_features_add = std.Target.wasm.featureSet(&.{
40064006
.atomics,
4007-
.bulk_memory,
40084007
// .extended_const, not supported by Safari
4009-
.multivalue,
4010-
.mutable_globals,
4011-
.nontrapping_fptoint,
40124008
.reference_types,
40134009
//.relaxed_simd, not supported by Firefox or Safari
4014-
.sign_ext,
40154010
// observed to cause Error occured during wast conversion :
40164011
// Unknown operator: 0xfd058 in Firefox 117
40174012
//.simd128,

tools/update_cpu_features.zig

+14
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,20 @@ const llvm_targets = [_]LlvmTarget{
10331033
.zig_name = "wasm",
10341034
.llvm_name = "WebAssembly",
10351035
.td_name = "WebAssembly.td",
1036+
.extra_cpus = &.{
1037+
.{
1038+
.llvm_name = null,
1039+
.zig_name = "lime1",
1040+
.features = &.{
1041+
"bulk_memory",
1042+
"extended_const",
1043+
"multivalue",
1044+
"mutable_globals",
1045+
"nontrapping_fptoint",
1046+
"sign_ext",
1047+
},
1048+
},
1049+
},
10361050
},
10371051
.{
10381052
.zig_name = "x86",

0 commit comments

Comments
 (0)