Skip to content
This repository was archived by the owner on Nov 22, 2025. It is now read-only.

Commit d3a19c3

Browse files
committed
update arocc and import it in a way that respects its build script
this also patches some functions to be pub
1 parent 423460c commit d3a19c3

23 files changed

+2668
-1078
lines changed

arocc/build.zig

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
const std = @import("std");
2-
const Builder = std.build.Builder;
3-
4-
fn addFuzzStep(b: *Builder, target: std.zig.CrossTarget) !void {
5-
const fuzz_lib = b.addStaticLibrary("fuzz-lib", "test/fuzz/fuzz_lib.zig");
6-
fuzz_lib.addPackagePath("aro", "src/lib.zig");
7-
fuzz_lib.setTarget(target);
8-
fuzz_lib.setBuildMode(.Debug);
2+
const Build = std.Build;
3+
4+
fn addFuzzStep(b: *Build, target: std.zig.CrossTarget) !void {
5+
const fuzz_lib = b.addStaticLibrary(.{
6+
.name = "fuzz-lib",
7+
.target = target,
8+
.optimize = .Debug,
9+
.root_source_file = .{ .path = "test/fuzz/fuzz_lib.zig" },
10+
});
11+
fuzz_lib.addAnonymousModule("aro", .{ .source_file = .{ .path = "src/lib.zig" } });
912
fuzz_lib.want_lto = true;
1013
fuzz_lib.bundle_compiler_rt = true;
1114

1215
const fuzz_executable_name = "fuzz";
13-
const fuzz_exe_path = try std.fs.path.join(b.allocator, &.{ b.cache_root, fuzz_executable_name });
16+
const fuzz_exe_path = try b.cache_root.join(b.allocator, &.{fuzz_executable_name});
1417

1518
// We want `afl-clang-lto -o path/to/output test/fuzz/main.c path/to/library`
1619
const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path, "test/fuzz/main.c" });
@@ -26,7 +29,7 @@ fn addFuzzStep(b: *Builder, target: std.zig.CrossTarget) !void {
2629
fuzz_compile_run.dependOn(&fuzz_install.step);
2730
}
2831

29-
pub fn build(b: *Builder) !void {
32+
pub fn build(b: *Build) !void {
3033
// Standard target options allows the person running `zig build` to choose
3134
// what target to build for. Here we do not override the defaults, which
3235
// means any target is allowed, and the default is native. Other options
@@ -35,20 +38,31 @@ pub fn build(b: *Builder) !void {
3538

3639
// Standard release options allow the person running `zig build` to select
3740
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
38-
const mode = b.standardReleaseOptions();
41+
const mode = b.standardOptimizeOption(.{});
3942

4043
const test_all_allocation_failures = b.option(bool, "test-all-allocation-failures", "Test all allocation failures") orelse false;
4144
const link_libc = b.option(bool, "link-libc", "Force self-hosted compiler to link libc") orelse (mode != .Debug);
4245
const tracy = b.option([]const u8, "tracy", "Enable Tracy integration. Supply path to Tracy source");
4346
const tracy_callstack = b.option(bool, "tracy-callstack", "Include callstack information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
4447
const tracy_allocation = b.option(bool, "tracy-allocation", "Include allocation information with Tracy data. Does nothing if -Dtracy is not provided") orelse false;
4548

46-
const zig_pkg = std.build.Pkg{
47-
.name = "zig",
48-
.source = .{ .path = "deps/zig/lib.zig" },
49-
};
49+
const zig_module = b.createModule(.{
50+
.source_file = .{ .path = "deps/zig/lib.zig" },
51+
});
52+
const aro_module = b.addModule("aro", .{
53+
.source_file = .{ .path = "src/lib.zig" },
54+
.dependencies = &.{.{
55+
.name = "zig",
56+
.module = zig_module,
57+
}},
58+
});
5059

51-
const exe = b.addExecutable("arocc", "src/main.zig");
60+
const exe = b.addExecutable(.{
61+
.name = "arocc",
62+
.root_source_file = .{ .path = "src/main.zig" },
63+
.optimize = mode,
64+
.target = target,
65+
});
5266
const exe_options = b.addOptions();
5367
exe.addOptions("build_options", exe_options);
5468
exe_options.addOption(bool, "enable_tracy", tracy != null);
@@ -76,52 +90,38 @@ pub fn build(b: *Builder) !void {
7690
exe.linkSystemLibrary("ws2_32");
7791
}
7892
}
79-
exe.setTarget(target);
80-
exe.setBuildMode(mode);
81-
exe.addPackage(zig_pkg);
93+
exe.addModule("zig", zig_module);
8294
if (link_libc) {
8395
exe.linkLibC();
8496
}
85-
exe.install();
86-
87-
const run_cmd = exe.run();
88-
run_cmd.expected_exit_code = null;
89-
run_cmd.step.dependOn(b.getInstallStep());
90-
if (b.args) |args| {
91-
run_cmd.addArgs(args);
92-
}
93-
94-
const run_step = b.step("run", "Run the app");
95-
run_step.dependOn(&run_cmd.step);
97+
b.installArtifact(exe);
9698

9799
const tests_step = b.step("test", "Run all tests");
98100
tests_step.dependOn(&exe.step);
99101

100-
var unit_tests = b.addTest("src/main.zig");
101-
unit_tests.addPackage(zig_pkg);
102+
var unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/main.zig" } });
103+
unit_tests.addModule("zig", zig_module);
102104
tests_step.dependOn(&unit_tests.step);
103105

104-
const integration_tests = b.addExecutable("arocc", "test/runner.zig");
105-
integration_tests.addPackage(.{
106-
.name = "aro",
107-
.source = .{ .path = "src/lib.zig" },
108-
.dependencies = &.{zig_pkg},
106+
const integration_tests = b.addExecutable(.{
107+
.name = "test-runner",
108+
.root_source_file = .{ .path = "test/runner.zig" },
109109
});
110+
integration_tests.addModule("aro", aro_module);
110111
const test_runner_options = b.addOptions();
111112
integration_tests.addOptions("build_options", test_runner_options);
112113
test_runner_options.addOption(bool, "test_all_allocation_failures", test_all_allocation_failures);
113114

114-
const integration_test_runner = integration_tests.run();
115+
const integration_test_runner = b.addRunArtifact(integration_tests);
115116
integration_test_runner.addArg(b.pathFromRoot("test/cases"));
116117
integration_test_runner.addArg(b.zig_exe);
117118

118-
const record_tests = b.addExecutable("arocc", "test/record_runner.zig");
119-
record_tests.addPackage(.{
120-
.name = "aro",
121-
.source = .{ .path = "src/lib.zig" },
122-
.dependencies = &.{zig_pkg},
119+
const record_tests = b.addExecutable(.{
120+
.name = "test-runner",
121+
.root_source_file = .{ .path = "test/record_runner.zig" },
123122
});
124-
const record_tests_runner = record_tests.run();
123+
record_tests.addModule("aro", aro_module);
124+
const record_tests_runner = b.addRunArtifact(record_tests);
125125
record_tests_runner.addArg(b.pathFromRoot("test/records"));
126126
record_tests_runner.addArg(b.zig_exe);
127127

0 commit comments

Comments
 (0)