diff --git a/build.zig b/build.zig index c223bc4..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,6 +41,9 @@ pub fn build(b: *std.Build) void { .use_llvm = use_llvm, .use_lld = use_llvm, }); + if (link_libc) { + 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();