Skip to content

Instantly share code, notes, and snippets.

@meheleventyone
Created November 20, 2018 20:48
Show Gist options
  • Save meheleventyone/b49433c958091cfa1be27f177e5af24d to your computer and use it in GitHub Desktop.
Save meheleventyone/b49433c958091cfa1be27f177e5af24d to your computer and use it in GitHub Desktop.
Build a Zig lib to WASM.
const Builder = @import("std").build.Builder;
const builtin = @import("builtin");
const wasmLink : []const []const u8 = []const []const u8 {"wasm-ld", "./zig-cache/wasmtest.o", "-o", "./zig-cache/wasmtest.wasm", "-O2", "--no-entry", "--allow-undefined"};
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const obj = b.addObject("wasmtest", "src/main.zig");
obj.setBuildMode(mode);
obj.setTarget(builtin.Arch.wasm32, builtin.Os.freestanding, builtin.Environ.unknown);
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
b.default_step.dependOn(&obj.step);
_ = b.exec(wasmLink);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment