Skip to content

Commit ef3c98e

Browse files
committed
Add preference for HostCPUFeatures so that it can be loaded/used
1 parent 6bd9793 commit ef3c98e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/compiling.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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()

test/TrimmabilityProject/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ uuid = "a1b2c3d4-5678-90ab-cdef-1234567890ab"
33
version = "0.1.0"
44

55
[deps]
6+
HostCPUFeatures = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0"
67
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
8+
9+
[compat]
10+
HostCPUFeatures = "0.1.18"

test/TrimmabilityProject/src/TrimmabilityProject.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Test that various constructs support trimming
22
module TrimmabilityProject
33

4+
using HostCPUFeatures
45
using Sockets
56

67
world::String = "world!"

0 commit comments

Comments
 (0)