Skip to content

make find_libilo_a honour CARGO_TARGET_DIR and .cargo/config.toml#514

Merged
danieljohnmorris merged 1 commit into
mainfrom
fix/aot-target-dir-lookup
May 21, 2026
Merged

make find_libilo_a honour CARGO_TARGET_DIR and .cargo/config.toml#514
danieljohnmorris merged 1 commit into
mainfrom
fix/aot-target-dir-lookup

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

The AOT linker helper find_libilo_a (in src/vm/compile_cranelift.rs) hard-coded $CARGO_MANIFEST_DIR/target/{release,debug}/libilo.a as its only search path. Fix worktrees that redirect cargo's target dir out of the tree, which is the convention we adopted for isolated parallel builds (.cargo/config.toml containing [build]\ntarget-dir = "/tmp/ilo-targets/<worktree-name>"), ended up with the staticlib at the redirected path while the lookup kept probing target/. Every aot_compile_* test failed with cannot find libilo.a, and each fix PR carried a ln -sf /tmp/ilo-targets/<name>/release/libilo.a target/release/libilo.a workaround.

That workaround was load-bearing in at least #499, #511, #506, and #512. It's fragile (litters the worktree, can race the build), and every future fix agent had to re-discover it. This PR makes the helper match where cargo actually puts the staticlib.

Repro before / after

In any worktree with .cargo/config.toml redirecting build.target-dir:

Before:

$ rm -f target/release/libilo.a
$ cargo test --release --features cranelift --lib compile_cranelift::tests::aot_compile_simple_multiply
...
thread '...' panicked at: cannot find libilo.a, build with `cargo build --release --features cranelift` first.

After (this worktree's target/release/libilo.a does not exist):

$ ls target/release/libilo.a
ls: target/release/libilo.a: No such file or directory
$ cargo test --release --features cranelift --lib compile_cranelift
...
test result: ok. 163 passed; 0 failed; 0 ignored

No symlink. The lookup reads .cargo/config.toml, finds target-dir = "/tmp/ilo-targets/ilo-fix-aot-lookup", and links from there.

What is in the diff

One commit (1c8fc33d):

  • find_libilo_a probes in order: CARGO_TARGET_DIR env var, build.target-dir from $CARGO_MANIFEST_DIR/.cargo/config.toml, $CARGO_MANIFEST_DIR/target, workspace parent target/. Each step tries release then debug.
  • Helpers extracted: cargo_config_target_dir (ad-hoc TOML parser, no new dep, looks only for target-dir = "..." inside [build]), libilo_a_in (probe one target dir).
  • Unit tests for both helpers: double-quoted and single-quoted values, ignoring target-dir outside [build], missing-file behaviour, release-over-debug preference, debug fallback, no-match returns None.
  • CHANGELOG entry under Unreleased > Changed.

The end-to-end integration test is the existing aot_compile_* suite plus tests/coverage_cranelift_compile.rs. This very worktree exercises the new lookup path: it redirects target-dir to /tmp/ilo-targets/ilo-fix-aot-lookup and links successfully without any symlink. I deliberately did not write a unit test that mutates CARGO_TARGET_DIR directly, because that would race other tests sharing the process; the helper-level tests plus the end-to-end suite cover it cleanly.

Test plan

  • cargo build --release --features cranelift clean
  • cargo test --release --features cranelift --lib compile_cranelift passes (163 tests, includes the new helper tests and all AOT tests)
  • cargo test --release --features cranelift full suite passes (50 test binaries, 0 failed)
  • cargo fmt --check clean
  • cargo clippy --release --features cranelift --all-targets -- -D warnings clean
  • Verified target/release/libilo.a does not exist in this worktree, AOT tests still link from /tmp/ilo-targets/ilo-fix-aot-lookup/release/libilo.a

Follow-ups

  • None. Closes pending.md #5av.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 20 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/vm/compile_cranelift.rs 84.61% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

The AOT linker helper hard-coded $CARGO_MANIFEST_DIR/target/{release,debug}
as the libilo.a search path. Fix worktrees that redirect cargo's target dir
out of the tree (typical: [build] target-dir = "/tmp/ilo-targets/<name>")
ended up with the staticlib at the redirected path while the lookup kept
probing target/, so every aot_compile_* test failed with "cannot find
libilo.a" and each PR carried a ln -sf symlink workaround.

Probe order now:
  1. CARGO_TARGET_DIR env var
  2. build.target-dir in $CARGO_MANIFEST_DIR/.cargo/config.toml
  3. $CARGO_MANIFEST_DIR/target
  4. workspace parent target/

Each step tries release then debug. Ad-hoc TOML parser, no new dep:
target-dir = "..." inside [build] is the only line we care about.

Unit tests cover the parser (double quotes, single quotes, ignoring other
sections, missing file) and the probe helper (release-over-debug
preference, debug fallback, no-match). The end-to-end integration is the
existing aot_compile_* suite itself: this very worktree redirects its
target dir, so a passing `cargo test --release --features cranelift`
without a symlink is the regression test.
@danieljohnmorris danieljohnmorris force-pushed the fix/aot-target-dir-lookup branch from 1c8fc33 to bbc36df Compare May 21, 2026 08:14
@danieljohnmorris danieljohnmorris merged commit 8dc1cdf into main May 21, 2026
4 of 5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/aot-target-dir-lookup branch May 21, 2026 08:27
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