Skip to content

Commit

Permalink
update for the times we live in
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Jan 18, 2024
1 parent f986554 commit 8da0c6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
zig master
zig 0.11
20 changes: 14 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -25,24 +26,31 @@ 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,
});

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/";
Expand Down Expand Up @@ -94,5 +102,5 @@ const TRIPLES = .{
"x86-linux-gnu",
"x86-linux-musl",
"x86-windows-gnu",
"x86_64-windows-gnu"
"x86_64-windows-gnu",
};
14 changes: 8 additions & 6 deletions src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -251,7 +253,7 @@ pub fn ls(dt: *DtMachine) !void {

try dt.push(.{ .quote = quote });

dir.close();
theCwd.close();
}

test "ls" {
Expand Down

0 comments on commit 8da0c6b

Please sign in to comment.