Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig 0.13.0 support #1

Open
wants to merge 1 commit into
base: core
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) !void {
const compile_step = b.step("findup", "Install findup executable");
const cross_step = b.step("cross", "Generate cross-compiled executables");

const source = std.Build.FileSource.relative("src/main.zig");
const source = b.path("src/main.zig");
const exe = b.addExecutable(.{
.name = name,
.root_source_file = source,
Expand All @@ -23,26 +23,27 @@ pub fn build(b: *std.Build) !void {

// Cross-compile
inline for (TRIPLES) |TRIPLE| {
const cross_target = b.resolveTargetQuery(try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }));
const cross = b.addExecutable(.{
.name = name,
.root_source_file = source,
.optimize = optimize,
.target = try std.zig.CrossTarget.parse(.{ .arch_os_abi = TRIPLE }),
.target = cross_target,
});

const cross_install = b.addInstallArtifact(cross, .{
.dest_dir = .{ .override = .{ .custom = "cross/" ++ TRIPLE } },
});

const cross_tar = b.addSystemCommand(&.{ "sh", "-c", "tar -czvf findup-" ++ TRIPLE ++ ".tgz findup" });
cross_tar.cwd = "./zig-out/cross/" ++ TRIPLE;
cross_tar.cwd = b.path("./zig-out/cross/" ++ TRIPLE);

cross_tar.step.dependOn(&cross_install.step);
cross_step.dependOn(&cross_tar.step);
}

// Tests
const testSource = std.Build.FileSource.relative("src/test.zig");
const testSource = b.path("src/test.zig");

const test_exe = b.addTest(.{
.root_source_file = testSource,
Expand Down
18 changes: 9 additions & 9 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const stderr = std.io.getStdErr().writer();
const Writer = std.io.Writer;
const Dir = std.fs.Dir;
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
const AccessError = std.os.AccessError;
const AccessError = std.posix.AccessError;

const Findup = struct { program: [:0]const u8, target: [:0]const u8, cwd: Dir, printHelp: bool, printVersion: bool };
const FindupError = error{NoFileSpecified};
Expand Down Expand Up @@ -32,28 +32,28 @@ pub fn main() anyerror!void {

const findup = initFindup() catch |err| {
try stderr.print("ERROR: {?}\n\n{s}", .{ err, USAGE });
std.os.exit(1);
std.process.exit(1);
};

if (findup.printHelp) {
try stdout.print("{s}\n{s}", .{ VERSION, USAGE });
std.os.exit(0);
std.process.exit(0);
} else if (findup.printVersion) {
try stdout.print(VERSION, .{});
std.os.exit(0);
std.process.exit(0);
}

var cwd = findup.cwd;

const result = while (true) {
var cwdStr = try dirStr(cwd, buf[0..]);
const cwdStr = try dirStr(cwd, buf[0..]);
if (try fileExists(cwd, findup.target)) break cwdStr;
if (std.mem.eql(u8, "/", cwdStr)) break null;
try std.os.chdir("..");
try std.posix.chdir("..");
cwd = std.fs.cwd();
} else unreachable;

if (result == null) std.os.exit(1);
if (result == null) std.process.exit(1);

try stdout.print("{s}\n", .{result.?});
}
Expand All @@ -66,8 +66,8 @@ fn initFindup() anyerror!Findup {
const target = if (maybeTarget == null) return FindupError.NoFileSpecified else maybeTarget.?;
const cwd = std.fs.cwd();

var printHelp = std.mem.eql(u8, "-h", target) or std.mem.eql(u8, "--help", target);
var printVersion = std.mem.eql(u8, "-V", target) or std.mem.eql(u8, "--version", target);
const printHelp = std.mem.eql(u8, "-h", target) or std.mem.eql(u8, "--help", target);
const printVersion = std.mem.eql(u8, "-V", target) or std.mem.eql(u8, "--version", target);

return Findup{ .program = program, .target = target, .cwd = cwd, .printHelp = printHelp, .printVersion = printVersion };
}
Expand Down
12 changes: 6 additions & 6 deletions src/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ const std = @import("std");
const testing = std.testing;
const allocator = testing.allocator;

const ChildProcess = std.ChildProcess;
const ChildProcess = std.process.Child;

const findup = "./zig-out/bin/findup";

test "findup --version" {
const invocation = &[_][]const u8{ findup, "--version" };

const result = try ChildProcess.exec(.{ .allocator = allocator, .argv = invocation });
const result = try ChildProcess.run(.{ .argv = invocation, .allocator = allocator });
defer allocator.free(result.stdout);
defer allocator.free(result.stderr);

Expand All @@ -19,12 +18,13 @@ test "findup --version" {
test "findup build.zig" {
const invocation = &[_][]const u8{ findup, "build.zig" };

const result = try ChildProcess.exec(.{ .allocator = allocator, .argv = invocation });
const result = try ChildProcess.run(.{ .argv = invocation, .allocator = allocator });

defer allocator.free(result.stdout);
defer allocator.free(result.stderr);

var buf: [256]u8 = undefined;
const cwd = try std.os.getcwd(&buf);
const cwd = try std.posix.getcwd(&buf);

// Test that some non-empty string is returned.
try testing.expectStringStartsWith(std.mem.trimRight(u8, cwd, &std.ascii.whitespace), std.mem.trimRight(u8, result.stdout, &std.ascii.whitespace));
Expand All @@ -34,7 +34,7 @@ test "findup build.zig" {
test "findup SOME_FILE_THAT_I_SUPPOSE_DOES_NOT_EXIST" {
const invocation = &[_][]const u8{ findup, "SOME_FILE_THAT_I_SUPPOSE_DOES_NOT_EXIST" };

const result = try ChildProcess.exec(.{ .allocator = allocator, .argv = invocation });
const result = try ChildProcess.run(.{ .argv = invocation, .allocator = allocator });
defer allocator.free(result.stdout);
defer allocator.free(result.stderr);

Expand Down