From 8da0c6b96f8aad69f15144321aa0f358de3aba55 Mon Sep 17 00:00:00 2001 From: booniepepper Date: Thu, 18 Jan 2024 00:47:26 -0800 Subject: [PATCH] update for the times we live in --- .tool-versions | 2 +- build.zig | 20 ++++++++++++++------ src/builtins.zig | 14 ++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.tool-versions b/.tool-versions index f81adbc..932b1fe 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -zig master +zig 0.11 diff --git a/build.zig b/build.zig index 2c94ae0..ab66da8 100644 --- a/build.zig +++ b/build.zig @@ -1,9 +1,10 @@ const std = @import("std"); +const LazyPath = if (@hasDecl(std.Build, "LazyPath")) std.Build.LazyPath else std.Build.FileSource; pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const root_source_file = std.Build.FileSource.relative("src/main.zig"); + const root_source_file = LazyPath.relative("src/main.zig"); // Dt executable const dt_step = b.step("dt", "Install dt executable"); @@ -25,16 +26,23 @@ pub fn build(b: *std.Build) !void { inline for (TRIPLES) |TRIPLE| { const exe = "dt-" ++ TRIPLE; - const cross = b.addExecutable(.{ + const query = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }); + + const cross: *std.Build.Step.Compile = b.addExecutable(.{ .name = exe, .root_source_file = root_source_file, .optimize = optimize, - .target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }), + .target = if (comptime @hasDecl(std.zig.system, "resolveTargetQuery")) + // Zig 0.12 + .{ .query = query, .result = try std.zig.system.resolveTargetQuery(query) } + else + // Zig 0.11 + query, }); const cross_install = b.addInstallArtifact(cross, .{}); - const exe_filename = if (cross.target.cpu_arch == .wasm32) exe ++ ".wasm" else if (cross.target.os_tag == .windows) exe ++ ".exe" else exe; + const exe_filename = if (query.cpu_arch == .wasm32) 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, @@ -42,7 +50,7 @@ pub fn build(b: *std.Build) !void { if (comptime @hasDecl(@TypeOf(cross_tar.*), "setCwd")) { // Zig 0.12.0 - cross_tar.setCwd(.{ .path="./zig-out/bin/"}); + cross_tar.setCwd(.{ .path = "./zig-out/bin/" }); } else { // Zig 0.11.0 cross_tar.cwd = "./zig-out/bin/"; @@ -94,5 +102,5 @@ const TRIPLES = .{ "x86-linux-gnu", "x86-linux-musl", "x86-windows-gnu", - "x86_64-windows-gnu" + "x86_64-windows-gnu", }; diff --git a/src/builtins.zig b/src/builtins.zig index 403b68d..1e20880 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -237,11 +237,13 @@ test "\".\" cd" { } pub fn ls(dt: *DtMachine) !void { - const theCwd = try std.process.getCwdAlloc(dt.alloc); - defer dt.alloc.free(theCwd); - - var dir = try std.fs.openIterableDirAbsolute(theCwd, .{}); - var entries = dir.iterate(); + var theCwd = if (comptime @hasDecl(std.fs.Dir, "openIterableDir")) + // Zig 0.11 + try std.fs.cwd().openIterableDir("/", .{}) + else + // Zig 0.12 + try std.fs.cwd().openDir("/", .{ .iterate = true }); + var entries = theCwd.iterate(); var quote = Quote.init(dt.alloc); while (try entries.next()) |entry| { @@ -251,7 +253,7 @@ pub fn ls(dt: *DtMachine) !void { try dt.push(.{ .quote = quote }); - dir.close(); + theCwd.close(); } test "ls" {