From 3f0b2eb3ef5acda4be18513f1874d5ca1968cb86 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Fri, 28 Jun 2024 17:59:00 -0700 Subject: [PATCH] better formatting --- build.zig | 132 +++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 72 deletions(-) diff --git a/build.zig b/build.zig index d5b6892..0efaa8a 100644 --- a/build.zig +++ b/build.zig @@ -21,78 +21,66 @@ pub fn build(b: *std.Build) !void { const exe_options = b.addOptions(); exe.root_module.addOptions("options", exe_options); - // options - { - const trace = b.option( - bool, - "trace", - "Enables tracing of the compiler using the default backend (spall)", - ) orelse false; - const backend: TraceBackend = bend: { - if (trace) { - break :bend b.option( - TraceBackend, - "trace-backend", - "Switch between what backend to use. None is default.", - ) orelse .None; - } - break :bend .None; - }; - - const use_llvm = b.option(bool, "use-llvm", "Uses llvm to compile Osmium. Default true.") orelse true; - exe.use_llvm = use_llvm; - exe.use_lld = use_llvm; - - const enable_logging = b.option(bool, "log", "Enable debug logging.") orelse false; - const enable_debug_extensions = b.option( - bool, - "debug-extensions", - "Enable commands and options useful for debugging the compiler", - ) orelse (optimize == .Debug); - - exe_options.addOption(bool, "trace", trace); - exe_options.addOption(TraceBackend, "backend", backend); - exe_options.addOption(bool, "enable_logging", enable_logging); - exe_options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len); - exe_options.addOption(bool, "enable_debug_extensions", enable_debug_extensions); - } - - // dependencies - { - const tracer_dep = b.dependency("tracer", .{ .optimize = optimize, .target = target }); - const libgc_dep = b.dependency("libgc", .{ .optimize = optimize, .target = target }); - exe.root_module.addImport("tracer", tracer_dep.module("tracer")); - exe.root_module.addImport("gc", libgc_dep.module("gc")); - } - - // libpython - { - const libpython, const lib_path = try generateLibPython(b, target, optimize); - exe.linkLibrary(libpython); - exe_options.addOption([]const u8, "lib_path", lib_path); - const libpython_install = b.addInstallArtifact(libpython, .{ - .dest_dir = .{ .override = .{ .custom = "python" } }, - }); - b.getInstallStep().dependOn(&libpython_install.step); - - const test_step = b.step("test", "Test Osmium"); - try cases.addCases(b, exe, test_step); - test_step.dependOn(&libpython_install.step); - } - - // other steps - { - 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 opcode_step = b.step("opcode", "Generate opcodes"); - generateOpCode(b, opcode_step); - } + const trace = b.option( + bool, + "trace", + "Enables tracing of the compiler using the default backend (spall)", + ) orelse false; + const backend: TraceBackend = bend: { + if (trace) { + break :bend b.option( + TraceBackend, + "trace-backend", + "Switch between what backend to use. None is default.", + ) orelse .None; + } + break :bend .None; + }; + + const use_llvm = b.option(bool, "use-llvm", "Uses llvm to compile Osmium. Default true.") orelse true; + exe.use_llvm = use_llvm; + exe.use_lld = use_llvm; + + const enable_logging = b.option(bool, "log", "Enable debug logging.") orelse false; + const enable_debug_extensions = b.option( + bool, + "debug-extensions", + "Enable commands and options useful for debugging the compiler", + ) orelse (optimize == .Debug); + + exe_options.addOption(bool, "trace", trace); + exe_options.addOption(TraceBackend, "backend", backend); + exe_options.addOption(bool, "enable_logging", enable_logging); + exe_options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len); + exe_options.addOption(bool, "enable_debug_extensions", enable_debug_extensions); + + const tracer_dep = b.dependency("tracer", .{ .optimize = optimize, .target = target }); + const libgc_dep = b.dependency("libgc", .{ .optimize = optimize, .target = target }); + exe.root_module.addImport("tracer", tracer_dep.module("tracer")); + exe.root_module.addImport("gc", libgc_dep.module("gc")); + + const libpython, const lib_path = try generateLibPython(b, target, optimize); + exe.linkLibrary(libpython); + exe_options.addOption([]const u8, "lib_path", lib_path); + const libpython_install = b.addInstallArtifact(libpython, .{ + .dest_dir = .{ .override = .{ .custom = "python" } }, + }); + b.getInstallStep().dependOn(&libpython_install.step); + + 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 opcode_step = b.step("opcode", "Generate opcodes"); + generateOpCode(b, opcode_step); + + const test_step = b.step("test", "Test Osmium"); + try cases.addCases(b, exe, test_step); + test_step.dependOn(&libpython_install.step); } const TraceBackend = enum {