@@ -78,7 +78,29 @@ function compile_products(recipe::ImageRecipe)
7878 end
7979
8080 project_arg = recipe. project == " " ? Base. active_project () : recipe. project
81- env_overrides = Dict {String,Any} (" JULIA_LOAD_PATH" => nothing )
81+ env_overrides = Dict {String,Any} ()
82+ tmp_prefs_env = nothing
83+ if is_trim_enabled (recipe)
84+ # Create a temporary depot so packages are recompiled fresh with the trim preference
85+ load_path_sep = Sys. iswindows () ? " ;" : " :"
86+
87+ # Create a temporary environment with a LocalPreferences.toml that will be added to JULIA_LOAD_PATH.
88+ tmp_prefs_env = mktempdir ()
89+ # env_overrides["JULIA_DEPOT_PATH"] = tmp_prefs_env * load_path_sep
90+ open (joinpath (tmp_prefs_env, " Project.toml" ), " w" ) do io
91+ println (io, " [deps]" )
92+ println (io, " HostCPUFeatures = \" 3e5b6fbb-0976-4d2c-9146-d79de83f2fb0\" " )
93+ end
94+ # Write LocalPreferences.toml with the trim preferences
95+ open (joinpath (tmp_prefs_env, " LocalPreferences.toml" ), " w" ) do io
96+ println (io, " [HostCPUFeatures]" )
97+ println (io, " freeze_cpu_target = true" )
98+ end
99+ # Prepend the temp env to JULIA_LOAD_PATH
100+
101+ env_overrides[" JULIA_LOAD_PATH" ] = load_path_sep * tmp_prefs_env
102+ end
103+
82104 inst_cmd = addenv (` $(Base. julia_cmd (cpu_target= precompile_cpu_target)) --project=$project_arg -e "using Pkg; Pkg.instantiate(); Pkg.precompile()"` , env_overrides... )
83105 recipe. verbose && println (" Running: $inst_cmd " )
84106 precompile_time = time_ns ()
0 commit comments