Skip to content

Commit

Permalink
Update for latest Zig build system changes
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 authored and Vexu committed Jan 6, 2024
1 parent 375dedb commit 86cc098
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
38 changes: 20 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const aro_version = std.SemanticVersion{
.patch = 0,
};

fn addFuzzStep(b: *Build, target: std.zig.CrossTarget, afl_clang_lto_path: []const u8, aro_module: *std.Build.Module) !void {
fn addFuzzStep(b: *Build, target: std.Build.ResolvedTarget, afl_clang_lto_path: []const u8, aro_module: *std.Build.Module) !void {
const fuzz_step = b.step("fuzz", "Build executable for fuzz testing.");
var fuzz_target = target;
fuzz_target.ofmt = .c;
fuzz_target.result.ofmt = .c;

const lib_dir_step = try ZigLibDirStep.create(b);

const compiler_rt = b.createModule(.{
.source_file = lib_dir_step.getCompilerRTPath(),
.root_source_file = lib_dir_step.getCompilerRTPath(),
});
const fuzz_lib = b.addStaticLibrary(.{
.name = "fuzz-lib",
Expand All @@ -26,9 +26,9 @@ fn addFuzzStep(b: *Build, target: std.zig.CrossTarget, afl_clang_lto_path: []con
.target = fuzz_target,
.single_threaded = true,
});
fuzz_lib.addModule("compiler_rt", compiler_rt);
fuzz_lib.root_module.addImport("compiler_rt", compiler_rt);

fuzz_lib.addModule("aro", aro_module);
fuzz_lib.root_module.addImport("aro", aro_module);
const fuzz_compile = b.addSystemCommand(&.{
afl_clang_lto_path,
"-Wno-incompatible-pointer-types",
Expand Down Expand Up @@ -144,11 +144,11 @@ pub fn build(b: *Build) !void {
const aro_options_module = aro_options.createModule();

const zig_module = b.createModule(.{
.source_file = .{ .path = "deps/zig/lib.zig" },
.root_source_file = .{ .path = "deps/zig/lib.zig" },
});
const aro_backend = b.addModule("aro_backend", .{
.source_file = .{ .path = "src/backend.zig" },
.dependencies = &.{
.root_source_file = .{ .path = "src/backend.zig" },
.imports = &.{
.{
.name = "zig",
.module = zig_module,
Expand All @@ -160,8 +160,8 @@ pub fn build(b: *Build) !void {
},
});
const aro_module = b.addModule("aro", .{
.source_file = .{ .path = "src/aro.zig" },
.dependencies = &.{
.root_source_file = .{ .path = "src/aro.zig" },
.imports = &.{
.{
.name = "system_defaults",
.module = system_defaults.createModule(),
Expand Down Expand Up @@ -193,7 +193,7 @@ pub fn build(b: *Build) !void {
.target = target,
.single_threaded = true,
});
exe.addModule("aro", aro_module);
exe.root_module.addImport("aro", aro_module);

// tracy integration
if (tracy) |tracy_path| {
Expand All @@ -203,7 +203,7 @@ pub fn build(b: *Build) !void {
) catch unreachable;

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
const tracy_c_flags: []const []const u8 = if (target.result.isMinGW())
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
Expand All @@ -213,7 +213,7 @@ pub fn build(b: *Build) !void {
exe.linkLibCpp();
exe.linkLibC();

if (target.isWindows()) {
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("dbghelp");
exe.linkSystemLibrary("ws2_32");
}
Expand All @@ -226,8 +226,8 @@ pub fn build(b: *Build) !void {
const tests_step = b.step("test", "Run all tests");

var unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/aro.zig" } });
for (aro_module.dependencies.keys(), aro_module.dependencies.values()) |name, module| {
unit_tests.addModule(name, module);
for (aro_module.import_table.keys(), aro_module.import_table.values()) |name, module| {
unit_tests.root_module.addImport(name, module);
}
const run_test = b.addRunArtifact(unit_tests);
tests_step.dependOn(&run_test.step);
Expand All @@ -236,10 +236,11 @@ pub fn build(b: *Build) !void {
.name = "test-runner",
.root_source_file = .{ .path = "test/runner.zig" },
.optimize = mode,
.target = target,
});
integration_tests.addModule("aro", aro_module);
integration_tests.root_module.addImport("aro", aro_module);
const test_runner_options = b.addOptions();
integration_tests.addOptions("build_options", test_runner_options);
integration_tests.root_module.addOptions("build_options", test_runner_options);
test_runner_options.addOption(bool, "test_all_allocation_failures", test_all_allocation_failures);

const integration_test_runner = b.addRunArtifact(integration_tests);
Expand All @@ -250,8 +251,9 @@ pub fn build(b: *Build) !void {
.name = "record-runner",
.root_source_file = .{ .path = "test/record_runner.zig" },
.optimize = mode,
.target = target,
});
record_tests.addModule("aro", aro_module);
record_tests.root_module.addImport("aro", aro_module);
const record_tests_runner = b.addRunArtifact(record_tests);
record_tests_runner.addArg(b.pathFromRoot("test/records"));

Expand Down
4 changes: 2 additions & 2 deletions build/GenerateDef.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub const Options = struct {
pub const Kind = enum { dafsa, named };
};

pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency {
pub fn create(owner: *std.Build, options: Options) std.Build.Module.Import {
const self = owner.allocator.create(GenerateDef) catch @panic("OOM");
const path = owner.pathJoin(&.{ options.src_prefix, options.name });

Expand All @@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency {
.generated_file = .{ .step = &self.step },
};
const module = self.step.owner.createModule(.{
.source_file = .{ .generated = &self.generated_file },
.root_source_file = .{ .generated = &self.generated_file },
});
return .{
.module = module,
Expand Down
9 changes: 6 additions & 3 deletions src/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,15 @@ pub fn parseArgs(
} else if (mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--assemble")) {
d.only_preprocess_and_compile = true;
} else if (option(arg, "--target=")) |triple| {
const cross = std.zig.CrossTarget.parse(.{ .arch_os_abi = triple }) catch {
const query = std.Target.Query.parse(.{ .arch_os_abi = triple }) catch {
try d.comp.addDiagnostic(.{ .tag = .cli_invalid_target, .extra = .{ .str = arg } }, &.{});
continue;
};
d.comp.target = cross.toTarget(); // TODO deprecated
d.comp.langopts.setEmulatedCompiler(target_util.systemCompiler(d.comp.target));
const target = std.zig.system.resolveTargetQuery(query) catch |e| {
return d.fatal("unable to resolve target: {s}", .{errorDescription(e)});
};
d.comp.target = target;
d.comp.langopts.setEmulatedCompiler(target_util.systemCompiler(target));
d.raw_target_triple = triple;
} else if (mem.eql(u8, arg, "--verbose-ast")) {
d.verbose_ast = true;
Expand Down
6 changes: 4 additions & 2 deletions src/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ test "minUnsignedBits" {

var comp = Compilation.init(std.testing.allocator);
defer comp.deinit();
comp.target = (try std.zig.CrossTarget.parse(.{ .arch_os_abi = "x86_64-linux-gnu" })).toTarget();
const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
comp.target = try std.zig.system.resolveTargetQuery(target_query);

try Test.checkIntBits(&comp, 0, 0);
try Test.checkIntBits(&comp, 1, 1);
Expand Down Expand Up @@ -94,7 +95,8 @@ test "minSignedBits" {

var comp = Compilation.init(std.testing.allocator);
defer comp.deinit();
comp.target = (try std.zig.CrossTarget.parse(.{ .arch_os_abi = "x86_64-linux-gnu" })).toTarget();
const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
comp.target = try std.zig.system.resolveTargetQuery(target_query);

try Test.checkIntBits(&comp, -1, 1);
try Test.checkIntBits(&comp, -2, 2);
Expand Down
4 changes: 2 additions & 2 deletions src/aro/toolchains/Linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ test Linux {
defer comp.environment = .{};

const raw_triple = "x86_64-linux-gnu";
const cross = std.zig.CrossTarget.parse(.{ .arch_os_abi = raw_triple }) catch unreachable;
comp.target = cross.toTarget(); // TODO deprecated
const target_query = try std.Target.Query.parse(.{ .arch_os_abi = raw_triple });
comp.target = try std.zig.system.resolveTargetQuery(target_query);
comp.langopts.setEmulatedCompiler(.gcc);

var driver: Driver = .{ .comp = &comp };
Expand Down

0 comments on commit 86cc098

Please sign in to comment.