Skip to content

build: reduce macOS release binary size with LLD - #4281

Closed
codeshaunted wants to merge 4 commits into
canaryfrom
codex/safe-icf-size
Closed

codeshaunted wants to merge 4 commits into
canaryfrom
codex/safe-icf-size

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • link macOS toolchain releases with the Rust 1.93 bundled LLD and safe ICF
  • remove unused dylib loads and Mach-O function-start metadata
  • apply the same flags to the macOS size gate
  • leave Linux and Windows unchanged
  • cover the release workflow contract

Size impact

Measured with the aarch64-apple-darwin size gate:

Artifact Baseline Safe ICF Final Total reduction
baml-cli 21,286,092 B 20,720,192 B 20,666,768 B 619,324 B (2.91%)
packed program 13,841,203 B 13,620,482 B 13,586,034 B 255,169 B (1.84%)

Removing LC_FUNCTION_STARTS accounts for the additional 53,424 B reduction in baml-cli and 34,448 B in the packed program. It does not affect runtime performance, but removes function-boundary metadata used by macOS profilers and symbolication tools.

Linux experiments were not retained:

  • LLD with safe ICF increased baml-cli by 8,832 B versus the default linker in consecutive CI runs.
  • DT_RELR saved roughly 1 MB, but baml pack cannot parse the resulting ELF section with the pinned object implementation. It would also require glibc 2.36 or newer.

Verification

  • macOS baml-cli and baml-pack-host release builds
  • valid ad hoc signatures on both executables
  • full local size gate, including packed-program creation and launch
  • python3 -m unittest scripts.tests.test_release_pipeline_contract (23 tests)
  • repository pre-commit hooks

@vercel

vercel Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Error Error Jul 30, 2026 7:05pm
promptfiddle2 Ready Ready Preview Jul 30, 2026 7:05pm

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Rustflags script now supports macOS hosts only and no longer accepts a target argument. Release and size-gate workflows apply its flags only to macOS jobs, with contract tests updated accordingly.

Changes

Safe ICF release pipeline

Layer / File(s) Summary
macOS Rustflags generation and workflow wiring
scripts/baml-release-rustflags, .github/workflows/release-baml-language.yml, .github/workflows/size-gate.reusable.yaml
The script emits bundled-LLD linker flags for macOS only; release and size-gate workflows apply them to Apple Darwin jobs and remove Linux usage.
macOS workflow contract validation
scripts/tests/test_release_pipeline_contract.py
Contract tests verify macOS targeting, Rustflags content, and updated workflow invocation counts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: rossirpaulo

Poem

A rabbit hops where Mac flags gleam,
LLD guides the linking stream.
Linux steps now rest,
Contract tests check the quest.
Safe ICF springs bright—
Through workflows into flight! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the macOS-focused size reduction using LLD, which matches the main change in the PR.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/safe-icf-size

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
scripts/tests/test_release_pipeline_contract.py (2)

656-668: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test that existing RUSTFLAGS are preserved.

The assertions only check the appended linker flags. A regression that overwrites the caller’s RUSTFLAGS would still pass, despite the PR contract. Assert the preservation expression or run the script with a sentinel existing value and verify it remains in the output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/tests/test_release_pipeline_contract.py` around lines 656 - 668,
Extend test_unix_toolchain_releases_and_size_gates_enable_safe_icf to verify
that scripts/baml-release-rustflags preserves pre-existing RUSTFLAGS, not just
appends linker flags. Assert the workflow or script uses the preservation
expression, or execute the script with a sentinel RUSTFLAGS value and confirm
that value remains in the generated output.

656-668: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Scope workflow assertions to the actual jobs and ordering.

Raw count() checks can pass when the script path appears in an unrelated step or comment; they do not prove the environment step runs in build-toolchain and both size-gate jobs before their build/check steps. Use the existing job/step helpers or parse YAML to assert placement.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/tests/test_release_pipeline_contract.py` around lines 656 - 668,
Update test_unix_toolchain_releases_and_size_gates_enable_safe_icf to inspect
parsed workflow jobs or use the existing job/step helpers instead of raw
script-path count assertions. Assert the rustflags script is configured within
build-toolchain and in both size-gate jobs, with each environment step appearing
before that job’s build/check step; retain the existing rustflags and
release-condition assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/tests/test_release_pipeline_contract.py`:
- Around line 656-668: Extend
test_unix_toolchain_releases_and_size_gates_enable_safe_icf to verify that
scripts/baml-release-rustflags preserves pre-existing RUSTFLAGS, not just
appends linker flags. Assert the workflow or script uses the preservation
expression, or execute the script with a sentinel RUSTFLAGS value and confirm
that value remains in the generated output.
- Around line 656-668: Update
test_unix_toolchain_releases_and_size_gates_enable_safe_icf to inspect parsed
workflow jobs or use the existing job/step helpers instead of raw script-path
count assertions. Assert the rustflags script is configured within
build-toolchain and in both size-gate jobs, with each environment step appearing
before that job’s build/check step; retain the existing rustflags and
release-condition assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bfd4559-9735-4f69-acfe-7ac77375a5b2

📥 Commits

Reviewing files that changed from the base of the PR and between 61148c0 and a6c0dc4.

📒 Files selected for processing (4)
  • .github/workflows/release-baml-language.yml
  • .github/workflows/size-gate.reusable.yaml
  • scripts/baml-release-rustflags
  • scripts/tests/test_release_pipeline_contract.py

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 30, 2026 17:52 Inactive
@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 27.4 MB 11.7 MB file 27.4 MB +43.2 KB (+0.2%) OK
✅ packed-program Linux 🔒 17.7 MB 7.3 MB file 17.7 MB +13.2 KB (+0.1%) OK
✅ baml-cli macOS 🔒 20.7 MB 10.1 MB file 21.3 MB -619.3 KB (-2.9%) OK
✅ packed-program macOS 🔒 13.6 MB 6.4 MB file 13.8 MB -255.2 KB (-1.8%) OK
✅ baml-cli Windows 🔒 23.0 MB 10.4 MB file 23.0 MB +13.7 KB (+0.1%) OK
✅ packed-program Windows 🔒 14.8 MB 6.5 MB file 14.8 MB -10.3 KB (-0.1%) OK
✅ bridge_wasm WASM 16.8 MB 🔒 4.6 MB gzip 4.6 MB -40.9 KB (-0.9%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@vercel
vercel Bot temporarily deployed to Preview – beps July 30, 2026 18:43 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 30, 2026 18:51 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/release-baml-language.yml:
- Around line 342-344: Update the “Enable safe ICF” workflow step so
scripts/baml-release-rustflags must complete successfully before modifying
GITHUB_ENV. Capture its output in a temporary shell variable, fail the step on
command failure, and only then append the generated RUSTFLAGS value without
overwriting an existing value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c23b10de-9b29-4512-b1d0-056be0eb6f17

📥 Commits

Reviewing files that changed from the base of the PR and between a6c0dc4 and 321bb76.

📒 Files selected for processing (3)
  • .github/workflows/release-baml-language.yml
  • scripts/baml-release-rustflags
  • scripts/tests/test_release_pipeline_contract.py

Comment on lines +342 to +344
- name: Enable safe ICF
if: ${{ !contains(matrix.target, 'windows-msvc') }}
run: echo "RUSTFLAGS=$(scripts/baml-release-rustflags '${{ matrix.target }}')" >> "$GITHUB_ENV"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT

bash -c 'set -e; echo "RUSTFLAGS=$(false)" >> "$1"' bash "$tmp"
test -s "$tmp"

Repository: BoundaryML/baml

Length of output: 153


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== workflow context =="
sed -n '320,355p' .github/workflows/release-baml-language.yml

echo
echo "== rustflags script outline/search =="
if [ -f scripts/baml-release-rustflags ]; then
  wc -l scripts/baml-release-rustflags
  sed -n '1,220p' scripts/baml-release-rustflags
else
  echo "scripts/baml-release-rustflags not found"
  fd -a 'baml-release-rustflags|rustflags' .
fi

echo
echo "== related environment writes =="
rg -n 'RUSTFLAGS=|baml-release-rustflags|Enable safe ICF' .github/workflows/release-baml-language.yml

Repository: BoundaryML/baml

Length of output: 2789


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT

echo "== current single-line behavior =="
bash -c 'set -e; echo "RUSTFLAGS=$(false)" >> "$1"; echo "job status: ${PIPESTATUS[*]}"' bash "$tmp"
echo "file contents:"
cat -n "$tmp"
echo "exit: $?"

echo
echo "== proposed fail-closed behavior =="
bash -c 'set -euo pipefail; if ! rustflags="$(false)"; then exit 1; fi; printf "RUSTFLAGS=%s\n" "$rustflags" >> "$1"' bash "$tmp"
echo "proposal exit status: $?"

Repository: BoundaryML/baml

Length of output: 280


Fail closed when Rustflags generation fails.

The single-line command substitution happens before echo’s exit status, so RUSTFLAGS=$(fake-fail) can produce RUSTFLAGS= and exit successfully. This can let the job continue without safe ICF or replace existing RUSTFLAGS; write the value only after the script succeeds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/release-baml-language.yml around lines 342 - 344, Update
the “Enable safe ICF” workflow step so scripts/baml-release-rustflags must
complete successfully before modifying GITHUB_ENV. Capture its output in a
temporary shell variable, fail the step on command failure, and only then append
the generated RUSTFLAGS value without overwriting an existing value.

@vercel
vercel Bot temporarily deployed to Preview – beps July 30, 2026 18:56 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps July 30, 2026 18:57 Inactive
@codeshaunted codeshaunted changed the title build: enable safe ICF for Unix toolchains build: reduce macOS release binary size with LLD Jul 30, 2026
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 30, 2026 19:05 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/tests/test_release_pipeline_contract.py (1)

656-672: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Restore the RELR regression assertion.

This change removes the pack-relative-relocs check, but the PR objective explicitly preserves RELR being disabled for packed programs. Keep an equivalent negative assertion against the actual packed-program flags or configuration so a future regression remains covered.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/tests/test_release_pipeline_contract.py` around lines 656 - 672,
Update test_macos_toolchain_releases_and_size_gate_enable_safe_icf to restore a
negative assertion confirming pack-relative-relocs/RELR remains disabled for
packed programs. Assert against the actual packed-program flags or configuration
used by the release pipeline, while preserving the existing toolchain and linker
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/release-baml-language.yml:
- Line 344: Update the release workflow step that invokes
scripts/baml-release-rustflags so a failure from that script causes the step to
fail before writing to GITHUB_ENV. Preserve the existing RUSTFLAGS export on
success, and ensure an empty or failed result cannot overwrite existing flags.

---

Nitpick comments:
In `@scripts/tests/test_release_pipeline_contract.py`:
- Around line 656-672: Update
test_macos_toolchain_releases_and_size_gate_enable_safe_icf to restore a
negative assertion confirming pack-relative-relocs/RELR remains disabled for
packed programs. Assert against the actual packed-program flags or configuration
used by the release pipeline, while preserving the existing toolchain and linker
assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 484ae1e8-70d8-4f41-80cb-8833a062810a

📥 Commits

Reviewing files that changed from the base of the PR and between 321bb76 and eda0b60.

📒 Files selected for processing (4)
  • .github/workflows/release-baml-language.yml
  • .github/workflows/size-gate.reusable.yaml
  • scripts/baml-release-rustflags
  • scripts/tests/test_release_pipeline_contract.py
💤 Files with no reviewable changes (1)
  • .github/workflows/size-gate.reusable.yaml

target: ${{ matrix.target }}
- name: Enable safe ICF
if: ${{ contains(matrix.target, 'apple-darwin') }}
run: echo "RUSTFLAGS=$(scripts/baml-release-rustflags)" >> "$GITHUB_ENV"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fail closed before writing GITHUB_ENV.

If scripts/baml-release-rustflags fails, the command substitution can still let echo succeed and write RUSTFLAGS=, so the build continues without safe ICF and may overwrite existing flags.

Proposed fix
-        run: echo "RUSTFLAGS=$(scripts/baml-release-rustflags)" >> "$GITHUB_ENV"
+        run: |
+          set -euo pipefail
+          rustflags="$(scripts/baml-release-rustflags)"
+          printf 'RUSTFLAGS=%s\n' "$rustflags" >> "$GITHUB_ENV"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/release-baml-language.yml at line 344, Update the release
workflow step that invokes scripts/baml-release-rustflags so a failure from that
script causes the step to fail before writing to GITHUB_ENV. Preserve the
existing RUSTFLAGS export on success, and ensure an empty or failed result
cannot overwrite existing flags.

This branch was previously deployed

2 inactive deployments
Preview – promptfiddle2 — eda0b600 Deployed Jul 30, 2026 by vercel[bot]
Preview – beps — eda0b600 Deployed Jul 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant