|
| 1 | +# macOS Installation Guide for Cross-Compilation to aarch64-unknown-linux-musl |
| 2 | + |
| 3 | +This guide outlines the steps to set up your macOS environment for cross-compiling Rust projects to the `aarch64-unknown-linux-musl` target. This is particularly useful for building binaries that can run on ARM-based Linux systems (e.g., Raspberry Pi, AWS Graviton) using musl libc. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +* Homebrew (https://brew.sh/) installed on your macOS system. |
| 8 | +* Rust and Cargo installed (e.g., via `rustup`). |
| 9 | + |
| 10 | +## Step 1: Install the `aarch64-linux-musl-gcc` Toolchain |
| 11 | + |
| 12 | +The `aarch64-linux-musl-gcc` toolchain is required for linking when cross-compiling to `aarch64-unknown-linux-musl`. You can install it using Homebrew: |
| 13 | + |
| 14 | +```bash |
| 15 | +brew install messense/macos-cross-toolchains/aarch64-linux-musl-cross |
| 16 | +``` |
| 17 | + |
| 18 | +## Step 2: Link `musl-gcc` |
| 19 | + |
| 20 | +Some build scripts or tools might look for `musl-gcc`. To ensure compatibility, create a symbolic link: |
| 21 | + |
| 22 | +```bash |
| 23 | +sudo ln -s /opt/homebrew/bin/aarch64-linux-musl-gcc /opt/homebrew/bin/musl-gcc |
| 24 | +``` |
| 25 | + |
| 26 | +You might be prompted for your system password to complete this operation. |
| 27 | + |
| 28 | +## Step 3: Add the Rust Target |
| 29 | + |
| 30 | +Add the `aarch64-unknown-linux-musl` target to your Rust toolchain: |
| 31 | + |
| 32 | +```bash |
| 33 | +rustup target add aarch64-unknown-linux-musl |
| 34 | +``` |
| 35 | + |
| 36 | +## Step 4: Build Your Project |
| 37 | + |
| 38 | +Now you can build your Rust project for the `aarch64-unknown-linux-musl` target using Cargo: |
| 39 | + |
| 40 | +```bash |
| 41 | +cargo build --release --target aarch64-unknown-linux-musl |
| 42 | +``` |
| 43 | + |
| 44 | +Alternatively, if you are using the provided `Makefile`, you can use the new target: |
| 45 | + |
| 46 | +```bash |
| 47 | +make release-aarch64-musl |
| 48 | +``` |
| 49 | + |
| 50 | +This will produce a release binary located in `target/aarch64-unknown-linux-musl/release/`. |
| 51 | + |
| 52 | +## Step 5: Running Zinit |
| 53 | + |
| 54 | +After building, you can run `zinit`. First, you need to start the `zinit` daemon using the `init` subcommand. On macOS, `zinit` will now default to using `~/hero/cfg/zinit` as its configuration directory. This will create the Unix socket at `/tmp/zinit.sock` and start managing services. |
| 55 | + |
| 56 | +Once the directory is created (if it doesn't exist, `zinit` will create it automatically), you can run the `init` command: |
| 57 | + |
| 58 | +```bash |
| 59 | +/path/to/your/zinit init |
| 60 | +``` |
| 61 | + |
| 62 | +Replace `/path/to/your/zinit` with the actual path to your compiled `zinit` binary (e.g., `~/hero/bin/zinit` if you copied it there). |
| 63 | + |
| 64 | +Once the daemon is running, you can interact with it using other `zinit` commands. For example, to list services: |
| 65 | + |
| 66 | +```bash |
| 67 | +/path/to/your/zinit list |
| 68 | +``` |
| 69 | + |
| 70 | +If you encounter a "failed to connect to socket" error, ensure that the `zinit init` command is running in the background. |
0 commit comments