Skip to content

Hermetic Apple Silicon Support

Matthew Clarkson requested to merge macos into main

Supports Apple Silicon when Developer Tools are not installed.

  • Upgrades toolchain_utils to get support for Bash 3.2
    • Newer Bash on Mac requires Homebrew, or similar to get newer Bash due to license restrictions
  • Compiles the APE launcher using a zig cc -target so that host libc detection does not need to occur
    • Host detection requires Developer Tool installed
  • Uses APE launcher indirect symlinks to remove the need for the APE binary to recompile the embedded APE launcher with system cc
    • Developer Tools are required for a system cc
  • Patches the APE launcher to walk a symlink tree back to the indirect symlink
    • Allows symlink chain in Bazel to resolve correctly

The crucial point is that assimilating an APE binary on MacOS is not natively launchable, unlike all other platforms:

$ 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
Edited by Matthew Clarkson

Merge request reports