master
1const std = @import("std");
2
3pub fn main() anyerror!void {
4 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
5 defer if (gpa.deinit() == .leak) @panic("found memory leaks");
6 const allocator = gpa.allocator();
7
8 var it = try std.process.argsWithAllocator(allocator);
9 defer it.deinit();
10 _ = it.next() orelse unreachable; // skip binary name
11 const exe_path = it.next() orelse unreachable;
12 const symlink_path = it.next() orelse unreachable;
13
14 // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
15 const exe_rel_path = try std.fs.path.relative(allocator, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
16 defer allocator.free(exe_rel_path);
17 try std.fs.cwd().symLink(exe_rel_path, symlink_path, .{});
18}