Skip to content

Commit

Permalink
Add back support for Zig 0.11.0 (stable), update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Oct 28, 2023
1 parent 41adb65 commit f58602c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ on:

jobs:
compile:
runs-on: ubuntu-latest
strategy:
matrix:
zig_version: [0.11.0, master]
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Set up Zig
uses: goto-bus-stop/[email protected]
with:
version: 0.11.0
version: ${{ matrix.zig_version }}

- name: Check out repository
uses: actions/checkout@v3
Expand Down
18 changes: 13 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ pub fn build(b: *std.Build) !void {

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 cross_tar = b.addSystemCommand(&.{
"tar", "--transform", "s|" ++ exe ++ "|dt|", "-czvf", exe ++ ".tgz", switch (cross.target.cpu_arch.?) {
.wasm32 => exe ++ ".wasm",
else => exe,
},
"tar", "--transform", "s|" ++ exe ++ "|dt|", "-czvf", exe ++ ".tgz", exe_filename,
});
cross_tar.setCwd(.{ .path = "./zig-out/bin/" });

if (comptime @hasDecl(@TypeOf(cross_tar.*), "setCwd")) {
// Zig 0.12.0
cross_tar.setCwd(.{ .path="./zig-out/bin/"});
} else {
// Zig 0.11.0
cross_tar.cwd = "./zig-out/bin/";
}

cross_tar.step.dependOn(&cross_install.step);
cross_step.dependOn(&cross_tar.step);
Expand Down Expand Up @@ -87,4 +93,6 @@ const TRIPLES = .{
"x86_64-macos-none",
"x86-linux-gnu",
"x86-linux-musl",
"x86-windows-gnu",
"x86_64-windows-gnu"
};
9 changes: 6 additions & 3 deletions src/builtins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ pub fn exec(dt: *DtMachine) !void {

while (childArgs.next()) |arg| try argv.append(arg);

var result = std.process.Child.run(.{
const run = if (comptime @hasDecl(std.process.Child, "run"))std.process.Child.run else std.process.Child.exec;

var result = run(.{
.allocator = dt.alloc,
.argv = argv.items,
}) catch |e| return dt.rewind(log, val, e);
Expand Down Expand Up @@ -770,13 +772,14 @@ pub fn abs(dt: *DtMachine) !void {
if (val.isInt()) {
const a = try val.intoInt();

try dt.push(.{ .int = @intCast(@abs(a)) });
try dt.push(.{ .int = try std.math.absInt(a) });

return;
}

const a = val.intoFloat() catch |e| return dt.rewind(log, val, e);

try dt.push(.{ .float = @abs(a) });
try dt.push(.{ .float = std.math.fabs(a) });
}

pub fn rand(dt: *DtMachine) !void {
Expand Down
13 changes: 8 additions & 5 deletions src/tests/dt_test_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ const allocator = std.heap.page_allocator;

const MAX_FILE_SIZE = 1 << 12;

pub fn dtRunFile(file_path: []const u8) !Child.RunResult {
const ChildResult = if (@hasDecl(Child, "RunResult")) Child.RunResult else Child.ExecResult;
const run = if(@hasDecl(Child, "run")) Child.run else Child.exec;

pub fn dtRunFile(file_path: []const u8) !ChildResult {
const cur_dir = std.fs.cwd();
const contents = try cur_dir.readFileAlloc(allocator, file_path, MAX_FILE_SIZE);
return try dtStdin(contents);
}

pub fn dtStdin(input: []const u8) !Child.RunResult {
return try Child.run(.{ .allocator = allocator, .argv = &.{
pub fn dtStdin(input: []const u8) !ChildResult {
return try run(.{ .allocator = allocator, .argv = &.{
"./zig-out/bin/dt",
"[\"#\" starts-with? not] filter",
"unwords",
Expand All @@ -20,7 +23,7 @@ pub fn dtStdin(input: []const u8) !Child.RunResult {
} });
}

pub fn dt(argv: []const []const u8) !Child.RunResult {
pub fn dt(argv: []const []const u8) !ChildResult {
var args = std.ArrayList([]const u8).init(allocator);
defer args.deinit();

Expand All @@ -30,5 +33,5 @@ pub fn dt(argv: []const []const u8) !Child.RunResult {
try args.append(arg);
}

return try Child.run(.{ .allocator = allocator, .argv = args.items });
return try run(.{ .allocator = allocator, .argv = args.items });
}

0 comments on commit f58602c

Please sign in to comment.