Add --trim-mode (compile-time) preference #31 (fixed) #65
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.
Title: Add compile-time
_trim_enabledpreference during--trimprecompilationSummary
When building with
--trim, some packages need to know at precompile time that trimming is enabled so they can register / specialize code accordingly (see SciML/LinearSolve.jl#778). This PR ensures a compile-time preference_trim_enabledis visible to packages during thePkg.instantiate(); Pkg.precompile()step invoked by JuliaC when trimming is requested.What I changed
src/compiling.jlBehavior
ImageRecipehas trimming enabled (i.e.recipe.trim_mode !== nothing && recipe.trim_mode != "no"), the precompile subprocess will:config/LocalPreferences.tomlcontaining:Pkg.instantiate(); Pkg.precompile()withJULIA_DEPOT_PATHpointed to the temporary depot soPreferences.load_preference(Preferences, "_trim_enabled")will returntruefor packages during precompilation.Why this approach
LocalPreferences.tomlhack so packages can call:Preferences.load_preference(Preferences, "_trim_enabled")and see a compile-time flag during precompilation.
Files edited
src/compiling.jl— add logic to create temporary depot, writeLocalPreferences.toml, setJULIA_DEPOT_PATHfor the precompile subprocess, and cleanup afterward.Testing & verification
julia --project -e "using Pkg; Pkg.test()"— all tests passed locally on Windows.Preferences.load_preference(Preferences, "_trim_enabled")in a top-level file and checks the behavior during thePkg.precompile()invoked by the compile pipeline.Caveats & notes
Preferences.jland readingLocalPreferences.tomlviaPreferences.load_preference. Packages that obtain preferences from other sources will not be affected.Pkg.instantiate(); Pkg.precompile()subprocess and is removed afterwards; user's depot is not modified.How to try locally
Run the existing test-suite (this was used to validate the change):
julia --project -e "using Pkg; Pkg.test()"