1
Fork 0
mirror of https://github.com/RGBCube/crash synced 2025-08-02 11:27:46 +00:00

Compare commits

...

3 commits

Author SHA1 Message Date
7849872b30
fix: build 2025-04-13 02:51:24 +03:00
aa1d4f6693
fix: fix indexing 2025-04-13 02:48:15 +03:00
119c52f090
feat: bug fixes and build fixes 2025-04-13 02:25:46 +03:00
5 changed files with 29 additions and 18 deletions

View file

@ -1,10 +1,13 @@
.{
.name = "crash",
.name = .crash,
.version = "0.0.1",
.fingerprint = 0xd7e8f0df85300b08,
.minimum_zig_version = "0.12.0",
.minimum_zig_version = "0.14.0",
.paths = .{
"",
"src/main.zig",
"build.zig",
"build.zig.zon",
},
}

6
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1715653339,
"narHash": "sha256-7lR9tpVXviSccl07GXI0+ve/natd24HAkuy1sQp0OlI=",
"lastModified": 1744442362,
"narHash": "sha256-i47t4DRIZgwBZw2Osbrp1OJhhO1k/n+QzRx+TrmfE9Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "abd6d48f8c77bea7dc51beb2adfa6ed3950d2585",
"rev": "2349f9de17183971db12ae9e0123dab132023bd7",
"type": "github"
},
"original": {

View file

@ -18,7 +18,7 @@
in {
devShell = forEachSystem (system: with nixpkgs.legacyPackages.${system}; mkShell {
packages = [
zig_0_12
zig_0_14
zls
zon2nix
];

View file

@ -2,7 +2,7 @@
lib,
stdenvNoCC,
zig,
zig_0_14,
bashInteractive,
fallbackShell ? bashInteractive,
@ -20,7 +20,7 @@ in stdenvNoCC.mkDerivation {
dontCheck = true;
nativeBuildInputs = [
zig.hook
zig_0_14.hook
];
zigBuildFlags = [
@ -34,7 +34,6 @@ in stdenvNoCC.mkDerivation {
homepage = "https://github.com/RGBCube/crash";
license = licenses.mit;
mainProgram = "crash";
platforms = platforms.linux;
maintainers = with maintainers; [ RGBCube ];
platforms = platforms.unix;
};
}

View file

@ -1,8 +1,8 @@
const std = @import("std");
const fallback_shell = @import("build_options").fallback_shell orelse @compileError("fallback shell was not specified");
pub fn fallback(alloc: std.mem.Allocator) noreturn {
const err = std.process.execv(alloc, &[_][]const u8{fallback_shell});
pub fn fallback(alloc: std.mem.Allocator, args: []const []const u8) noreturn {
const err = std.process.execv(alloc, args);
std.process.exit(@intCast(@intFromError(err)));
}
@ -10,7 +10,7 @@ pub fn main() noreturn {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc);
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc, &[_][]const u8{fallback_shell});
defer alloc.free(args);
args.len = 0;
@ -20,18 +20,27 @@ pub fn main() noreturn {
args[args.len - 1] = arg;
}
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc);
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
});
var it = std.mem.split(u8, shells, ":");
var it = std.mem.splitScalar(u8, shells, ':');
while (it.next()) |shell| {
args[0] = shell;
var child = std.process.Child.init(args, alloc);
switch (child.spawnAndWait() catch fallback(alloc)) {
switch (child.spawnAndWait() catch fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
})) {
std.process.Child.Term.Exited => |exit_code| if (exit_code == 0) std.process.exit(0),
else => continue,
}
}
fallback(alloc);
fallback(alloc, args: {
args[0] = fallback_shell;
break :args args;
});
}