Skip to content

Commit 86900ca

Browse files
committed
refactor static lib files to lib/ directory, cleaned up value.zig bindings, updated pkgman to get version from zon file
1 parent 7439deb commit 86900ca

12 files changed

+41913
-295
lines changed

build.zig

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn build(b: *std.Build) !void {
5252

5353
const lib_scanner = b.addStaticLibrary(.{
5454
.name = "libmufiz_scanner",
55-
.root_source_file = b.path("src/scanner.zig"),
55+
.root_source_file = b.path("lib/scanner.zig"),
5656
.target = target,
5757
.optimize = .ReleaseFast,
5858
.link_libc = true,
@@ -63,55 +63,55 @@ pub fn build(b: *std.Build) !void {
6363
.target = target,
6464
.optimize = .ReleaseFast,
6565
.link_libc = true,
66-
.root_source_file = b.path("src/table.zig"),
66+
.root_source_file = b.path("lib/table.zig"),
6767
});
6868

6969
const lib_value = b.addStaticLibrary(.{
7070
.name = "libmufiz_value",
7171
.target = target,
7272
.optimize = .ReleaseFast,
7373
.link_libc = true,
74-
.root_source_file = b.path("src/value.zig"),
74+
.root_source_file = b.path("lib/value.zig"),
7575
});
7676

7777
const lib_memory = b.addStaticLibrary(.{
7878
.name = "libmufiz_memory",
7979
.target = target,
8080
.optimize = .ReleaseFast,
8181
.link_libc = true,
82-
.root_source_file = b.path("src/memory.zig"),
82+
.root_source_file = b.path("lib/memory.zig"),
8383
});
8484

8585
const lib_chunk = b.addStaticLibrary(.{
8686
.name = "libmufiz_chunk",
8787
.target = target,
8888
.optimize = .ReleaseFast,
8989
.link_libc = true,
90-
.root_source_file = b.path("src/chunk.zig"),
90+
.root_source_file = b.path("lib/chunk.zig"),
9191
});
9292

9393
const lib_compiler = b.addStaticLibrary(.{
9494
.name = "libmufiz_compiler",
9595
.target = target,
9696
.optimize = .ReleaseFast,
9797
.link_libc = true,
98-
.root_source_file = b.path("src/compiler.zig"),
98+
.root_source_file = b.path("lib/compiler.zig"),
9999
});
100100

101101
const lib_debug = b.addStaticLibrary(.{
102102
.name = "libmufiz_debug",
103103
.target = target,
104104
.optimize = .ReleaseFast,
105105
.link_libc = true,
106-
.root_source_file = b.path("src/debug.zig"),
106+
.root_source_file = b.path("lib/debug.zig"),
107107
});
108108

109109
const lib_cstd = b.addStaticLibrary(.{
110110
.name = "libmufiz_cstd",
111111
.target = target,
112112
.optimize = .ReleaseFast,
113113
.link_libc = true,
114-
.root_source_file = b.path("src/cstd.zig"),
114+
.root_source_file = b.path("lib/cstd.zig"),
115115
});
116116

117117
lib_value.addIncludePath(b.path("include"));
@@ -218,7 +218,7 @@ pub fn build(b: *std.Build) !void {
218218
const run_step = b.step("run", "Run the app");
219219
run_step.dependOn(&run_cmd.step);
220220

221-
const exe_test = b.addTest(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize });
221+
const exe_test = b.addTest(.{ .root_source_file = b.path("lib/main.zig"), .target = target, .optimize = optimize });
222222
exe_test.linkLibC();
223223
exe_test.addCSourceFiles(.{ .root = b.path("core"), .files = c_files, .flags = c_flags });
224224
exe_test.linkLibrary(lib_scanner);

build_multi.zig

+87-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33

4+
const zig_version = "0.13.0";
5+
46
comptime {
5-
const supported_version = std.SemanticVersion.parse("0.13.0") catch unreachable;
7+
const supported_version = std.SemanticVersion.parse(zig_version) catch unreachable;
68
if (builtin.zig_version.order(supported_version) != .eq) {
79
@compileError(std.fmt.comptimePrint("Unsupported Zig version ({}). Required Zig version 0.13.0.", .{builtin.zig_version}));
810
}
@@ -58,7 +60,7 @@ pub fn build(b: *std.Build) !void {
5860
options.addOption(bool, "sandbox", sandbox);
5961

6062
for (targets) |target| {
61-
try build_target(b, target, options);
63+
try buildTarget(b, target, options);
6264
}
6365
}
6466

@@ -114,7 +116,7 @@ fn common(optimize: std.builtin.OptimizeMode) !void {
114116
}
115117
}
116118

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 {
118120
var c_flags: []const []const u8 = undefined;
119121
if (target.cpu_arch == .x86_64) {
120122
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
158160
.root_source_file = b.path("src/table.zig"),
159161
});
160162

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+
});
166202

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"));
168231

169232
exe.linkLibrary(lib_table);
233+
exe.linkLibrary(lib_chunk);
234+
exe.linkLibrary(lib_compiler);
235+
exe.linkLibrary(lib_debug);
236+
exe.linkLibrary(lib_cstd);
170237

171238
exe.linkLibrary(lib_scanner);
172239

240+
const c_files: []const []const u8 = &.{
241+
// "chunk.c",
242+
// "compiler.c",
243+
// "debug.c",
244+
"vm.c",
245+
// "cstd.c",
246+
};
247+
173248
// zig fmt: off
174249
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,
182252
.flags = c_flags
183253
});
184-
exe.addIncludePath(b.path("include/"));
254+
exe.addIncludePath(b.path("include"));
185255
exe.linkSystemLibrary("m");
186256

187257
const clap = b.dependency("clap", .{
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)