fix: use indirect symlink on Apple Silicon
Makes the execution of the symlink entirely hermetic. Previously, a direct symlink was used which required the APE binary to unpack and compile the embedded APE launcher. This requires a `cc` on the system. This patch shifts to use the already compiled APE launcher and a "indirect" symlink. The [indirect] symlink feature works by having a `.ape` extension to a symlink that points at the APE launcher. The launcher then removes the `.ape` extension and uses that as the path to the binary to launch. The crucial point is that assimilating an APE binary on MacOS is not natively launchable, unlike all other platforms: ```console $ cd /tmp $ curl -sfSL https://cosmo.zip/pub/cosmos/v/4.0.2/bin/assimilate > assimilate $ curl -sfSL https://cosmo.zip/pub/cosmos/v/4.0.2/bin/awk > awk $ chmod +x assimilate $ chmod +x awk $ ./ape # Already compiled from the patched `ape-m1.c` usage: ape PROG [ARGV1,ARGV2,...] ape - PROG [ARGV0,ARGV1,...] PROG.ape [ARGV1,ARGV2,...] actually portable executable loader silicon 1.10 copyrights 2023 justine alexandra roberts tunney https://justine.lol/ape.html $ ./ape ./awk awk version 20240311 $ ./awk xcode-select: note: No developer tools were found, requesting install. If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog. See `man xcode-select` for more details. $ ./ape ./assimilate -o awk.assimilated awk awk: ape macho dd command for arm64 not found; by convention ape executables are run on apple silicon only as elf binaries, which are loaded by the ape-m1.c ape loader program; thus consider passing the -ae flags to assimilate to arm64 elf (the host os uses macho natively) $ ./ape ./assimilate -ae -o awk.assimilated awk $ chmod +x awk.assimilated $ ./awk.assimilated zsh: exec format error: ./awk.assimilated $ ./ape ./awk.assimilated awk version 20240311 $ ln -s ape awk.ape # indirect symlink $ ./awk.ape awk version 20240311 $ ln -s awk.ape abc # symlink chain (does not work without the patch) awk version 20240311 ``` [indirect]: https://github.com/jart/cosmopolitan/blob/9f6bf6ea71e1385cc34dab0c492773f428d62869/ape/ape-m1.c#L1043-L1055
Loading