From 78f46660db982a6a02a2bc3d669b19646efb2a06 Mon Sep 17 00:00:00 2001 From: Steeve Morin Date: Wed, 19 Nov 2025 17:12:12 -0800 Subject: [PATCH 1/2] Use raw_c_allocator when not in Debug In our case (lots of C headers), codegen went from ~90s to less than 1s. --- build.zig | 3 +++ src/main.zig | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index c223bc4..011113b 100644 --- a/build.zig +++ b/build.zig @@ -40,6 +40,9 @@ pub fn build(b: *std.Build) void { .use_llvm = use_llvm, .use_lld = use_llvm, }); + if (optimize != .Debug) { + translate_c_exe.linkLibC(); + } b.installDirectory(.{ .source_dir = aro.path("include"), diff --git a/src/main.zig b/src/main.zig index aa3aa19..f351581 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7,11 +7,16 @@ const Translator = @import("Translator.zig"); const fast_exit = @import("builtin").mode != .Debug; -var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .init; +var debug_allocator: std.heap.DebugAllocator(.{}) = .init; pub fn main() u8 { - const gpa = general_purpose_allocator.allocator(); - defer _ = general_purpose_allocator.deinit(); + const gpa = if (@import("builtin").link_libc) + std.heap.raw_c_allocator + else + debug_allocator.allocator(); + defer if (!@import("builtin").link_libc) { + _ = debug_allocator.deinit(); + }; var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena_instance.deinit(); From 0b92c32777bfa3658bf179c5a49c903eb874607d Mon Sep 17 00:00:00 2001 From: Steeve Morin Date: Sat, 22 Nov 2025 15:34:02 -0800 Subject: [PATCH 2/2] Add link_libc build option --- build.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 011113b..2f814be 100644 --- a/build.zig +++ b/build.zig @@ -7,6 +7,7 @@ pub fn build(b: *std.Build) void { const skip_run_translated = b.option(bool, "skip-run-translated", "Main test suite skips run-translated tests") orelse false; const test_cross_targets = b.option(bool, "test-cross-targets", "Include cross-translation targets in the test cases") orelse false; const use_llvm = b.option(bool, "llvm", "Use LLVM backend to generate aro executable"); + const link_libc = b.option(bool, "link-libc", "Link libc") orelse (optimize != .Debug); const aro = b.dependency("aro", .{ .target = target, @@ -40,7 +41,7 @@ pub fn build(b: *std.Build) void { .use_llvm = use_llvm, .use_lld = use_llvm, }); - if (optimize != .Debug) { + if (link_libc) { translate_c_exe.linkLibC(); }