Skip to content

Commit 7b17b21

Browse files
committed
Fix debug build
1 parent d0f1d70 commit 7b17b21

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

build.zig

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ pub fn build(b: *std.Build) !void {
3737
const lib = b.addStaticLibrary(.{
3838
.name = "libtinycc",
3939
.target = target,
40-
.optimize = switch (optimize) { // does not work with .Debug or .ReleaseSafe
41-
.Debug => .ReleaseFast,
42-
.ReleaseFast => .ReleaseFast,
43-
.ReleaseSafe => .ReleaseFast,
44-
.ReleaseSmall => .ReleaseSmall,
45-
},
40+
.optimize = optimize,
4641
});
4742
lib.linkLibC();
4843
lib.addIncludePath(b.path("src/config"));
@@ -56,14 +51,16 @@ pub fn build(b: *std.Build) !void {
5651
const os_tag = target.result.os.tag;
5752

5853
var FLAGS = std.ArrayList([]const u8).init(b.allocator);
59-
var C_SOURCES = std.ArrayList(std.Build.LazyPath).init(b.allocator);
54+
var C_SOURCES = std.ArrayList([]const u8).init(b.allocator);
6055

6156
try FLAGS.append("-Wall");
6257
try FLAGS.append("-fno-strict-aliasing");
58+
try FLAGS.append("-fno-sanitize=undefined");
6359
try FLAGS.append("-O3");
6460

6561
try FLAGS.append("-DCONFIG_TCC_PREDEFS");
6662
try FLAGS.append("-DONE_SOURCE=0");
63+
try FLAGS.append("-DMEM_DEBUG=2");
6764
try FLAGS.append("-DTCC_LIBTCC1=\"\\0\"");
6865

6966
if (!(b.option(bool, "CONFIG_TCC_BCHECK", "compile with built-in memory and bounds checker (implies -g)") orelse true))
@@ -73,38 +70,36 @@ pub fn build(b: *std.Build) !void {
7370
try FLAGS.append("-DCONFIG_TCC_BACKTRACE=0");
7471

7572
for (SOURCES) |file|
76-
try C_SOURCES.append(tcc_dep.path(file));
77-
78-
try C_SOURCES.append(b.path("src/patch/tccrun.c"));
73+
try C_SOURCES.append(file);
7974

8075
switch (cpu_arch) {
8176
.x86_64 => {
8277
for (X86_64_SOURCES) |file|
83-
try C_SOURCES.append(tcc_dep.path(file));
78+
try C_SOURCES.append(file);
8479
},
8580
.arm => {
8681
for (ARM_SOURCES) |file|
87-
try C_SOURCES.append(tcc_dep.path(file));
82+
try C_SOURCES.append(file);
8883
},
8984
.aarch64 => {
9085
for (AARCH64_SOURCES) |file|
91-
try C_SOURCES.append(tcc_dep.path(file));
86+
try C_SOURCES.append(file);
9287
},
9388
.riscv64 => {
9489
for (RISCV64_SOURCES) |file|
95-
try C_SOURCES.append(tcc_dep.path(file));
90+
try C_SOURCES.append(file);
9691
},
9792
else => @panic("Unsupported CPU architecture"),
9893
}
9994

10095
switch (os_tag) {
10196
.windows => {
10297
for (WINDOWS_SOURCES) |file|
103-
try C_SOURCES.append(tcc_dep.path(file));
98+
try C_SOURCES.append(file);
10499
},
105100
.macos => {
106101
for (MACOS_SOURCES) |file|
107-
try C_SOURCES.append(tcc_dep.path(file));
102+
try C_SOURCES.append(file);
108103
},
109104
.linux => {},
110105
else => @panic("Unsupported OS"),
@@ -136,18 +131,17 @@ pub fn build(b: *std.Build) !void {
136131
else => unreachable,
137132
}
138133

139-
for (C_SOURCES.items) |path|
140-
lib.addCSourceFile(.{ .file = path, .flags = FLAGS.items });
134+
lib.addCSourceFiles(.{
135+
.root = tcc_dep.path(""),
136+
.files = C_SOURCES.items,
137+
.flags = FLAGS.items,
138+
});
139+
lib.addCSourceFile(.{ .file = b.path("src/patch/tccrun.c"), .flags = FLAGS.items });
141140

142141
const module = b.addModule("tinycc", .{
143142
.root_source_file = b.path("src/lib.zig"),
144143
.target = target,
145-
.optimize = if (os_tag == .macos) switch (optimize) {
146-
.Debug => .ReleaseFast,
147-
.ReleaseFast => .ReleaseFast,
148-
.ReleaseSafe => .ReleaseFast,
149-
.ReleaseSmall => .ReleaseSmall,
150-
} else optimize,
144+
.optimize = optimize,
151145
});
152146
module.linkLibrary(lib);
153147

@@ -156,12 +150,7 @@ pub fn build(b: *std.Build) !void {
156150
const unit_tests = b.addTest(.{
157151
.root_source_file = b.path("src/lib.zig"),
158152
.target = target,
159-
.optimize = if (os_tag == .macos) switch (optimize) {
160-
.Debug => .ReleaseFast,
161-
.ReleaseFast => .ReleaseFast,
162-
.ReleaseSafe => .ReleaseFast,
163-
.ReleaseSmall => .ReleaseSmall,
164-
} else optimize,
153+
.optimize = optimize,
165154
});
166155
unit_tests.linkLibrary(lib);
167156

0 commit comments

Comments
 (0)