Skip to content

Re-apply JULIA_LOAD_PATH leakage fix when running as a Pkg app#145

Open
gbaraldi wants to merge 1 commit into
mainfrom
gb/fix-pkg-app-load-path-leakage
Open

Re-apply JULIA_LOAD_PATH leakage fix when running as a Pkg app#145
gbaraldi wants to merge 1 commit into
mainfrom
gb/fix-pkg-app-load-path-leakage

Conversation

@gbaraldi
Copy link
Copy Markdown
Member

Summary

Re-applies the fix from #127 (commit c3716ef, reverted in edd1e25) and fixes the test failure that prompted the revert. Closes #124, fixes #106.

When JuliaC is installed as a Pkg app, the generated shim exports JULIA_LOAD_PATH=<JuliaC project dir>. The compile subprocesses JuliaC spawns (Pkg.instantiate/Pkg.precompile and juliac-buildscript.jl) inherit it, locking the load path to JuliaC's own project and breaking the user project's precompilation: Missing source file for Base.PkgId(...).

3a17f5c (#59) originally fixed this with an unconditional JULIA_LOAD_PATH => nothing override; 6940a31 (#96) inadvertently regressed it by making the override conditional on is_trim_enabled.

Fix

  • Always clear JULIA_LOAD_PATH for the spawned subprocesses (restores 3a17f5c).
  • For --trim, inject HostCPUFeatures.freeze_cpu_target=true directly into the temp project copy's LocalPreferences.toml instead of constructing an ad-hoc env on JULIA_LOAD_PATH — separates environment isolation from preference injection.
  • Adds TOML (stdlib) to [deps]/[compat] for the preferences injection.

Why #127 was reverted, and what's different here

#127's regression test (Pkg app JULIA_LOAD_PATH isolation) simulated the shim by manually setting JULIA_LOAD_PATH=$ROOT/. That works in a dev checkout because the dev tree has a resolved Manifest.toml, but *Manifest*.toml is in this repo's .gitignore. When Julia's CI installs JuliaC via Pkg.add, no Manifest.toml ends up under $ROOT, so the simulation couldn't even load JuliaC's own deps in the subprocess and failed before exercising the fix.

This PR keeps both regression tests but reorganises them:

  • Project with dependencies (no trim) (#124) / (trim) (#124) — programmatic API tests, always on, would have caught "Missing source file" for direct dependencies introduced in v0.3.1 #124 before merge.
  • Pkg app end-to-end (#106) — uses Pkg.Apps.develop to install JuliaC and run its real shim against a user project (Unix only). Always on.
  • Pkg app JULIA_LOAD_PATH isolation (#106) — the simulated-shim variant, gated on JULIAC_TEST_PKG_APP_SHIM_SIM=1 with a hard precondition check on $ROOT/Manifest.toml. JuliaC's own CI sets the env var in .github/workflows/ci.yml; downstream consumers (like Julia's CI) won't run it.

Test plan

  • Reproduced "Missing source file" for direct dependencies introduced in v0.3.1 #124 on main with a minimal SHA-using project under JULIA_LOAD_PATH=$JC/
  • Verified the fix resolves the repro in both trim and no-trim paths
  • End-to-end check: Pkg.Apps.develop + invoke the generated shim → executable runs and prints expected output
  • Full Pkg.test() passes locally with JULIAC_TEST_PKG_APP_SHIM_SIM=1
  • CI on this PR

🤖 Generated with Claude Code

Re-applies the fix from #127 (commit c3716ef, reverted in edd1e25) and
addresses the test failure that prompted the revert.

When JuliaC is installed as a Pkg app, the generated shim exports
JULIA_LOAD_PATH=<JuliaC project dir>. The compile subprocesses JuliaC
spawns (Pkg.instantiate/Pkg.precompile and juliac-buildscript.jl)
inherit that env, locking the load path to JuliaC's project and
breaking precompilation of the user's project ("Missing source file
for Base.PkgId(...)" — #106, #124).

Fix: always clear JULIA_LOAD_PATH for the subprocesses (restoring
3a17f5c's behavior). Inject HostCPUFeatures trim preferences directly
into the temp project copy via LocalPreferences.toml so trim mode no
longer needs JULIA_LOAD_PATH manipulation.

Tests:
* New programmatic regression tests (Project with dependencies, with
  and without --trim) covering #124.
* New end-to-end test using Pkg.Apps.develop to install JuliaC and
  invoke its shim against a user project (Unix-only).
* The simulated-shim test (julia -m JuliaC with JULIA_LOAD_PATH set
  manually) is gated on JULIAC_TEST_PKG_APP_SHIM_SIM=1 — required
  because it depends on \$ROOT/Manifest.toml, which only exists in a
  dev checkout (Manifest.toml is gitignored). JuliaC's CI sets the env
  var; downstream consumers like Julia's CI that install JuliaC as a
  package will skip it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gbaraldi
Copy link
Copy Markdown
Member Author

Checked on upstream CI JuliaLang/julia#61840. And it no longer breaks

@gbaraldi gbaraldi requested a review from topolarity May 19, 2026 18:49
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.

"Missing source file" for direct dependencies introduced in v0.3.1 Regression in app usage

1 participant