Skip to content

Commit 280ced6

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 206373c commit 280ced6

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

build.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,14 @@ pub fn build(b: *std.Build) !void {
594594
fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
595595
const semver = try std.SemanticVersion.parse(version);
596596

597-
var target_query: std.Target.Query = .{
598-
.cpu_arch = .wasm32,
599-
.os_tag = .wasi,
600-
};
601-
target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
602-
603597
const exe = addCompilerStep(b, .{
604598
.optimize = .ReleaseSmall,
605-
.target = b.resolveTargetQuery(target_query),
599+
.target = b.resolveTargetQuery(std.Target.Query.parse(.{
600+
.arch_os_abi = "wasm32-wasi",
601+
// `extended_const` is not supported by the `wasm-opt` version in CI.
602+
// `nontrapping_fptoint` is not supported by `wasm2c`.
603+
.cpu_features = "baseline-extended_const-nontrapping_fptoint",
604+
}) catch unreachable),
606605
});
607606

608607
const exe_options = b.addOptions();
@@ -644,6 +643,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
644643
"wasm-opt",
645644
"-Oz",
646645
"--enable-bulk-memory",
646+
"--enable-mutable-globals",
647647
"--enable-sign-ext",
648648
});
649649
run_opt.addArtifactArg(exe);

lib/std/Target.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ pub const Cpu = struct {
20122012
else => generic(arch),
20132013
},
20142014
.xcore => &xcore.cpu.xs1b_generic,
2015-
.wasm32, .wasm64 => &wasm.cpu.generic,
2015+
.wasm32, .wasm64 => &wasm.cpu.lime1,
20162016

20172017
else => generic(arch),
20182018
};

lib/std/Target/wasm.zig

Lines changed: 12 additions & 0 deletions
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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,14 +4150,9 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
41504150
.os_tag = .freestanding,
41514151
.cpu_features_add = std.Target.wasm.featureSet(&.{
41524152
.atomics,
4153-
.bulk_memory,
41544153
// .extended_const, not supported by Safari
4155-
.multivalue,
4156-
.mutable_globals,
4157-
.nontrapping_fptoint,
41584154
.reference_types,
41594155
//.relaxed_simd, not supported by Firefox or Safari
4160-
.sign_ext,
41614156
// observed to cause Error occured during wast conversion :
41624157
// Unknown operator: 0xfd058 in Firefox 117
41634158
//.simd128,

tools/update_cpu_features.zig

Lines changed: 14 additions & 0 deletions
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)