| 1 | const std = @import("std"); |
| 2 | |
| 3 | pub fn main(init: std.process.Init) !void { |
| 4 | const io = init.io; |
| 5 | const gpa = init.gpa; |
| 6 | var it = try init.minimal.args.iterateAllocator(gpa); |
| 7 | defer it.deinit(); |
| 8 | _ = it.next() orelse unreachable; // skip binary name |
| 9 | const exe_path = it.next() orelse unreachable; |
| 10 | const symlink_path = it.next() orelse unreachable; |
| 11 | |
| 12 | const cwd = try std.process.currentPathAlloc(io, init.arena.allocator()); |
| 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(gpa, cwd, init.environ_map, std.fs.path.dirname(symlink_path) orelse ".", exe_path); |
| 16 | defer gpa.free(exe_rel_path); |
| 17 | |
| 18 | try std.Io.Dir.cwd().symLink(io, exe_rel_path, symlink_path, .{}); |
| 19 | } |