@@ -37,12 +37,7 @@ pub fn build(b: *std.Build) !void {
37
37
const lib = b .addStaticLibrary (.{
38
38
.name = "libtinycc" ,
39
39
.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 ,
46
41
});
47
42
lib .linkLibC ();
48
43
lib .addIncludePath (b .path ("src/config" ));
@@ -56,14 +51,16 @@ pub fn build(b: *std.Build) !void {
56
51
const os_tag = target .result .os .tag ;
57
52
58
53
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 );
60
55
61
56
try FLAGS .append ("-Wall" );
62
57
try FLAGS .append ("-fno-strict-aliasing" );
58
+ try FLAGS .append ("-fno-sanitize=undefined" );
63
59
try FLAGS .append ("-O3" );
64
60
65
61
try FLAGS .append ("-DCONFIG_TCC_PREDEFS" );
66
62
try FLAGS .append ("-DONE_SOURCE=0" );
63
+ try FLAGS .append ("-DMEM_DEBUG=2" );
67
64
try FLAGS .append ("-DTCC_LIBTCC1=\" \\ 0\" " );
68
65
69
66
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 {
73
70
try FLAGS .append ("-DCONFIG_TCC_BACKTRACE=0" );
74
71
75
72
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 );
79
74
80
75
switch (cpu_arch ) {
81
76
.x86_64 = > {
82
77
for (X86_64_SOURCES ) | file |
83
- try C_SOURCES .append (tcc_dep . path ( file ) );
78
+ try C_SOURCES .append (file );
84
79
},
85
80
.arm = > {
86
81
for (ARM_SOURCES ) | file |
87
- try C_SOURCES .append (tcc_dep . path ( file ) );
82
+ try C_SOURCES .append (file );
88
83
},
89
84
.aarch64 = > {
90
85
for (AARCH64_SOURCES ) | file |
91
- try C_SOURCES .append (tcc_dep . path ( file ) );
86
+ try C_SOURCES .append (file );
92
87
},
93
88
.riscv64 = > {
94
89
for (RISCV64_SOURCES ) | file |
95
- try C_SOURCES .append (tcc_dep . path ( file ) );
90
+ try C_SOURCES .append (file );
96
91
},
97
92
else = > @panic ("Unsupported CPU architecture" ),
98
93
}
99
94
100
95
switch (os_tag ) {
101
96
.windows = > {
102
97
for (WINDOWS_SOURCES ) | file |
103
- try C_SOURCES .append (tcc_dep . path ( file ) );
98
+ try C_SOURCES .append (file );
104
99
},
105
100
.macos = > {
106
101
for (MACOS_SOURCES ) | file |
107
- try C_SOURCES .append (tcc_dep . path ( file ) );
102
+ try C_SOURCES .append (file );
108
103
},
109
104
.linux = > {},
110
105
else = > @panic ("Unsupported OS" ),
@@ -136,18 +131,17 @@ pub fn build(b: *std.Build) !void {
136
131
else = > unreachable ,
137
132
}
138
133
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 });
141
140
142
141
const module = b .addModule ("tinycc" , .{
143
142
.root_source_file = b .path ("src/lib.zig" ),
144
143
.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 ,
151
145
});
152
146
module .linkLibrary (lib );
153
147
@@ -156,12 +150,7 @@ pub fn build(b: *std.Build) !void {
156
150
const unit_tests = b .addTest (.{
157
151
.root_source_file = b .path ("src/lib.zig" ),
158
152
.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 ,
165
154
});
166
155
unit_tests .linkLibrary (lib );
167
156
0 commit comments