|
1 | 1 | const std = @import("std");
|
2 | 2 | const builtin = @import("builtin");
|
3 | 3 |
|
| 4 | +const zig_version = "0.13.0"; |
| 5 | + |
4 | 6 | comptime {
|
5 |
| - const supported_version = std.SemanticVersion.parse("0.13.0") catch unreachable; |
| 7 | + const supported_version = std.SemanticVersion.parse(zig_version) catch unreachable; |
6 | 8 | if (builtin.zig_version.order(supported_version) != .eq) {
|
7 | 9 | @compileError(std.fmt.comptimePrint("Unsupported Zig version ({}). Required Zig version 0.13.0.", .{builtin.zig_version}));
|
8 | 10 | }
|
@@ -58,7 +60,7 @@ pub fn build(b: *std.Build) !void {
|
58 | 60 | options.addOption(bool, "sandbox", sandbox);
|
59 | 61 |
|
60 | 62 | for (targets) |target| {
|
61 |
| - try build_target(b, target, options); |
| 63 | + try buildTarget(b, target, options); |
62 | 64 | }
|
63 | 65 | }
|
64 | 66 |
|
@@ -114,7 +116,7 @@ fn common(optimize: std.builtin.OptimizeMode) !void {
|
114 | 116 | }
|
115 | 117 | }
|
116 | 118 |
|
117 |
| -fn build_target(b: *std.Build, target: std.Target.Query, options: *std.Build.Step.Options) !void { |
| 119 | +fn buildTarget(b: *std.Build, target: std.Target.Query, options: *std.Build.Step.Options) !void { |
118 | 120 | var c_flags: []const []const u8 = undefined;
|
119 | 121 | if (target.cpu_arch == .x86_64) {
|
120 | 122 | c_flags = &.{ "-Wall", "-O3", "-ffast-math", "-Wno-unused-variable", "-Wno-unused-function", "-mavx2" };
|
@@ -158,30 +160,98 @@ fn build_target(b: *std.Build, target: std.Target.Query, options: *std.Build.Ste
|
158 | 160 | .root_source_file = b.path("src/table.zig"),
|
159 | 161 | });
|
160 | 162 |
|
161 |
| - lib_table.addCSourceFiles(.{ .files = &.{ |
162 |
| - "core/value.c", |
163 |
| - "core/memory.c", |
164 |
| - "core/object.c", |
165 |
| - }, .flags = c_flags }); |
| 163 | + const lib_value = b.addStaticLibrary(.{ |
| 164 | + .name = "libmufiz_value", |
| 165 | + .target = b.resolveTargetQuery(target), |
| 166 | + .optimize = .ReleaseFast, |
| 167 | + .link_libc = true, |
| 168 | + .root_source_file = b.path("src/value.zig"), |
| 169 | + }); |
| 170 | + |
| 171 | + const lib_memory = b.addStaticLibrary(.{ |
| 172 | + .name = "libmufiz_memory", |
| 173 | + .target = b.resolveTargetQuery(target), |
| 174 | + .optimize = .ReleaseFast, |
| 175 | + .link_libc = true, |
| 176 | + .root_source_file = b.path("src/memory.zig"), |
| 177 | + }); |
| 178 | + |
| 179 | + const lib_chunk = b.addStaticLibrary(.{ |
| 180 | + .name = "libmufiz_chunk", |
| 181 | + .target = b.resolveTargetQuery(target), |
| 182 | + .optimize = .ReleaseFast, |
| 183 | + .link_libc = true, |
| 184 | + .root_source_file = b.path("src/chunk.zig"), |
| 185 | + }); |
| 186 | + |
| 187 | + const lib_compiler = b.addStaticLibrary(.{ |
| 188 | + .name = "libmufiz_compiler", |
| 189 | + .target = b.resolveTargetQuery(target), |
| 190 | + .optimize = .ReleaseFast, |
| 191 | + .link_libc = true, |
| 192 | + .root_source_file = b.path("src/compiler.zig"), |
| 193 | + }); |
| 194 | + |
| 195 | + const lib_debug = b.addStaticLibrary(.{ |
| 196 | + .name = "libmufiz_debug", |
| 197 | + .target = b.resolveTargetQuery(target), |
| 198 | + .optimize = .ReleaseFast, |
| 199 | + .link_libc = true, |
| 200 | + .root_source_file = b.path("src/debug.zig"), |
| 201 | + }); |
166 | 202 |
|
167 |
| - lib_table.addIncludePath(b.path("include/")); |
| 203 | + const lib_cstd = b.addStaticLibrary(.{ |
| 204 | + .name = "libmufiz_cstd", |
| 205 | + .target = b.resolveTargetQuery(target), |
| 206 | + .optimize = .ReleaseFast, |
| 207 | + .link_libc = true, |
| 208 | + .root_source_file = b.path("src/cstd.zig"), |
| 209 | + }); |
| 210 | + |
| 211 | + lib_value.addIncludePath(b.path("include")); |
| 212 | + lib_memory.addIncludePath(b.path("include")); |
| 213 | + lib_chunk.addIncludePath(b.path("include")); |
| 214 | + lib_compiler.addIncludePath(b.path("include")); |
| 215 | + lib_debug.addIncludePath(b.path("include")); |
| 216 | + lib_cstd.addIncludePath(b.path("include")); |
| 217 | + |
| 218 | + lib_table.linkLibrary(lib_value); |
| 219 | + lib_table.linkLibrary(lib_memory); |
| 220 | + lib_table.addCSourceFiles(.{ |
| 221 | + .root = b.path("core"), |
| 222 | + .files = &.{ |
| 223 | + // "value.c", |
| 224 | + //"memory.c", |
| 225 | + "object.c", |
| 226 | + }, |
| 227 | + .flags = c_flags, |
| 228 | + }); |
| 229 | + |
| 230 | + lib_table.addIncludePath(b.path("include")); |
168 | 231 |
|
169 | 232 | exe.linkLibrary(lib_table);
|
| 233 | + exe.linkLibrary(lib_chunk); |
| 234 | + exe.linkLibrary(lib_compiler); |
| 235 | + exe.linkLibrary(lib_debug); |
| 236 | + exe.linkLibrary(lib_cstd); |
170 | 237 |
|
171 | 238 | exe.linkLibrary(lib_scanner);
|
172 | 239 |
|
| 240 | + const c_files: []const []const u8 = &.{ |
| 241 | + // "chunk.c", |
| 242 | + // "compiler.c", |
| 243 | + // "debug.c", |
| 244 | + "vm.c", |
| 245 | + // "cstd.c", |
| 246 | + }; |
| 247 | + |
173 | 248 | // zig fmt: off
|
174 | 249 | exe.addCSourceFiles(.{
|
175 |
| - .files = &.{ |
176 |
| - "core/chunk.c", |
177 |
| - "core/compiler.c", |
178 |
| - "core/debug.c", |
179 |
| - "core/vm.c", |
180 |
| - "core/cstd.c", |
181 |
| - }, |
| 250 | + .root = b.path("core"), |
| 251 | + .files = c_files, |
182 | 252 | .flags = c_flags
|
183 | 253 | });
|
184 |
| - exe.addIncludePath(b.path("include/")); |
| 254 | + exe.addIncludePath(b.path("include")); |
185 | 255 | exe.linkSystemLibrary("m");
|
186 | 256 |
|
187 | 257 | const clap = b.dependency("clap", .{
|
|
0 commit comments