// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie // // SPDX-License-Identifier: MIT const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); // The debugger is an emulator, and one built for being stepped through // rather than for running is the difference between a machine that keeps // up with the one it is pretending to be and one that does not: six times // the speed, measured, and most of that in the processor itself. So it is // built optimised unless a mode was actually asked for, while everything // else, the tests above all, keeps Zig's own default. // // Optimised *with the safety checks kept*. Everything the emulated machine // does -- every address it reads, every block it asks for, every register // it writes -- ends in an index into some array of the host's, and an audit // found every one of them bounded. ReleaseSafe is what turns that from an // audit into a guarantee: a bound that is missed some day traps instead of // becoming undefined behaviour with a 6502 program on the other end of it. // It was measured before it was chosen. Against ReleaseFast the cost is // within noise on the machines themselves -- a IIe emulates at 67 times // real speed either way -- and six to twelve per cent on the synthetic // cores, which have sixty times more headroom than they need. The six-fold // figure above is Debug's penalty, not this one's. const mode_was_asked_for = b.user_input_options.contains("optimize") or b.release_mode != .off; const app_optimize: std.builtin.OptimizeMode = if (mode_was_asked_for) optimize else .ReleaseSafe; // Turning a screen into pixels and a file, which src/picture.zig is the // only user of: everything else here works in dots and palette numbers, // which is what the machines deal in. const z2d = b.dependency("z2d", .{ .target = target, .optimize = optimize, }); const z2d_shipped = b.dependency("z2d", .{ .target = target, .optimize = app_optimize, }); // Reading and writing ShrinkIt archives -- the NuFX format and the two LZW // compressors inside it -- which src/diskfile.zig and src/writeback.zig use // to unpack a disk out of a `.SHK`/`.SDK` and to put a modified one back. // It is the user's own project, and it replaces what used to be an // uncompressed-only reimplementation here in src/shrinkit.zig. const shrinkit = b.dependency("shrinkit", .{ .target = target, .optimize = optimize, }); const shrinkit_shipped = b.dependency("shrinkit", .{ .target = target, .optimize = app_optimize, }); const zig65 = b.addModule("zig65", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "z2d", .module = z2d.module("z2d") }, .{ .name = "shrinkit", .module = shrinkit.module("shrinkit") }, }, }); // The library again at the mode the debugger ships in, which is what the // benchmarks and the tools measure and what the debugger is built from when // no mode was asked for: a build of any other mode is one nobody runs. const zig65_shipped = b.addModule("zig65_shipped", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "z2d", .module = z2d_shipped.module("z2d") }, .{ .name = "shrinkit", .module = shrinkit_shipped.module("shrinkit") }, }, }); // At the debugger's own mode: drawing the screen is the other half of // where its time goes. const vaxis = b.dependency("vaxis", .{ .target = target, .optimize = app_optimize, }); // The configuration file's format. A debugger with this many switches is // easier to point at a machine once and keep, and Ziggy is a small typed // language for exactly that: it reads like what it is, it says what went // wrong and where, and a Zig program gets a struct out of it rather than a // bag of strings. const ziggy = b.dependency("ziggy", .{}).module("ziggy"); // The user's own parsers: z46 for IP addresses, macaddress for MAC // addresses. Pure-Zig modules with no options, so one instance of each is // shared by every module that needs it, the way ziggy is. The library uses // both (in `ethernet.zig`); the IIgs front end uses z46 through the // LocalTalk bridge it compiles in. const z46 = b.dependency("z46", .{}).module("z46"); const macaddress = b.dependency("macaddress", .{}).module("macaddress"); for ([_]*std.Build.Module{ zig65, zig65_shipped }) |m| { m.addImport("z46", z46); m.addImport("macaddress", macaddress); } // Live audio: the machine's sound out of a real speaker rather than only // into a `.wav`. This is the user's own PipeWire client, pure Zig talking // to the daemon's socket -- no libpipewire, no C -- so it adds no system // dependency and only wants a daemon running to make a sound. It is Linux's // way of doing it; `tools/audio.zig` is shaped so another platform's is a // second backend beside it. const pipewire = b.dependency("pipewire", .{ .target = target, .optimize = app_optimize, }); // The user's own ImageWriter II emulator: the bytes of a print stream in, // rendered pages out. It implements `std.Io.Writer`, so the front end hands // its face to the serial card as the sink the card's output drains into. // Only the front end knows about it -- the library's cards take a // `*std.Io.Writer` and do not care what is on the other end -- so it is not // an import of the `zig65` library module, only of the executable. const imagewriter2 = b.dependency("imagewriter2", .{ .target = target, .optimize = app_optimize, }); // The audio sink both front ends share: turning the samples the library // renders into live sound, with a volume and mute over the top. Kept out // of the library proper -- which stays about machines, not about this // host's audio -- and beside terminal.zig and config.zig, which the front // ends share for the same reason. const audio = b.createModule(.{ .root_source_file = b.path("tools/audio.zig"), .target = target, .optimize = app_optimize, .imports = &.{.{ .name = "pipewire", .module = pipewire.module("pipewire") }}, }); // The configuration file, shared by both front ends the way terminal.zig // is: neither the debugger nor gs should have its own idea of what a // machine written down looks like. const config = b.createModule(.{ .root_source_file = b.path("tools/config.zig"), .target = target, .optimize = app_optimize, .imports = &.{.{ .name = "ziggy", .module = ziggy }}, }); // const ehbasic = b.dependency("ehbasic", .{ // .target = target, // .optimize = optimize, // }); // No ROM is built into the executable any more; it takes a --rom path // instead. Nothing references these, so nothing fetches them. // const apple_2p_rom = b.dependency("apple_2p_rom", .{ // .target = target, // .optimize = optimize, // }); // const apple_2e_rom = b.dependency("apple_2e_rom", .{ // .target = target, // .optimize = optimize, // }); // const allsuitea = b.dependency("allsuitea", .{ // .target = target, // .optimize = optimize, // }); // The screen and keyboard bits the two front ends share: the debugger and // the IIgs are different programs, but turning a keystroke into what an // Apple keyboard sent and getting a machine's screen into a terminal is // the same job twice. One executable holds both of them now, so this is // shared between two front ends of the same program rather than between // two programs. const terminal = b.addModule("terminal", .{ .root_source_file = b.path("tools/terminal.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = if (mode_was_asked_for) zig65 else zig65_shipped }, .{ .name = "vaxis", .module = vaxis.module("vaxis") }, }, }); // The machine-driving core with no front end in it, shared by any front // end the way terminal.zig is. It imports the very same library module the // programs do, so the machine it builds is the machine they hold. const session = b.createModule(.{ .root_source_file = b.path("src/session8.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = if (mode_was_asked_for) zig65 else zig65_shipped }, .{ .name = "audio", .module = audio }, }, }); // The Apple IIgs front end. One executable holds both machines now, so // this is a module of it rather than a program of its own: `--machine // iigs` runs it, and everything it shares with the debugger — the // terminal, the configuration file, the library itself — is the very same // module rather than a second copy built alongside. const gs_module = b.createModule(.{ .root_source_file = b.path("src/gs.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = if (mode_was_asked_for) zig65 else zig65_shipped }, .{ .name = "vaxis", .module = vaxis.module("vaxis") }, .{ .name = "terminal", .module = terminal }, .{ .name = "config", .module = config }, .{ .name = "audio", .module = audio }, }, }); const exe = b.addExecutable(.{ .name = "zig65", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", // The same library, built the same way as what is around // it. A fast debugger around a library built for stepping // through would be no faster at all: the processor is in // the library. .module = if (mode_was_asked_for) zig65 else zig65_shipped, }, .{ .name = "vaxis", .module = vaxis.module("vaxis"), }, .{ .name = "terminal", .module = terminal, }, .{ .name = "config", .module = config }, .{ .name = "gs", .module = gs_module }, .{ .name = "session8", .module = session }, .{ .name = "imagewriter2", .module = imagewriter2.module("imagewriter2") }, }, }), }); // exe.root_module.addAnonymousImport( // "ehbasic", // .{ // .root_source_file = ehbasic.path("ehbasic.bin"), // }, // ); // exe.root_module.addAnonymousImport( // "apple_2p_rom", // .{ // .root_source_file = apple_2p_rom.path("APPLE2.ROM"), // }, // ); // exe.root_module.addAnonymousImport( // "apple_2e_rom", // .{ // .root_source_file = apple_2e_rom.path("APPLE2E.ROM"), // }, // ); // exe.root_module.addAnonymousImport( // "allsuitea", // .{ // .root_source_file = allsuitea.path("AllSuiteA.bin"), // }, // ); // Which processor's corpus `zig build corpus` runs. This is no longer // anything to do with what gets built: every machine and every processor // is compiled into the executable and `--machine` and `--processor` choose // between them at run time. The corpus is the one thing left that has to // be told, because the traces for each chip were recorded from that chip // and there are two and a half million of them. const Processor = enum { @"6502", RP2A03, @"65C02", R65C02, W65C02 }; // The completions are embedded as well as installed, so that a test can // hold them up against the usage text and fail if the two drift apart. exe.root_module.addAnonymousImport("zig65.fish", .{ .root_source_file = b.path("completions/zig65.fish"), }); exe.root_module.addAnonymousImport("zig65.bash", .{ .root_source_file = b.path("completions/zig65.bash"), }); const processor = b.option(Processor, "processor", "which processor's corpus `zig build corpus` runs (default 6502)") orelse .@"6502"; b.installArtifact(exe); // The shell completions, put where each shell looks for the ones that came // with a package rather than with the user. Installed unconditionally: they // are two small text files, and a build that only sometimes produces them // is a build whose output depends on something nobody thought to ask about. b.installFile("completions/zig65.fish", "share/fish/vendor_completions.d/zig65.fish"); b.installFile("completions/zig65.bash", "share/bash-completion/completions/zig65"); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); const module_unit_tests = b.addTest(.{ .root_module = zig65, }); const run_module_unit_tests = b.addRunArtifact(module_unit_tests); // The executable has tests of its own, for the debugger's state machine. // The debugger's own tests keep Zig's default mode whatever the debugger // itself is built as. A test is for finding what is wrong, and the checks // that find it are the ones an optimised build turns off, so they get // their own module rather than sharing the one that is built to be fast. const test_module = if (mode_was_asked_for) exe.root_module else module: { const slow_vaxis = b.dependency("vaxis", .{ .target = target, .optimize = optimize, }); // And the shared screen and keyboard module built the same way, since // a module can only be in one build at a time. const slow_config = b.createModule(.{ .root_source_file = b.path("tools/config.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "ziggy", .module = ziggy }}, }); // The audio sink built the same way, since a module can only be in // one build at a time and this test build is at `optimize`. const slow_audio = b.createModule(.{ .root_source_file = b.path("tools/audio.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pipewire", .module = pipewire.module("pipewire") }}, }); const slow_session = b.createModule(.{ .root_source_file = b.path("src/session8.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "audio", .module = slow_audio }, }, }); const slow_terminal = b.addModule("terminal_tests", .{ .root_source_file = b.path("tools/terminal.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "vaxis", .module = slow_vaxis.module("vaxis") }, }, }); const slow_imagewriter2 = b.dependency("imagewriter2", .{ .target = target, .optimize = optimize, }); const module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "vaxis", .module = slow_vaxis.module("vaxis") }, .{ .name = "terminal", .module = slow_terminal }, .{ .name = "config", .module = slow_config }, .{ .name = "session8", .module = slow_session }, .{ .name = "imagewriter2", .module = slow_imagewriter2.module("imagewriter2") }, // The IIgs front end, which main.zig imports because one // executable holds both machines. Built the same way as what // is around it, for the same reason everything else here is. .{ .name = "gs", .module = b.createModule(.{ .root_source_file = b.path("src/gs.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "vaxis", .module = slow_vaxis.module("vaxis") }, .{ .name = "terminal", .module = slow_terminal }, .{ .name = "config", .module = slow_config }, .{ .name = "audio", .module = slow_audio }, }, }) }, }, }); module.addAnonymousImport("zig65.fish", .{ .root_source_file = b.path("completions/zig65.fish"), }); module.addAnonymousImport("zig65.bash", .{ .root_source_file = b.path("completions/zig65.bash"), }); break :module module; }; const exe_unit_tests = b.addTest(.{ .root_module = test_module, }); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); // The shared terminal module's own tests, which nothing else would run: // a module imported by a test build is compiled, not tested. const terminal_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("tools/terminal.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "vaxis", .module = b.dependency("vaxis", .{ .target = target, .optimize = optimize, }).module("vaxis") }, }, }), }); const run_terminal_tests = b.addRunArtifact(terminal_tests); // The configuration reader's own tests: what a file may say, and what it // may not. // // The schema and the two examples are embedded so that a test can hold // them up against each other and against `Config` itself, the same way the // shell completions are embedded to be held up against the usage text. const config_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("tools/config.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "ziggy", .module = ziggy }}, }), }); config_tests.root_module.addAnonymousImport("schema", .{ .root_source_file = b.path(".ziggy-schema"), }); config_tests.root_module.addAnonymousImport("apple2e.ziggy", .{ .root_source_file = b.path("examples/apple2e.ziggy"), }); config_tests.root_module.addAnonymousImport("iigs.ziggy", .{ .root_source_file = b.path("examples/iigs.ziggy"), }); const run_config_tests = b.addRunArtifact(config_tests); // The session's own tests. It is a module rather than a file of the // library, so its tests are only compiled when it is the root of a test // of its own: without this they are written and never run, which is what // happened to the first of them. const session_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/session8.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65 }, .{ .name = "audio", .module = audio }, }, }), }); const run_session_tests = b.addRunArtifact(session_tests); // And the sixteen-bit session's, for the same reason: it is the Apple // IIgs front end's half of the same job, and it is a module of `gs.zig` // rather than a file of the library, so nothing else would compile its // tests. `ltoudp.zig` sits beside it in `src/` and comes along by path. const session16_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/session16.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "zig65", .module = zig65 }}, }), }); const run_session16_tests = b.addRunArtifact(session16_tests); // And the IIgs front end's own, which are the debugger's keys. Like the // session's, they are compiled only when the module is the root of a test // build, and `gs_module` is imported by the executable rather than being // one. const gs_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/gs.zig"), .target = target, .optimize = optimize, .imports = &.{ // The same library module `terminal` was built against, and // not a second one rooted at the same file: two modules over // one file is an error, and the shared terminal already // imports this one. .{ .name = "zig65", .module = if (mode_was_asked_for) zig65 else zig65_shipped }, .{ .name = "vaxis", .module = vaxis.module("vaxis") }, .{ .name = "terminal", .module = terminal }, .{ .name = "config", .module = config }, .{ .name = "audio", .module = audio }, }, }), }); const run_gs_tests = b.addRunArtifact(gs_tests); // The audio sink's own tests -- the volume steps and the silent fallback. // Like the others it is compiled when it is a test's root; the pipewire // dependency is pure Zig and needs no daemon to compile or to test. const audio_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("tools/audio.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "pipewire", .module = pipewire.module("pipewire") }}, }), }); const run_audio_tests = b.addRunArtifact(audio_tests); const libtest_step = b.step("libtest", "Run only the library module's unit tests"); libtest_step.dependOn(&run_module_unit_tests.step); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_module_unit_tests.step); test_step.dependOn(&run_exe_unit_tests.step); test_step.dependOn(&run_terminal_tests.step); test_step.dependOn(&run_config_tests.step); test_step.dependOn(&run_session_tests.step); test_step.dependOn(&run_session16_tests.step); test_step.dependOn(&run_gs_tests.step); test_step.dependOn(&run_audio_tests.step); const coverage_step = b.step("coverage", "Generate a coverage report with kcov"); const run_kcov = b.addSystemCommand(&.{ "kcov", "--clean", "--include-pattern=src", }); const run_kcov_output = run_kcov.addOutputDirectoryArg("cover"); run_kcov.addArtifactArg(module_unit_tests); coverage_step.dependOn(&run_kcov.step); const run_kcov_install = b.addInstallDirectory(.{ .source_dir = run_kcov_output, .install_dir = .{ .custom = "kcov" }, .install_subdir = "", }); coverage_step.dependOn(&run_kcov_install.step); // How fast the processor runs. Built at the shipped mode whatever the rest // of the build is doing, since a debug build measures Debug's overhead // rather than the emulator -- and the shipped mode keeps its safety // checks, so those are measured too, as they should be. const bench_module = b.createModule(.{ .root_source_file = b.path("src/bench.zig"), .target = target, .optimize = app_optimize, }); bench_module.addImport("zig65", zig65_shipped); const bench_exe = b.addExecutable(.{ .name = "bench", .root_module = bench_module }); const bench_cmd = b.addRunArtifact(bench_exe); // A worked example of using this as a library rather than as a program. const example = b.addExecutable(.{ .name = "typing", .root_module = b.createModule(.{ .root_source_file = b.path("examples/typing.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = if (mode_was_asked_for) zig65 else zig65_shipped, }, }, }), }); const run_example = b.addRunArtifact(example); if (b.args) |args| run_example.addArgs(args); const example_step = b.step("example", "Run the embedding example: zig build example -- ROM"); example_step.dependOn(&run_example.step); const bench_step = b.step("bench", "Measure instruction throughput"); bench_step.dependOn(&bench_cmd.step); // Zig emits the API documentation as a side effect of compiling, so this // builds the library purely to get at it. The result is a static site: // index.html, the viewer's wasm and javascript, and the sources it reads // from. const docs_library = b.addLibrary(.{ .name = "zig65", .root_module = zig65, }); const install_docs = b.addInstallDirectory(.{ .source_dir = docs_library.getEmittedDocs(), .install_dir = .prefix, .install_subdir = "docs", }); const docs_step = b.step("docs", "Build the API documentation into zig-out/docs"); docs_step.dependOn(&install_docs.step); // The generated viewer fetches `sources.tar` and `main.wasm` at runtime, // which a browser refuses to do from a `file://` page, so reading the docs // locally means serving them. This is the same reason `zig std` runs a // server rather than just opening a file. const docs_port = b.option(u16, "docs-port", "Port for `zig build docs-serve` (default 8000)") orelse 8000; const docs_server = b.addExecutable(.{ .name = "docs-server", .root_module = b.createModule(.{ .root_source_file = b.path("tools/docs_server.zig"), // Always built for the machine running the build, never for // whatever -Dtarget the library is being built for. .target = b.graph.host, .optimize = .Debug, }), }); const run_docs_server = b.addRunArtifact(docs_server); run_docs_server.step.dependOn(&install_docs.step); run_docs_server.addArg(b.getInstallPath(.prefix, "docs")); run_docs_server.addArg(b.fmt("{d}", .{docs_port})); // The server runs until interrupted, so its output has to reach the // terminal rather than being captured by the build runner. run_docs_server.stdio = .inherit; const docs_serve_step = b.step("docs-serve", "Serve the API documentation over HTTP"); docs_serve_step.dependOn(&run_docs_server.step); // The server has tests of its own; without this they would never run. const docs_server_tests = b.addTest(.{ .root_module = docs_server.root_module }); test_step.dependOn(&b.addRunArtifact(docs_server_tests).step); // Runs a IIgs ROM against the model and reports what it asked for and // did not get, which is the nearest thing a machine has to a corpus. const bootgs = b.addExecutable(.{ .name = "bootgs", .root_module = b.createModule(.{ .root_source_file = b.path("tools/bootgs.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = zig65_shipped }, // ltoudp lives beside the IIgs front end in src/ and cannot be // reached from tools/ by a relative import, so it comes in as a // module here the way it does for gs. .{ .name = "ltoudp", .module = b.createModule(.{ .root_source_file = b.path("src/ltoudp.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = zig65_shipped }, }, }) }, }, }), }); const run_bootgs = b.addRunArtifact(bootgs); run_bootgs.stdio = .inherit; if (b.args) |args| run_bootgs.addArgs(args); const bootgs_step = b.step("bootgs", "Run a IIgs ROM against the model: zig build bootgs -- ROM"); bootgs_step.dependOn(&run_bootgs.step); // Running the IIgs is now the ordinary program with a switch on it, so the // step is a convenience rather than a second executable: it puts // `--machine iigs` in front of whatever else was asked for. const run_gs = b.addRunArtifact(exe); run_gs.stdio = .inherit; run_gs.step.dependOn(b.getInstallStep()); run_gs.addArg("--machine"); run_gs.addArg("iigs"); if (b.args) |args| run_gs.addArgs(args); const gs_step = b.step("gs", "Run an Apple IIgs you can type at: zig build gs -- --rom ROM"); gs_step.dependOn(&run_gs.step); // The WOZ reference images, run against the drive in woz/. Its own // project for the same reason the corpus is: the disks are other people's // software, they are fetched rather than committed, and nothing that // merely builds this should have to know they exist. const woz_step = b.step("woz", "Read the WOZ reference images, in woz/"); const woz_run = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run" }); woz_run.setCwd(b.path("woz")); woz_run.stdio = .inherit; if (b.args) |args| { woz_run.addArg("--"); woz_run.addArgs(args); } woz_step.dependOn(&woz_run.step); // Klaus Dormann's functional tests, run against both eight-bit cores in // functional/. Its own project again, for the smallest of the three // reasons: the images are fetched rather than committed. They are only a // hundred and twenty-eight kilobytes and the whole run takes seconds, so // unlike the corpus this one is cheap enough for CI. const functional_step = b.step("functional", "Run Klaus Dormann's functional tests, in functional/"); const functional_run = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run" }); functional_run.setCwd(b.path("functional")); functional_run.stdio = .inherit; if (b.args) |args| { functional_run.addArg("--"); functional_run.addArgs(args); } functional_step.dependOn(&functional_run.step); // Which way the 65816 should dispatch is a question with two answers and // no obvious winner, so both are built and this measures them against each // other. At the shipped mode: a benchmark of a debug build measures the // debug build. const bench16 = b.addExecutable(.{ .name = "bench16", .root_module = b.createModule(.{ .root_source_file = b.path("tools/bench16.zig"), .target = target, .optimize = app_optimize, .imports = &.{ .{ .name = "zig65", .module = zig65_shipped }, }, }), }); const run_bench16 = b.addRunArtifact(bench16); run_bench16.stdio = .inherit; if (b.args) |args| run_bench16.addArgs(args); const bench16_step = b.step("bench16", "Measure the 65816's two dispatch strategies against each other"); bench16_step.dependOn(&run_bench16.step); // The corpus runner is its own project, in corpus/, because the corpus is // two and a half million files and nothing that merely builds this should // have to know it exists. `zig build corpus` runs it there. const corpus_step = b.step("corpus", "Run the SingleStepTests corpus, in corpus/"); const corpus_run = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run" }); corpus_run.setCwd(b.path("corpus")); // Whichever processor is being built is the one to check, and the corpus // has both: the traces for each were recorded from that chip. corpus_run.addArg(switch (processor) { .@"6502" => "-Dprocessor=6502", .RP2A03 => "-Dprocessor=RP2A03", .@"65C02" => "-Dprocessor=65C02", .R65C02 => "-Dprocessor=R65C02", .W65C02 => "-Dprocessor=W65C02", }); if (b.args) |args| { corpus_run.addArg("--"); corpus_run.addArgs(args); } corpus_step.dependOn(&corpus_run.step); // And the 65816's, which is a step of its own rather than a value of // -Dprocessor, because the 16-bit core is not one of the processors the // debugger can be built around: it is its own core, with its own memory // models, and nothing in the machines above can hold one yet. const corpus16_step = b.step("corpus16", "Run the SingleStepTests 65816 corpus, in corpus/"); const corpus16_run = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run", "-Dprocessor=65C816" }); corpus16_run.setCwd(b.path("corpus")); if (b.args) |args| { corpus16_run.addArg("--"); corpus16_run.addArgs(args); } corpus16_step.dependOn(&corpus16_run.step); // Semantic analysis with nothing to show for it. None of these artifacts is // installed or run, so nothing ever asks them for their output, and the // build system passes -fno-emit-bin and stops the compiler after checking. // This is what a language server runs, so it covers every source file in // the project and writes no binaries at all. const check_step = b.step("check", "Type check everything, emitting nothing"); check_step.dependOn(&b.addExecutable(.{ .name = "zig65", .root_module = exe.root_module, }).step); check_step.dependOn(&b.addExecutable(.{ .name = "typing", .root_module = example.root_module, }).step); check_step.dependOn(&b.addExecutable(.{ .name = "bootgs", .root_module = bootgs.root_module, }).step); check_step.dependOn(&b.addTest(.{ .root_module = zig65 }).step); check_step.dependOn(&b.addTest(.{ .root_module = exe.root_module }).step); // The README's reference list and bibliography are generated from // doc/references.bib and doc/bibliography.bib rather than hand-maintained; // tools/bibgen.zig renders them into the README between its markers. This // is run when a reference changes rather than as part of a normal build. const bibgen = b.addExecutable(.{ .name = "bibgen", .root_module = b.createModule(.{ .root_source_file = b.path("tools/bibgen.zig"), // The machine running the build, since it reads and writes files in // the source tree rather than anything the target cares about. .target = b.graph.host, .optimize = .Debug, }), }); const run_bibgen = b.addRunArtifact(bibgen); run_bibgen.setCwd(b.path(".")); run_bibgen.has_side_effects = true; // it rewrites README.md run_bibgen.stdio = .inherit; const references_step = b.step("references", "Regenerate the README's reference sections from doc/*.bib"); references_step.dependOn(&run_bibgen.step); const check_bibgen = b.addRunArtifact(bibgen); check_bibgen.setCwd(b.path(".")); check_bibgen.addArg("--check"); check_bibgen.stdio = .inherit; const references_check_step = b.step("references-check", "Report whether the README's reference sections are stale"); references_check_step.dependOn(&check_bibgen.step); // It compiles as part of `check`. check_step.dependOn(&bibgen.step); }