Skip to content

Commit

Permalink
Use C allocator in release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Dec 15, 2024
1 parent bd473e0 commit 4cb8c65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

if (optimize == .ReleaseFast) {
main_exe.linkLibC();
}
main_exe.root_module.addImport("httpz", httpz.module("httpz"));
main_exe.root_module.addImport("metrics", metrics.module("metrics"));
main_exe.root_module.addImport("zul", zul.module("zul"));
Expand Down
5 changes: 3 additions & 2 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const builtin = @import("builtin");
const std = @import("std");
const log = std.log.scoped(.main);
const zul = @import("zul");
Expand Down Expand Up @@ -37,10 +38,10 @@ pub fn logHandler(
}

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();

const allocator = gpa.allocator();
const allocator = if (builtin.mode == .ReleaseFast and !builtin.is_test) std.heap.c_allocator else gpa.allocator();

var args = try zul.CommandLineArgs.parse(allocator);
defer args.deinit();
Expand Down

0 comments on commit 4cb8c65

Please sign in to comment.