Skip to content

Commit

Permalink
Use lld to reduce macOS release binary size
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanau committed Oct 9, 2024
1 parent 5bc9bf2 commit 35fec47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ build:release_macos --config=release_unix
# data in releases.
build:release_macos --linkopt="-Wl,-no_data_in_code_info"
build:release_macos --linkopt="-Wl,-no_function_starts"
# Enable lld identical code folding to significantly reduce binary size.
build:release_macos --config=macos_lld_icf

# On macOS, compile using LLD (19 or higher is compatible with the default flags added by
# apple_support). Requires Homebrew's lld package to be installed. This is less CPU intensive than
# the system linker, but also slightly slower in terms of wall time since it is less parallel. More
# importantly, it allows us to enable LLD's ICF pass, which significantly decreases binary sizes.
# We also want to enable ICF for Linux, but there it causes warnings when dynamically linking with
# libc++.
build:macos_lld --linkopt="-fuse-ld=/opt/homebrew/bin/ld64.lld"
build:macos_lld_icf --config=macos_lld
build:macos_lld_icf --linkopt="-Wl,--icf=safe"

build:release_windows --config=release
# Windows uses /O2 as its preferred optimization setting and enabled by bazel in the opt
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ jobs:
if: runner.os == 'macOS'
run: |
sudo xcode-select -s "/Applications/Xcode_15.1.app"
# Install lld
brew install lld
- name: Setup Windows
if: runner.os == 'Windows'
run: |
Expand Down

0 comments on commit 35fec47

Please sign in to comment.