Skip to content

fix(build): Use shared Rust target directory by default (fixes #2442). - #2459

Open
junhaoliao wants to merge 1 commit into
y-scope:mainfrom
junhaoliao:feat/shared-rust-target-directory
Open

fix(build): Use shared Rust target directory by default (fixes #2442).#2459
junhaoliao wants to merge 1 commit into
y-scope:mainfrom
junhaoliao:feat/shared-rust-target-directory

Conversation

@junhaoliao

@junhaoliao junhaoliao commented Aug 6, 2026

Copy link
Copy Markdown
Member

Description

Fixes #2442.

Cargo commands launched outside the Taskfile environment, including IDE language servers and coding agents, currently fall back to the repository-local target/ directory and duplicate artifacts already stored under build/rust-targets.

Restore build/rust-targets as Cargo's repository default in .cargo/config.toml. The generated toolchain environment continues to export CARGO_TARGET_DIR from G_RUST_BUILD_DIR, so custom G_BUILD_DIR values still take precedence over the default.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

$ task lint:fix-rust >/dev/null 2>&1 && printf 'task lint:fix-rust: passed\n'
task lint:fix-rust: passed

$ task tests:rust-all >/dev/null 2>&1 && printf 'task tests:rust-all: passed\n'
task tests:rust-all: passed

$ task >/dev/null 2>&1 && printf 'task: passed\n'
task: passed

$ printf 'default=' && env -u CARGO_TARGET_DIR cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["target_directory"])' && printf 'override=' && CARGO_TARGET_DIR=/tmp/clp-issue-2442-target cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["target_directory"])' && printf 'task-env=' && sed -n 's/^export CARGO_TARGET_DIR="\(.*\)"$/\1/p' build/toolchains/rust/env
default=/home/junhao/.codex/worktrees/de50/clp/build/rust-targets
override=/tmp/clp-issue-2442-target
task-env=/home/junhao/.codex/worktrees/de50/clp/build/rust-targets

$ git diff --check && printf 'git diff --check: passed\n'
git diff --check: passed

Summary by CodeRabbit

  • Chores
    • Updated Rust build output storage to use a dedicated build directory.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a73de9a8-9f63-490e-957b-8d5978bd3025

📥 Commits

Reviewing files that changed from the base of the PR and between 979b93c and 376794b.

📒 Files selected for processing (1)
  • .cargo/config.toml

Walkthrough

Cargo now stores Rust build outputs in build/rust-targets through the project Cargo configuration.

Changes

Cargo build configuration

Layer / File(s) Summary
Configure Cargo target directory
.cargo/config.toml
Cargo uses build/rust-targets for Rust build outputs.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related issues

Suggested reviewers: davidlion

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: using a shared Rust target directory by default.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@junhaoliao
junhaoliao marked this pull request as ready for review August 6, 2026 18:34
@junhaoliao
junhaoliao requested a review from a team as a code owner August 6, 2026 18:34
@Bill-hbrhbr

Bill-hbrhbr commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

I assume this PR is intended to have Cargo invocations outside the CLP toolchain environment use the same target directory as the CLP-managed toolchain.

That being said, if a user runs:

G_BUILD_DIR=/some/other/location task <some_rust_task>

the target-dir added to .cargo/config.toml would no longer match the target directory used by the CLP toolchain.

If supporting custom G_BUILD_DIR values is not a requirement for Rust build artifacts, .cargo/config.toml can be sufficient to serve as the single source of truth for the Rust target directory, and we could remove the CARGO_TARGET_DIR export from build/toolchains/rust/env.


Anyway, there's no perfect way to make cargo default to the CLP-installed toolchain without requiring some prerequisite setup.

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.

Rust language servers can create build artifacts outside build/rust-targets

2 participants