Skip to content

Commit

Permalink
feat: MIR is built by zig
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Jul 31, 2024
1 parent 0f8f5ca commit 7528467
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <buzz_dir>`
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 -- <myscript.buzz>`

Expand Down
39 changes: 4 additions & 35 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -731,28 +725,6 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
);

lib.addIncludePath(b.path("./vendors/mir"));
lib.linkLibC();

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),
);
// 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"));
lib.addSystemIncludePath(b.path("/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include"));
lib.addSystemIncludePath(b.path("/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include"));
lib.addSystemIncludePath(b.path("/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include"));
lib.addSystemIncludePath(b.path("/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include"));
}

lib.addCSourceFiles(
.{
Expand All @@ -766,13 +738,10 @@ pub fn buildMir(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.O
"-O3",
"-DNDEBUG=1",
"-DMIR_PARALLEL_GEN=1",
// "-DADDITIONAL_INCLUDE_PATH=\"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include\"",
"-fno-sanitize=undefined", // MIR has some undefined behaviour somewhere so we need this
},
},
);

// lib.linkSystemLibrary("m");
// lib.linkSystemLibrary("dl");

return lib;
}
2 changes: 1 addition & 1 deletion examples/fibonacci.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down

0 comments on commit 7528467

Please sign in to comment.