Don't rely on Pkg being present in the juliac env#138
Open
asinghvi17 wants to merge 7 commits into
Open
Conversation
This way we rely on the stdlib lookup of Pkg (e.g. `julia -e 'using Pkg'` just works), and then activate the project in question.
asinghvi17
commented
May 12, 2026
asinghvi17
commented
May 12, 2026
Member
|
Seems like this should be handled with |
When JuliaC is invoked as a Pkg app, the Pkg-app shim points
JULIA_LOAD_PATH at JuliaC's own env so that JuliaC's deps resolve.
That env var is inherited by the Julia subprocess we spawn to run
`Pkg.instantiate(); Pkg.precompile()` on the user's project, which
leaks two ways:
1. `using Pkg` resolves via JuliaC's env (which today happens to
have Pkg as a direct dep — but we shouldn't have to rely on
that), and
2. the user's project is effectively shadowed by JuliaC's
manifest during precompile resolution.
Mirror the pattern PackageCompiler.jl uses (see PackageCompiler.jl
`ensurecompiled` / `run_precompilation_script`) and pin
JULIA_LOAD_PATH = "<user_project>:@stdlib"
(with the trim prefs env appended when applicable). The user's
project goes first so `using <UserDep>` resolves via its
Project/Manifest; `@stdlib` guarantees `using Pkg` resolves to the
bundled Pkg regardless of whether the user's project lists Pkg as a
direct dep. We still pass --project=\$project_arg so that
Pkg.instantiate() / Pkg.precompile() target the user's project via
Base.active_project().
Addresses topolarity's review on JuliaLang#138 to handle this with
JULIA_LOAD_PATH rather than by switching to Pkg.activate(ARGS).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
asinghvi17
commented
May 12, 2026
Member
|
Looks pretty reasonable |
Member
|
I am a bit confused. The leading $ JULIA_LOAD_PATH=":test" julia -e "println(Base.LOAD_PATH)"
["@", "@v#.#", "@stdlib", "test"]Are we inheriting a |
Author
|
Hm it could have been inherited from the running process, so maybe we should set it to nothing? |
Member
|
Yeah, that sounds reasonable to me I think Pkg app scripts set this: https://github.com/JuliaLang/Pkg.jl/blob/43dcd1fc05ef312f837e714a7f09b1b5616ae9f2/src/Apps/Apps.jl#L519-L520 |
…rocess When JuliaC is invoked as a Pkg app, the Pkg-app shim sets JULIA_LOAD_PATH to JuliaC's own env. That value gets inherited by the Julia subprocess we spawn for Pkg.instantiate/precompile, so the subprocess's LOAD_PATH becomes just JuliaC's env — no @stdlib, no @ — and `using Pkg` (along with anything else in startup.jl, like `using REPL`) fails unless JuliaC happens to list it as a direct dep. Per topolarity's review, set JULIA_LOAD_PATH => nothing in the env overrides so Julia falls back to its default load path. The leading `:` trick is preserved for the trim case, which appends the temp prefs env to the default. Verified locally by setting parent JULIA_LOAD_PATH=<juliac-env> and running compile_products on test/AppProject; previously crashed in the subprocess startup, now succeeds. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This way we rely on the stdlib lookup of Pkg (e.g.
julia -e 'using Pkg'just works), and then activate the project in question.