Skip to content

fix: build --lib only for .rlib targets to skip harness binaries - #1397

Merged
shunkakinoki merged 3 commits into
mainfrom
fix/cargo-rlib-lib-only
Apr 6, 2026
Merged

fix: build --lib only for .rlib targets to skip harness binaries#1397
shunkakinoki merged 3 commits into
mainfrom
fix/cargo-rlib-lib-only

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • When update-local-binaries.sh encounters a .rlib target (e.g. frankensqlite/target/release/libfsqlite.rlib), it now passes --lib to cargo build instead of building all targets
  • Avoids compiling 200+ harness/e2e binaries in large workspaces, cutting frankensqlite build time from ~4min to ~30-60s on warm cache

Test plan

  • Run update-local-binaries.sh and confirm frankensqlite lib builds without triggering harness binary compilation

Summary by cubic

Use cargo build --lib for .rlib targets in update-local-binaries.sh to skip harness/test binaries, leaving other targets unchanged.
Pass extra cargo flags via an array to satisfy ShellCheck/shell tests and apply formatting; frankensqlite drops from ~4m to ~30–60s on warm cache.

Written for commit fea4628. Summary will update on new commits.

Copilot AI review requested due to automatic review settings April 6, 2026 17:22
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The build_repo function in scripts/update-local-binaries.sh now expands ~ in binary_path and conditionally appends --lib to the cargo +nightly build invocation when the resolved path ends with .rlib; otherwise it uses the default release build flags.

Changes

Cohort / File(s) Summary
Cargo Build Flag Selection
scripts/update-local-binaries.sh
Resolve ~ in binary_path before checking suffix; compute cargo_flags conditionally and append --lib when target ends with .rlib; previously always used cargo +nightly build --release.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I sniffed the path, expanded the tilde with glee,
If .rlib is found, --lib joins the spree.
Nightly cargo hums, flags chosen just right,
Binaries and libraries, hopping into the night. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding --lib flag for .rlib targets to skip harness binary compilation, which directly matches the primary modification in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the optimization of cargo build flags for .rlib targets in update-local-binaries.sh.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cargo-rlib-lib-only

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 and usage tips.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 6, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@mesa-dot-dev

mesa-dot-dev Bot commented Apr 6, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Optimized cargo build for .rlib targets in update-local-binaries.sh to skip building unnecessary harness binaries, significantly reducing build times for large Rust workspaces.

What changed?

  • scripts/update-local-binaries.sh: The build_repo function now conditionally passes the --lib flag to cargo build when the detected target is a .rlib file.

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request modifies the build process in scripts/update-local-binaries.sh to conditionally include the --lib flag when the target is a .rlib file, optimizing builds in large workspaces. Review feedback highlights a regression in the test suite due to the changed command string and suggests using Bash arrays for more robust flag handling along with support for additional library file extensions.

Comment thread scripts/update-local-binaries.sh Outdated
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then

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.

high

This change will cause the test at line 166 of spec/update_local_binaries_spec.sh to fail. The test uses grep to look for the literal string cargo +nightly build --release in the script, which no longer exists in that form. Please update the test suite to accommodate this change.

Comment thread scripts/update-local-binaries.sh Outdated
Comment on lines +175 to +182
# If the target is a .rlib, only build the library (avoids compiling all
# test/harness binaries in large workspaces like frankensqlite).
local cargo_flags="--release"
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then

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.

medium

Using an array for cargo_flags is more robust and maintainable than string concatenation, as it correctly handles argument boundaries and makes it easier to extend with more flags. Additionally, the tilde expansion for expanded_bin is not strictly necessary for the extension check within [[ ... ]] as the pattern match works on the raw string.

You might also consider supporting other library extensions like .a, .so, and .dylib for consistency with sync-local-binaries.sh.

Suggested change
# If the target is a .rlib, only build the library (avoids compiling all
# test/harness binaries in large workspaces like frankensqlite).
local cargo_flags="--release"
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then
# If the target is a .rlib, only build the library (avoids compiling all
# test/harness binaries in large workspaces like frankensqlite).
local cargo_flags=("--release")
if [[ "$binary_path" == *.rlib ]]; then
cargo_flags+=("--lib")
fi
if (cd "$build_dir" && cargo +nightly build "${cargo_flags[@]}" 2>&1); then

Copilot AI 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.

Pull request overview

Updates the local binaries updater script to avoid building unnecessary Rust workspace targets when the configured artifact is a .rlib, significantly reducing build time for large workspaces.

Changes:

  • Detect .rlib targets and add --lib to the cargo build invocation.
  • Keep default behavior (--release) for non-.rlib Rust targets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 174 to 183
if [ -f "$build_dir/Cargo.toml" ]; then
if (cd "$build_dir" && cargo +nightly build --release 2>&1); then
# If the target is a .rlib, only build the library (avoids compiling all
# test/harness binaries in large workspaces like frankensqlite).
local cargo_flags="--release"
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then
return 0

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

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

This change replaces the literal cargo +nightly build --release command with cargo +nightly build $cargo_flags, which will break the existing shell spec that greps for cargo +nightly build --release (see spec/update_local_binaries_spec.sh). Update the spec to assert the new behavior (including the new --lib case for .rlib targets) rather than matching the old hard-coded command string.

Copilot uses AI. Check for mistakes.
Comment thread scripts/update-local-binaries.sh Outdated
Comment on lines +177 to +182
local cargo_flags="--release"
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

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

Consider storing cargo flags in a bash array (e.g., cargo_flags=(--release) and conditionally appending --lib) and invoking cargo with "${cargo_flags[@]}". This avoids relying on word-splitting of $cargo_flags and makes the command more robust if additional flags are added later.

Suggested change
local cargo_flags="--release"
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then
local cargo_flags=(--release)
local expanded_bin="${binary_path/#\~/$HOME}"
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags+=(--lib)
fi
if (cd "$build_dir" && cargo +nightly build "${cargo_flags[@]}" 2>&1); then

Copilot uses AI. Check for mistakes.

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/update-local-binaries.sh">

<violation number="1" location="scripts/update-local-binaries.sh:182">
P2: This change removes the literal `cargo +nightly build --release` string from the script, which will break the existing test in `spec/update_local_binaries_spec.sh` that uses `grep` to match that exact command. The spec needs to be updated to account for the new `$cargo_flags` variable (and ideally assert the `--lib` behavior for `.rlib` targets).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread scripts/update-local-binaries.sh Outdated
if [[ "$expanded_bin" == *.rlib ]]; then
cargo_flags="--release --lib"
fi
if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then

@cubic-dev-ai cubic-dev-ai Bot Apr 6, 2026

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.

P2: This change removes the literal cargo +nightly build --release string from the script, which will break the existing test in spec/update_local_binaries_spec.sh that uses grep to match that exact command. The spec needs to be updated to account for the new $cargo_flags variable (and ideally assert the --lib behavior for .rlib targets).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/update-local-binaries.sh, line 182:

<comment>This change removes the literal `cargo +nightly build --release` string from the script, which will break the existing test in `spec/update_local_binaries_spec.sh` that uses `grep` to match that exact command. The spec needs to be updated to account for the new `$cargo_flags` variable (and ideally assert the `--lib` behavior for `.rlib` targets).</comment>

<file context>
@@ -172,7 +172,14 @@ build_repo() {
+    if [[ "$expanded_bin" == *.rlib ]]; then
+      cargo_flags="--release --lib"
+    fi
+    if (cd "$build_dir" && cargo +nightly build $cargo_flags 2>&1); then
       return 0
     else
</file context>
Fix with Cubic

@shunkakinoki
shunkakinoki merged commit 6d17add into main Apr 6, 2026
36 checks passed
@shunkakinoki
shunkakinoki deleted the fix/cargo-rlib-lib-only branch April 6, 2026 18:48
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.

2 participants