diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0286ab5..78562f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ on: - master jobs: - behaviour-test: + test: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 @@ -28,9 +28,12 @@ jobs: path: | ~/.cache/zig .zig-cache - key: osmium-${{hashFiles('build.zig.zon')}} + key: osmium-${{hashFiles('build.zig.zon')}} - - name: Run Tests + - name: Build Osmium + run: zig build + + - name: Run Behaviour Tests run: zig build test --summary all - name: Save Cache diff --git a/build.zig b/build.zig index 2522510..d5b6892 100644 --- a/build.zig +++ b/build.zig @@ -16,66 +16,83 @@ pub fn build(b: *std.Build) !void { .target = target, .optimize = optimize, }); - - 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); + b.installArtifact(exe); const exe_options = b.addOptions(); - 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); exe.root_module.addOptions("options", exe_options); - 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); - - b.installArtifact(exe); - 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); + // 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 TraceBackend = enum { @@ -146,7 +163,7 @@ fn generateLibPython( .HAVE_CLOCK_GETRES = 1, .HAVE_CLOCK_GETTIME = 1, .HAVE_CLOCK_SETTIME = 1, - .HAVE_CLOSE_RANGE = have(t.isGnuLibC()), + .HAVE_CLOSE_RANGE = null, .HAVE_COMPUTED_GOTOS = 1, .HAVE_CONFSTR = 1, .HAVE_COPY_FILE_RANGE = 1,