Skip to content

Commit

Permalink
enable wasm multivalue in zig 0.12+
Browse files Browse the repository at this point in the history
also fix wasm exportable check
  • Loading branch information
scheibo committed Oct 27, 2024
1 parent fb6653d commit 3158fa1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ fn buildWasm(
else => optimize,
};
// https://webassembly.org/features/
const features = std.Target.wasm.featureSet(&.{
var features = std.Target.wasm.featureSet(&.{
.atomics,
.bulk_memory,
// .exception_handling,
Expand All @@ -333,7 +333,9 @@ fn buildWasm(
.simd128,
// .tail_call,
});
// TODO features.addFeature(@intFromEnum(std.Target.wasm.Feature.multivalue));
if (builtin.zig_version.order(try std.SemanticVersion.parse("0.12.0")) != .lt) {
features.addFeature(@intFromEnum(std.Target.wasm.Feature.multivalue));
}
const freestanding = if (@hasDecl(std.Build, "resolveTargetQuery"))
b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/bindings/wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const std = @import("std");
const assert = std.debug.assert;

const Enum = if (@hasField(std.builtin.Type, "enum")) .@"enum" else .Enum;
const Strong = if (@hasField(std.builtin.GlobalLinkage, "strong")) .strong else .Strong;

pub const options = pkmn.options;

Expand Down Expand Up @@ -48,8 +49,8 @@ pub fn gen(comptime num: comptime_int) type {
}

pub fn exports() type {
@export(gen(1).update, .{ .name = "GEN1_update", .linkage = .Strong });
@export(gen(1).choices, .{ .name = "GEN1_choices", .linkage = .Strong });
@export(gen(1).update, .{ .name = "GEN1_update", .linkage = Strong });
@export(gen(1).choices, .{ .name = "GEN1_choices", .linkage = Strong });
return struct {};
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const CALC = wasm.options.calc;
export const GEN1_CHOICES_SIZE = wasm.gen(1).CHOICES_SIZE;
export const GEN1_LOGS_SIZE = wasm.gen(1).LOGS_SIZE;

const exportable = @hasDecl(std.zig, "Zir") and !@hasDecl(std.zig.Zir.Inst, "export_value");
const exportable = @hasDecl(std.zig, "Zir") and !@hasField(std.zig.Zir.Inst.Tag, "export_value");

usingnamespace if (exportable) struct {
export const GEN1_update = wasm.gen(1).update;
Expand Down

0 comments on commit 3158fa1

Please sign in to comment.