diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 525fa81..367fdd2 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -13,11 +13,10 @@ jobs: compile: strategy: matrix: - zig_version: [0.11.0, master] - os: [ubuntu-latest] + zig_version: [0.11.0, 0.12.0] experimental: [false] include: - - zig_version: 0.11.0 + - zig_version: 0.12.0 os: windows-latest experimental: true - zig_version: master @@ -26,7 +25,7 @@ jobs: continue-on-error: ${{ matrix.experimental }} - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - name: Set up Zig diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d219a0..468708f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Zig uses: goto-bus-stop/setup-zig@v2.1.0 with: - version: 0.11.0 + version: 0.12.0 - name: Check out repository uses: actions/checkout@v3 diff --git a/.tool-versions b/.tool-versions index 932b1fe..939bae7 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -zig 0.11 +zig 0.12 diff --git a/aqua.yaml b/aqua.yaml index f461eb2..0df10df 100644 --- a/aqua.yaml +++ b/aqua.yaml @@ -10,4 +10,4 @@ registries: - type: standard ref: v4.63.0 # renovate: depName=aquaproj/aqua-registry packages: -- name: ziglang/zig@0.11.0 +- name: ziglang/zig@0.12.0 diff --git a/build.zig b/build.zig index ab66da8..147a422 100644 --- a/build.zig +++ b/build.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const LazyPath = if (@hasDecl(std.Build, "LazyPath")) std.Build.LazyPath else std.Build.FileSource; +const Build = if (@hasDecl(std, "Build")) std.Build else std.build.Builder; -pub fn build(b: *std.Build) !void { +pub fn build(b: *Build) !void { const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); - const root_source_file = LazyPath.relative("src/main.zig"); + const optimize = if (comptime @hasDecl(Build, "standardOptimizeOption")) b.standardOptimizeOption(.{}) else b.standardReleaseOptions(); + const root_source_file = if (@hasDecl(Build, "path")) b.path("src/main.zig") else Build.LazyPath.relative("src/main.zig"); // Dt executable const dt_step = b.step("dt", "Install dt executable"); @@ -16,7 +16,9 @@ pub fn build(b: *std.Build) !void { .target = target, }); - const dt_install = b.addInstallArtifact(dt, .{}); + const dt_install = + b.addInstallArtifact(dt, .{}); + dt_step.dependOn(&dt_install.step); b.default_step.dependOn(dt_step); @@ -28,7 +30,7 @@ pub fn build(b: *std.Build) !void { const query = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }); - const cross: *std.Build.Step.Compile = b.addExecutable(.{ + const cross = b.addExecutable(.{ .name = exe, .root_source_file = root_source_file, .optimize = optimize, @@ -40,9 +42,11 @@ pub fn build(b: *std.Build) !void { query, }); - const cross_install = b.addInstallArtifact(cross, .{}); + const cross_install = + b.addInstallArtifact(cross, .{}); - const exe_filename = if (query.cpu_arch == .wasm32) exe ++ ".wasm" else if (query.os_tag == .windows) exe ++ ".exe" else exe; + const is_wasm = if (query.cpu_arch) |arch| arch.isWasm() else false; + const exe_filename = if (is_wasm) exe ++ ".wasm" else if (query.os_tag == .windows) exe ++ ".exe" else exe; const cross_tar = b.addSystemCommand(&.{ "tar", "--transform", "s|" ++ exe ++ "|dt|", "-czvf", exe ++ ".tgz", exe_filename, @@ -52,7 +56,7 @@ pub fn build(b: *std.Build) !void { // Zig 0.12.0 cross_tar.setCwd(.{ .path = "./zig-out/bin/" }); } else { - // Zig 0.11.0 + // Zig 0.11 cross_tar.cwd = "./zig-out/bin/"; } @@ -63,7 +67,8 @@ pub fn build(b: *std.Build) !void { // Tests const test_step = b.step("test", "Run tests"); - const test_exe = b.addTest(.{ + const test_exe = + b.addTest(.{ .root_source_file = root_source_file, .optimize = optimize, .target = target, diff --git a/build.zig.zon b/build.zig.zon index e3b4883..2cfa90f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ .name = "dt", - .version = "1.3.1", // Update in main.zig as well - .paths = .{ "" }, + .version = "2.0.0-rc", // Update in main.zig as well + .paths = .{""}, } diff --git a/default.nix b/default.nix index fe7eff0..baeab5e 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ { lib , stdenv , testers -, zig_0_11 +, zig_0_12 }: stdenv.mkDerivation (finalAttrs: { @@ -10,7 +10,7 @@ stdenv.mkDerivation (finalAttrs: { src = lib.cleanSource ./.; - nativeBuildInputs = [ zig_0_11.hook ]; + nativeBuildInputs = [ zig_0_12.hook ]; passthru.tests.version = testers.testVersion { package = finalAttrs.finalPackage; }; diff --git a/dev/dt b/dev/dt index 97d3747..99e716c 100755 --- a/dev/dt +++ b/dev/dt @@ -10,7 +10,7 @@ if [[ $DT_ROOT != dev/.. ]]; then >&2 echo "ERROR: $0 is intended to be run when developing dt." >&2 echo "If you're just trying to run a dt built from source:" >&2 echo "- Navigate to $DT_ROOT" - >&2 echo "- Run './build release' to compile a release executable (Requires Zig 0.11.*)" + >&2 echo "- Run './build release' to compile a release executable (Expects Zig 0.12)" >&2 echo "- Use the result at: $DT" exit 1 fi diff --git a/flake.nix b/flake.nix index 47cd24b..2df1f09 100644 --- a/flake.nix +++ b/flake.nix @@ -16,7 +16,7 @@ in { packages.default = dt; devShells.default = pkgs.mkShell { - packages = with pkgs; [ zig_0_11 ]; + packages = with pkgs; [ zig_0_12 ]; }; }); } diff --git a/src/builtins.zig b/src/builtins.zig index 1e20880..a665b0b 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1,5 +1,7 @@ const std = @import("std"); const ArrayList = std.ArrayList; +const osExit = if (@hasDecl(std, "posix")) std.posix.exit else std.os.exit; +const osChdir = if (@hasDecl(std, "posix")) std.posix.chdir else std.os.chdir; const interpret = @import("interpret.zig"); const Command = interpret.Command; @@ -139,7 +141,7 @@ pub fn quit(dt: *DtMachine) !void { try dt.norm(); } - std.os.exit(0); + osExit(0); } test "drop quit" { @@ -172,7 +174,7 @@ pub fn exit(dt: *DtMachine) !void { } const code: u8 = @intCast(i); - std.os.exit(code); + osExit(code); } test "7 exit" { @@ -225,7 +227,7 @@ pub fn cd(dt: *DtMachine) !void { path = try std.process.getEnvVarOwned(dt.alloc, "HOME"); } - std.os.chdir(path) catch |e| return dt.rewind(log, val, e); + osChdir(path) catch |e| return dt.rewind(log, val, e); } test "\".\" cd" { diff --git a/src/main.zig b/src/main.zig index f781994..9d80773 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Allocator = std.mem.Allocator; +const osExit = if (@hasDecl(std, "posix")) std.posix.exit else std.os.exit; const builtins = @import("builtins.zig"); @@ -7,7 +8,7 @@ const interpret = @import("interpret.zig"); const DtMachine = interpret.DtMachine; // TODO: Change to @import when it's supported for zon -pub const version = "1.3.1"; // Update in build.zig.zon as well. +pub const version = "2.0.0-rc"; // Update in build.zig.zon as well. const stdlib = @embedFile("stdlib.dt"); const dtlib = @embedFile("dt.dt"); @@ -35,17 +36,15 @@ pub fn main() !void { if (try readShebangFile(arena.allocator(), firstArg)) |fileContents| { return dt.loadFile(fileContents) catch |e| return doneOrDie(&dt, e); } else if ((std.mem.eql(u8, firstArg, "--stream") or std.mem.startsWith(u8, firstArg, "--stream ")) and (stdinPiped or stdoutPiped)) { - return handlePipedStdoutOnly(&dt); + dt.handleCmd("dt/run-args") catch |e| return doneOrDie(&dt, e); } } if (stdinPiped) { - return handlePipedStdin(&dt); - } else if (stdoutPiped) { - return handlePipedStdoutOnly(&dt); + dt.handleCmd("dt/pipe-thru-args") catch |e| return doneOrDie(&dt, e); + } else { + dt.handleCmd("dt/run-args") catch |e| return doneOrDie(&dt, e); } - - return readEvalPrintLoop(&dt); } fn readFirstArg(allocator: Allocator) !?[]const u8 { @@ -54,29 +53,6 @@ fn readFirstArg(allocator: Allocator) !?[]const u8 { return if (args.next()) |arg| try allocator.dupe(u8, arg) else null; } -fn handlePipedStdin(dt: *DtMachine) !void { - dt.handleCmd("dt/pipe-thru-args") catch |e| return doneOrDie(dt, e); -} - -fn handlePipedStdoutOnly(dt: *DtMachine) !void { - dt.handleCmd("dt/run-args") catch |e| return doneOrDie(dt, e); -} - -fn readEvalPrintLoop(dt: *DtMachine) !void { - dt.handleCmd("dt/run-args") catch |e| return doneOrDie(dt, e); - - // TODO: Can this catch be done in the stdlib? Other people need to catch errors too! - while (true) dt.handleCmd("dt/main-repl") catch |e| switch (e) { - error.EndOfStream => return, - else => { - const stderr = std.io.getStdErr().writer(); - try dt.red(); - try stderr.print("\nRestarting REPL after error: {s}\n\n", .{@errorName(e)}); - try dt.norm(); - }, - }; -} - fn doneOrDie(dt: *DtMachine, reason: anyerror) !void { const stderr = std.io.getStdErr().writer(); try stderr.print("\n", .{}); @@ -88,7 +64,7 @@ fn doneOrDie(dt: *DtMachine, reason: anyerror) !void { try stderr.print("\nRIP: {any}\n", .{reason}); try dt.norm(); - std.os.exit(1); + osExit(1); }, } }