-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update build to zig 0.11.0 #454
Open
mangas
wants to merge
1
commit into
wasm3:main
Choose a base branch
from
mangas:update-zig-build
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As far as I can see this is not tested on CI, perhaps it's worth adding a build step just keep it working? |
Thanks! I'd appreciate it if a CI job could be added along with this PR. |
Hi @mangas & @vshymanskyy My patch for v0.12.0 diff-patchdiff --git a/build.zig b/build.zig
index 6679f06..0d99eff 100644
--- a/build.zig
+++ b/build.zig
@@ -1,39 +1,82 @@
const std = @import("std");
-pub fn build(b: *std.build.Builder) !void {
+pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
- const mode = b.standardReleaseOptions();
+ const optimize = b.standardOptimizeOption(.{
+ .preferred_optimize_mode = .ReleaseSmall,
+ });
- const wasm3 = b.addExecutable("wasm3", null);
- wasm3.setTarget(target);
- wasm3.setBuildMode(mode);
- wasm3.install();
- wasm3.linkLibC();
+ const libwasm3 = b.addStaticLibrary(.{
+ .name = "m3",
+ .target = target,
+ .optimize = optimize,
+ });
+ libwasm3.root_module.sanitize_c = false; // fno-sanitize=undefined
+ libwasm3.defineCMacro("d_m3HasTracer", null);
- if (target.getCpuArch() == .wasm32 and target.getOsTag() == .wasi) {
- wasm3.linkSystemLibrary("wasi-emulated-process-clocks");
+ if (libwasm3.rootModuleTarget().isWasm()) {
+ if (libwasm3.rootModuleTarget().os.tag == .wasi) {
+ libwasm3.defineCMacro("d_m3HasWASI", null);
+ libwasm3.linkSystemLibrary("wasi-emulated-process-clocks");
+ }
}
+ libwasm3.addIncludePath(.{ .path = "source" });
+ libwasm3.addCSourceFiles(.{
+ .files = &.{
+ "source/m3_api_libc.c",
+ "source/extensions/m3_extensions.c",
+ "source/m3_api_meta_wasi.c",
+ "source/m3_api_tracer.c",
+ "source/m3_api_uvwasi.c",
+ "source/m3_api_wasi.c",
+ "source/m3_bind.c",
+ "source/m3_code.c",
+ "source/m3_compile.c",
+ "source/m3_core.c",
+ "source/m3_env.c",
+ "source/m3_exec.c",
+ "source/m3_function.c",
+ "source/m3_info.c",
+ "source/m3_module.c",
+ "source/m3_parse.c",
+ },
+ .flags = if (libwasm3.rootModuleTarget().isWasm())
+ &cflags ++ [_][]const u8{
+ "-Xclang",
+ "-target-feature",
+ "-Xclang",
+ "+tail-call",
+ }
+ else
+ &cflags,
+ });
+ libwasm3.linkSystemLibrary("m");
+ libwasm3.linkLibC();
- wasm3.addIncludePath("source");
- wasm3.addCSourceFiles(&.{
- "source/m3_api_libc.c",
- "source/m3_api_meta_wasi.c",
- "source/m3_api_tracer.c",
- "source/m3_api_uvwasi.c",
- "source/m3_api_wasi.c",
- "source/m3_bind.c",
- "source/m3_code.c",
- "source/m3_compile.c",
- "source/m3_core.c",
- "source/m3_env.c",
- "source/m3_exec.c",
- "source/m3_function.c",
- "source/m3_info.c",
- "source/m3_module.c",
- "source/m3_parse.c",
- "platforms/app/main.c",
- }, &.{
- "-Dd_m3HasWASI",
- "-fno-sanitize=undefined", // TODO investigate UB sites in the codebase, then delete this line.
+ const wasm3 = b.addExecutable(.{
+ .name = "wasm3",
+ .target = target,
+ .optimize = optimize,
});
+ for (libwasm3.root_module.include_dirs.items) |dir| {
+ wasm3.addIncludePath(dir.path);
+ }
+ wasm3.addCSourceFile(.{
+ .file = .{ .path = "platforms/app/main.c" },
+ .flags = &cflags,
+ });
+
+ wasm3.linkLibrary(libwasm3);
+ b.installArtifact(wasm3);
}
+
+const cflags = [_][]const u8{
+ "-Wall",
+ "-Wextra",
+ "-Wpedantic",
+ "-Wparentheses",
+ "-Wundef",
+ "-Wpointer-arith",
+ "-Wstrict-aliasing=2",
+ "-std=gnu11",
+}; Output: $> zig build --summary all
Build Summary: 4/4 steps succeeded
install success
└─ install wasm3 success
└─ zig build-exe wasm3 Debug native success 94ms MaxRSS:66M
└─ zig build-lib m3 Debug native success 487ms MaxRSS:86M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update zig build to use the v0.11.0 api