From 5d36bb83c9eb4b564cd03456697c692ce3bf19a7 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 31 Jul 2024 08:25:42 +0200 Subject: [PATCH] feat: MIR is built by zig --- README.md | 7 ++++--- build.zig | 37 ++++++++++++++++++------------------- examples/fibonacci.buzz | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 85314ed5..5fe43ba5 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,11 @@ _Latest zig version supported: 0.14.0-dev.121+ab4c461b7_ ### Build 1. Clone the project: `git clone https://github.com/buzz-language/buzz ` 2. Checkout submodules: `git submodule update --init` -3. Build MIR: +3. Run configure for pcre2: ```bash -cd vendors/mir -make +cd vendors/pcre2 +./configure +cd ../.. ``` 4. Have fun: `zig build run -- ` diff --git a/build.zig b/build.zig index be11bc55..0c71cc1e 100644 --- a/build.zig +++ b/build.zig @@ -116,20 +116,14 @@ pub fn build(b: *Build) !void { .sha = std.posix.getenv("GIT_SHA") orelse std.posix.getenv("GITHUB_SHA") orelse std.mem.trim( u8, - (std.process.Child.run(.{ - .allocator = b.allocator, - .argv = &.{ + b.run( + &.{ "git", "rev-parse", "--short", "HEAD", }, - .cwd = b.pathFromRoot("."), - .expand_arg0 = .expand, - }) catch { - std.debug.print("Warning: failed to get git HEAD", .{}); - unreachable; - }).stdout, + ), "\n \t", ), .cycle_limit = b.option( @@ -735,16 +729,20 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O if (lib.root_module.resolved_target.?.result.os.tag == .windows) { lib.addSystemIncludePath( - b.path((std.process.Child.run(.{ - .allocator = b.allocator, - .argv = &.{ - "xcrun", - "--show-sdk-path", - }, - }) catch { - std.debug.print("Failed to get MacOSX sdk path", .{}); - unreachable; - }).stdout), + b.path( + std.fmt.allocPrint( + b.allocator, + "{s}/usr/include", + .{ + b.run( + &.{ + "xcrun", + "--show-sdk-path", + }, + ), + }, + ) catch @panic("Out of memory"), + ), ); // Github macos-12 runner (https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md). lib.addSystemIncludePath(b.path("/Applications/Xcode_14.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include")); @@ -766,6 +764,7 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O "-O3", "-DNDEBUG=1", "-DMIR_PARALLEL_GEN=1", + "-fno-sanitize=undefined", // "-DADDITIONAL_INCLUDE_PATH=\"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include\"", }, }, diff --git a/examples/fibonacci.buzz b/examples/fibonacci.buzz index 2b3abc89..556a1cd5 100644 --- a/examples/fibonacci.buzz +++ b/examples/fibonacci.buzz @@ -14,7 +14,7 @@ fun fibonacci(int n) > void *> int? { } fun main([str] args) > void { - const N = std.parseInt(args[?0] ?? '10') ?? 10; + const N = std.parseInt(args[?0] ?? "10") ?? 10; foreach (var n in &fibonacci(N)) { std.print("{n}");