Skip to content

Commit

Permalink
better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Jun 29, 2024
1 parent 3b26fa1 commit 3f0b2eb
Showing 1 changed file with 60 additions and 72 deletions.
132 changes: 60 additions & 72 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3f0b2eb

Please sign in to comment.