How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions

Homebrew often provides static libraries in addition to shared ones. Therefore, you can use Homebrew to obtain static libraries and link them manually.

To do this, you should first create symbolic links or copy the static libraries to a separate direc…


This content originally appeared on DEV Community and was authored by kojix2

Homebrew often provides static libraries in addition to shared ones. Therefore, you can use Homebrew to obtain static libraries and link them manually.

To do this, you should first create symbolic links or copy the static libraries to a separate directory, and then refer to them using --link-flags. This is necessary because if both static and shared libraries exist in the same directory, the linker will prioritize the shared libraries. Moving the static libraries to a different location is currently the only reliable workaround. If there is a better solution, I’d be happy to hear it.

- name: Build executable (macOS)
  if: matrix.os == 'macos'
  run: |
    brew update
    brew install libgc pcre2
    ln -s $(brew ls libgc | grep libgc.a) .
    ln -s $(brew ls pcre2 | grep libpcre2-8.a) .
    shards build --link-flags="-L $(pwd) $(pwd)/libgc.a $(pwd)/libpcre2-8.a" --release
    otool -L bin/lolcat

Note: The binary produced using this method will be specific to Apple Silicon (Arm) Macs when using latest-macos runners. Creating a universal binary that supports both Intel and Arm architectures is significantly more complex. Given that it has been five years since the last Intel Mac was sold, it is probably acceptable to distribute Arm-only binaries for now.

Alternative Distribution Methods

Even if you provide a pre-built binary as described above, users on macOS may need to manually allow its execution via the System Settings > Privacy & Security menu, which can be a bit of a hassle.

A more convenient and recommended approach is to use a Homebrew tap. This method allows users to compile the source code themselves using Crystal, automatically installed via Homebrew. Since Homebrew also installs shared libraries, this method ensures that dependencies are resolved smoothly.

Nevertheless, distributing a statically linked binary—as is common in Rust projects—has a certain elegance. The method shown above demonstrates that it's not impossible to achieve this with Crystal as well.


This content originally appeared on DEV Community and was authored by kojix2


Print Share Comment Cite Upload Translate Updates
APA

kojix2 | Sciencx (2025-07-21T02:34:19+00:00) How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions. Retrieved from https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/

MLA
" » How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions." kojix2 | Sciencx - Monday July 21, 2025, https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/
HARVARD
kojix2 | Sciencx Monday July 21, 2025 » How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions., viewed ,<https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/>
VANCOUVER
kojix2 | Sciencx - » How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/
CHICAGO
" » How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions." kojix2 | Sciencx - Accessed . https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/
IEEE
" » How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions." kojix2 | Sciencx [Online]. Available: https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/. [Accessed: ]
rf:citation
» How to Distribute a Statically Linked Crystal Binary on macOS with GitHub Actions | kojix2 | Sciencx | https://www.scien.cx/2025/07/21/how-to-distribute-a-statically-linked-crystal-binary-on-macos-with-github-actions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.