Skip to content

Commit

Permalink
Enable more wasm 'cpu' features
Browse files Browse the repository at this point in the history
  • Loading branch information
Senryoku committed May 1, 2024
1 parent b51cf04 commit 43c0e57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSmall });

var lib_target_query = std.Target.Query{ .cpu_arch = .wasm32, .os_tag = .freestanding };
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.extended_const));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.multivalue));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.mutable_globals));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.reference_types));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.relaxed_simd));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.sign_ext));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.simd128));
lib_target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.tail_call));
const lib_target = b.resolveTargetQuery(lib_target_query);

var lib = b.addExecutable(.{
.name = "smol-string",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/wasm.zig" },
.target = b.resolveTargetQuery(std.zig.CrossTarget{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
.target = lib_target,
.optimize = .ReleaseSmall,
});
lib.entry = .disabled;
Expand Down
Binary file modified ts-lib/src/module.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion ts-lib/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineConfig({
name: "optimize-wasm",
async buildStart(options) {
exec(
"npx wasm-opt -O3 ../zig-out/bin/smol-string.wasm -o ./src/module.wasm"
"npx wasm-opt -O4 -all ../zig-out/bin/smol-string.wasm -o ./src/module.wasm"
);
},
},
Expand Down

0 comments on commit 43c0e57

Please sign in to comment.