Skip to content

Commit

Permalink
build: update for Zig master (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianprime0509 authored Jan 5, 2024
1 parent 2b5bbd4 commit 5d995ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
7 changes: 4 additions & 3 deletions bench/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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", .{
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions bench/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 13 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
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);
addExamples(b, target, optimize, xml);
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,
Expand All @@ -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);
Expand Down Expand Up @@ -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" },
Expand All @@ -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(.{
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -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");
Expand All @@ -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);

Expand All @@ -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| {
Expand Down

0 comments on commit 5d995ef

Please sign in to comment.