1
Fork 0
mirror of https://github.com/RGBCube/crash synced 2025-08-03 03:47:47 +00:00

Compare commits

..

No commits in common. "7849872b30482ecab7d3586246e46855522ea64d" and "3405a772baa5c33adab82c3d6034a7f1d8c62b65" have entirely different histories.

5 changed files with 18 additions and 29 deletions

View file

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

6
flake.lock generated
View file

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

View file

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

View file

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

View file

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