From 733b7a8da2301f2f5dcf64009f35d53fb33ffb3a Mon Sep 17 00:00:00 2001 From: Ian Johnson Date: Tue, 2 Jan 2024 22:25:39 -0500 Subject: [PATCH] build: update for Zig master --- bench/build.zig | 7 ++++--- bench/build.zig.zon | 4 ++-- build.zig | 25 +++++++++++++------------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/bench/build.zig b/bench/build.zig index a340a94..c4d185e 100644 --- a/bench/build.zig +++ b/bench/build.zig @@ -6,15 +6,15 @@ pub fn build(b: *Build) !void { const xml = b.dependency("xml", .{}).module("xml"); const bench_scanner = addBench(b, "scanner"); - bench_scanner.addModule("xml", xml); + bench_scanner.root_module.addImport("xml", xml); bench_scanner.linkLibC(); const bench_token_reader = addBench(b, "token_reader"); - bench_token_reader.addModule("xml", xml); + bench_token_reader.root_module.addImport("xml", xml); bench_token_reader.linkLibC(); const bench_reader = addBench(b, "reader"); - bench_reader.addModule("xml", xml); + bench_reader.root_module.addImport("xml", xml); bench_reader.linkLibC(); const libxml2 = b.dependency("libxml2", .{ @@ -70,6 +70,7 @@ fn addBench(b: *Build, name: []const u8) *Step.Compile { const exe = b.addExecutable(.{ .name = name, .root_source_file = .{ .path = b.fmt("src/{s}.zig", .{name}) }, + .target = b.host, .optimize = .ReleaseFast, }); b.installArtifact(exe); diff --git a/bench/build.zig.zon b/bench/build.zig.zon index f4fca46..98c7d61 100644 --- a/bench/build.zig.zon +++ b/bench/build.zig.zon @@ -13,8 +13,8 @@ }, .libxml2 = .{ // https://github.com/mitchellh/zig-build-libxml2/pull/1 - .url = "git+https://github.com/ianprime0509/zig-build-libxml2#e4ab543bf441bb2e1f4e9251b1d5c415602ba269", - .hash = "1220c48add849a9e9fa9c9b84e0c37b5843f7cefb45a98dab57a08daa772d273f810", + .url = "git+https://github.com/ianprime0509/zig-build-libxml2#4d1b7db156b0e7a19127c652adefdf27799770ab", + .hash = "122011b13203141cc965cfe6b070ffb5a8835eb906bb2cfd4650dbc17574e6e36fd5", }, .mxml = .{ .url = "git+https://github.com/michaelrsweet/mxml.git#809204a3051607f54b57e2950f3a5520d79ae383", diff --git a/build.zig b/build.zig index b24ab03..17e107c 100644 --- a/build.zig +++ b/build.zig @@ -1,13 +1,14 @@ const std = @import("std"); const Build = std.Build; -const CrossTarget = std.zig.CrossTarget; const Mode = std.builtin.Mode; pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const xml = b.addModule("xml", .{ .source_file = .{ .path = "src/xml.zig" } }); + const xml = b.addModule("xml", .{ + .root_source_file = .{ .path = "src/xml.zig" }, + }); addTests(b, target, optimize, xml); addDocs(b, target); @@ -15,7 +16,7 @@ pub fn build(b: *Build) void { addFuzz(b, target, xml); } -fn addTests(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Module) void { +fn addTests(b: *Build, target: Build.ResolvedTarget, optimize: Mode, xml: *Build.Module) void { const main_tests = b.addTest(.{ .root_source_file = .{ .path = "src/xml.zig" }, .target = target, @@ -33,7 +34,7 @@ fn addTests(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Module) .target = target, .optimize = optimize, }); - xmlconf_exe.addModule("xml", xml); + xmlconf_exe.root_module.addImport("xml", xml); const install_xmlconf_step = b.step("install-xmlconf", "Install xmlconf test runner"); install_xmlconf_step.dependOn(&b.addInstallArtifact(xmlconf_exe, .{}).step); @@ -68,7 +69,7 @@ fn addTests(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Module) run_xmlconf_step.dependOn(&run_xmlconf_exe.step); } -fn addDocs(b: *Build, target: CrossTarget) void { +fn addDocs(b: *Build, target: Build.ResolvedTarget) void { const obj = b.addObject(.{ .name = "zig-xml", .root_source_file = .{ .path = "src/xml.zig" }, @@ -87,7 +88,7 @@ fn addDocs(b: *Build, target: CrossTarget) void { docs_step.dependOn(&install_docs.step); } -fn addExamples(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Module) void { +fn addExamples(b: *Build, target: Build.ResolvedTarget, optimize: Mode, xml: *Build.Module) void { const install_examples_step = b.step("install-examples", "Install examples"); const scan_exe = b.addExecutable(.{ @@ -96,7 +97,7 @@ fn addExamples(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Modul .target = target, .optimize = optimize, }); - scan_exe.addModule("xml", xml); + scan_exe.root_module.addImport("xml", xml); install_examples_step.dependOn(&b.addInstallArtifact(scan_exe, .{}).step); const run_scan_exe = b.addRunArtifact(scan_exe); @@ -113,7 +114,7 @@ fn addExamples(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Modul .target = target, .optimize = optimize, }); - read_exe.addModule("xml", xml); + read_exe.root_module.addImport("xml", xml); install_examples_step.dependOn(&b.addInstallArtifact(read_exe, .{}).step); const run_read_exe = b.addRunArtifact(read_exe); @@ -125,7 +126,7 @@ fn addExamples(b: *Build, target: CrossTarget, optimize: Mode, xml: *Build.Modul run_read_step.dependOn(&run_read_exe.step); } -fn addFuzz(b: *Build, target: CrossTarget, xml: *Build.Module) void { +fn addFuzz(b: *Build, target: Build.ResolvedTarget, xml: *Build.Module) void { // Thanks to https://www.ryanliptak.com/blog/fuzzing-zig-code/ for the basis of this! const fuzz_lib = b.addStaticLibrary(.{ .name = "fuzz", @@ -135,7 +136,7 @@ fn addFuzz(b: *Build, target: CrossTarget, xml: *Build.Module) void { }); fuzz_lib.want_lto = true; fuzz_lib.bundle_compiler_rt = true; - fuzz_lib.addModule("xml", xml); + fuzz_lib.root_module.addImport("xml", xml); const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o" }); const fuzz_exe = fuzz_compile.addOutputFileArg("fuzz"); @@ -157,7 +158,7 @@ fn addFuzz(b: *Build, target: CrossTarget, xml: *Build.Module) void { for (dictionaries) |dictionary| { run_fuzz.addArgs(&.{ "-x", b.pathJoin(&.{ "fuzz", "dictionaries", dictionary }) }); } - run_fuzz.addFileSourceArg(fuzz_exe); + run_fuzz.addFileArg(fuzz_exe); const run_fuzz_step = b.step("fuzz", "Execute afl-fuzz with the fuzz testing executable"); run_fuzz_step.dependOn(&run_fuzz.step); @@ -167,7 +168,7 @@ fn addFuzz(b: *Build, target: CrossTarget, xml: *Build.Module) void { .target = target, .optimize = .Debug, }); - fuzz_reproduce_exe.addModule("xml", xml); + fuzz_reproduce_exe.root_module.addImport("xml", xml); const run_fuzz_reproduce_exe = b.addRunArtifact(fuzz_reproduce_exe); if (b.args) |args| {