Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
CI:
strategy:
matrix:
os: [windows-2025, windows-2022]
os: [windows-latest, windows-11-arm]
runs-on: ${{matrix.os}}
steps:
- name: Checkout
Expand All @@ -25,9 +25,9 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.14.1
version: 0.15.2
- name: Setup Deno
uses: denoland/setup-deno@v2
run: npm i -g deno

- name: Check format
run: deno task fmt:check
Expand Down
31 changes: 22 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,34 @@ pub fn build(b: *std.Build) void {
const zigwin32 = b.dependency("zigwin32", .{}).module("win32");

const test_step = b.step("test", "Run all tests");
const tests = b.addTest(.{

// Create a module for the main source
const main_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
tests.root_module.addImport("zigwin32", zigwin32);
const run_tests = b.addRunArtifact(tests);
main_module.addImport("zigwin32", zigwin32);

const unit_tests = b.addTest(.{
.root_module = main_module,
});
const run_tests = b.addRunArtifact(unit_tests);
test_step.dependOn(&run_tests.step);

const exe = b.addExecutable(.{
.name = "rb",
const exe_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_module.addImport("clap", clap.module("clap"));
exe_module.addImport("zigwin32", zigwin32);

const exe = b.addExecutable(.{
.name = "rb",
.root_module = exe_module,
});

exe.root_module.addImport("clap", clap.module("clap"));
exe.root_module.addImport("zigwin32", zigwin32);
b.installArtifact(exe);

const run_cmd = b.addRunArtifact(exe);
Expand All @@ -40,12 +50,15 @@ pub fn build(b: *std.Build) void {

// Release step
const release_step = b.step("release", "Run release script");
const release_exe = b.addExecutable(.{
.name = "release",
const release_module = b.createModule(.{
.root_source_file = b.path("scripts/release.zig"),
.target = target,
.optimize = optimize,
});
const release_exe = b.addExecutable(.{
.name = "release",
.root_module = release_module,
});
const release_cmd = b.addRunArtifact(release_exe);
release_step.dependOn(&release_cmd.step);
}
10 changes: 5 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.{
.name = .rb,
.version = "0.3.2",
.minimum_zig_version = "0.14.0",
.minimum_zig_version = "0.15.0",
.fingerprint = 0xff6c09ff26628417,
.dependencies = .{
.clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.10.0.tar.gz",
.hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0",
.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz",
.hash = "clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e",
},
.zigwin32 = .{
.url = "git+https://github.com/marlersoft/zigwin32.git#d21b419d808215e1f82605fdaddc49750bfa3bca",
.hash = "zigwin32-25.0.28-preview-AAAAAI0J-wP-8_KKo4Yjr33XLhVhlJmeagGUedByaOnX",
.url = "git+https://github.com/marlersoft/zigwin32.git#5587b16fa040573846a6bf531301f6206d31a6bf",
.hash = "zigwin32-25.0.28-preview-AAAAAICM5AMResOGQnQ85mfe60TTOQeMtt7GRATUOKoP",
},
},
.paths = .{
Expand Down
12 changes: 4 additions & 8 deletions scripts/release.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ pub fn main() !void {
std.crypto.hash.sha2.Sha256.hash(zip_data, &hash, .{});

// Convert hash to hex string
var hex_hash: [std.crypto.hash.sha2.Sha256.digest_length * 2]u8 = undefined;
_ = std.fmt.bufPrint(&hex_hash, "{}", .{std.fmt.fmtSliceHexLower(&hash)}) catch unreachable;
const hex_hash = std.fmt.bytesToHex(hash, .lower);

// Generate scoop manifest
try generateScoopManifest(allocator, version, &hex_hash);
Expand Down Expand Up @@ -126,13 +125,10 @@ fn generateScoopManifest(allocator: std.mem.Allocator, version: []const u8, hash
},
};

var buffer = std.ArrayList(u8).init(allocator);
defer buffer.deinit();

try json.stringify(manifest, .{ .whitespace = .indent_2 }, buffer.writer());
try buffer.append('\n');
const manifest_str = try std.fmt.allocPrint(allocator, "{f}\n", .{json.fmt(manifest, .{ .whitespace = .indent_2 })});
defer allocator.free(manifest_str);

const file = try fs.cwd().createFile("rb.json", .{});
defer file.close();
try file.writeAll(buffer.items);
try file.writeAll(manifest_str);
}
34 changes: 28 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ pub fn main() !void {
var res = clap.parse(clap.Help, &params, clap.parsers.default, .{
.allocator = alc,
}) catch {
try std.io.getStdErr().writer().print("rb: cannot be executed: Invalid arguments\n", .{});
const stderr = std.fs.File.stderr();
var buffer: [4096]u8 = undefined;
var writer = stderr.writer(&buffer);
try writer.interface.print("rb: cannot be executed: Invalid arguments\n", .{});
try writer.interface.flush();
Output.restore();
process.exit(1);
};
Expand All @@ -44,7 +48,11 @@ pub fn main() !void {
\\ -h, --help Display this help
\\ --version Display version information
;
try std.io.getStdErr().writer().print("{s}\n", .{help_message});
const stderr = std.fs.File.stderr();
var buffer: [4096]u8 = undefined;
var writer = stderr.writer(&buffer);
try writer.interface.print("{s}\n", .{help_message});
try writer.interface.flush();
Output.restore();
process.exit(0);
}
Expand All @@ -54,21 +62,33 @@ pub fn main() !void {
const message =
\\rb {s}
;
try std.io.getStdErr().writer().print(message, .{RbVersion.version});
const stderr = std.fs.File.stderr();
var buffer: [4096]u8 = undefined;
var writer = stderr.writer(&buffer);
try writer.interface.print(message, .{RbVersion.version});
try writer.interface.flush();
Output.restore();
process.exit(0);
}

// No arguments
if (res.positionals[0].len == 0) {
try std.io.getStdErr().writer().print("rb: missing operand\nTry 'rb --help' for more information\n", .{});
const stderr = std.fs.File.stderr();
var buffer: [4096]u8 = undefined;
var writer = stderr.writer(&buffer);
try writer.interface.print("rb: missing operand\nTry 'rb --help' for more information\n", .{});
try writer.interface.flush();
Output.restore();
process.exit(1);
}

const verbose = res.args.verbose != 0;
const force = res.args.force != 0;

const stderr = std.fs.File.stderr();
var buffer: [4096]u8 = undefined;
var stderr_writer = stderr.writer(&buffer);

for (res.positionals[0]) |filename| {
const result = try trash.trash(alc, filename);
// If --force is enabled and file doesn't exist (error code 2) on Windows, ignore it
Expand All @@ -77,9 +97,11 @@ pub fn main() !void {
} else if (result != 0) {
const message = try trash.getErrorMessage(alc, result);
defer alc.free(message);
try std.io.getStdErr().writer().print("rb: cannot remove '{s}': {s}\n", .{ filename, message });
try stderr_writer.interface.print("rb: cannot remove '{s}': {s}\n", .{ filename, message });
try stderr_writer.interface.flush();
} else if (verbose) {
try std.io.getStdErr().writer().print("removed '{s}'\n", .{filename});
try stderr_writer.interface.print("removed '{s}'\n", .{filename});
try stderr_writer.interface.flush();
}
}
Output.restore();
Expand Down
2 changes: 1 addition & 1 deletion src/output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const WindowsOutput = struct {
// Make a console output code is the same as before execution
fn setAbortSignalHandler(comptime handler: *const fn () void) !void {
const handler_routine = struct {
fn handler_routine(dwCtrlType: win.DWORD) callconv(win.WINAPI) win.BOOL {
fn handler_routine(dwCtrlType: win.DWORD) callconv(std.builtin.CallingConvention.winapi) win.BOOL {
if (dwCtrlType == win.CTRL_C_EVENT) {
handler();
return win.TRUE;
Expand Down