Skip to content

Commit

Permalink
add mechanism for configuring system image builds (#54387)
Browse files Browse the repository at this point in the history
This adds the option to pass a filename of configuration settings when
building the Core/compiler system image (from
`base/compiler/compiler.jl`). This makes it easier to build different
flavors of images, for example it can replace the hack that
PackageCompiler uses to edit the list of included stdlibs, and makes it
easy to change knobs you might want like max_methods.
  • Loading branch information
JeffBezanson authored Jun 26, 2024
1 parent 4e1fd72 commit db687ad
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 26 deletions.
26 changes: 23 additions & 3 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,28 @@ function strcat(x::String, y::String)
end
return out
end
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)

BUILDROOT::String = ""

baremodule BuildSettings
end

let i = 1
global BUILDROOT
while i <= length(Core.ARGS)
if Core.ARGS[i] == "--buildsettings"
include(BuildSettings, ARGS[i+1])
i += 1
else
BUILDROOT = Core.ARGS[i]
end
i += 1
end
end

include(strcat(BUILDROOT, "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
include(strcat(BUILDROOT, "version_git.jl")) # include($BUILDROOT/base/version_git.jl)

# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
# a slightly more verbose fashion than usual, because we're running so early.
const DL_LOAD_PATH = String[]
Expand Down Expand Up @@ -562,7 +582,7 @@ include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexp

# External libraries vendored into Base
Core.println("JuliaSyntax/src/JuliaSyntax.jl")
include(@__MODULE__, string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "JuliaSyntax/src/JuliaSyntax.jl")) # include($BUILDROOT/base/JuliaSyntax/JuliaSyntax.jl)
include(@__MODULE__, string(BUILDROOT, "JuliaSyntax/src/JuliaSyntax.jl")) # include($BUILDROOT/base/JuliaSyntax/JuliaSyntax.jl)

end_base_include = time_ns()

Expand Down
12 changes: 12 additions & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ something(x::Any, y...) = x
# compiler #
############

baremodule BuildSettings
using Core: ARGS, include
using Core.Compiler: >, getindex, length

MAX_METHODS::Int = 3
UNOPTIMIZE_THROW_BLOCKS::Bool = true

if length(ARGS) > 2 && ARGS[2] === "--buildsettings"
include(BuildSettings, ARGS[3])
end
end

if false
import Base: Base, @show
else
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ struct InferenceParams
end
function InferenceParams(
params::InferenceParams = InferenceParams( # default constructor
#=max_methods::Int=# 3,
#=max_methods::Int=# BuildSettings.MAX_METHODS,
#=max_union_splitting::Int=# 4,
#=max_apply_union_enum::Int=# 8,
#=max_tuple_splat::Int=# 32,
#=tuple_complexity_limit_depth::Int=# 3,
#=ipo_constant_propagation::Bool=# true,
#=aggressive_constant_propagation::Bool=# false,
#=unoptimize_throw_blocks::Bool=# true,
#=unoptimize_throw_blocks::Bool=# BuildSettings.UNOPTIMIZE_THROW_BLOCKS,
#=assume_bindings_static::Bool=# false,
#=ignore_recursion_hardlimit::Bool=# false);
max_methods::Int = params.max_methods,
Expand Down
2 changes: 1 addition & 1 deletion base/cpuid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Base.:<=(a::ISA, b::ISA) = a.features <= b.features
Base.:<(a::ISA, b::ISA) = a.features < b.features
Base.isless(a::ISA, b::ISA) = a < b

include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "features_h.jl")) # include($BUILDROOT/base/features_h.jl)
include(string(Base.BUILDROOT, "features_h.jl")) # include($BUILDROOT/base/features_h.jl)

# Keep in sync with `arch_march_isa_mapping`.
const ISAs_by_family = Dict(
Expand Down
2 changes: 1 addition & 1 deletion base/filesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ uv_fs_req_cleanup(req) = ccall(:uv_fs_req_cleanup, Cvoid, (Ptr{Cvoid},), req)
include("path.jl")
include("stat.jl")
include("file.jl")
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)
include(string(Base.BUILDROOT, "file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)

## Operations with File (fd) objects ##

Expand Down
2 changes: 1 addition & 1 deletion base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if Sys.iswindows()
export GetLastError, FormatMessage
end

include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)
include(string(Base.BUILDROOT, "errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)

## RawFD ##

Expand Down
2 changes: 1 addition & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Core definitions for interacting with the libuv library from Julia

include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)
include(string(Base.BUILDROOT, "uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)

# convert UV handle data to julia object, checking for null
function uv_sizeof_handle(handle)
Expand Down
2 changes: 1 addition & 1 deletion base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module PCRE
import ..RefValue

# include($BUILDROOT/base/pcre_h.jl)
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "pcre_h.jl"))
include(string(Base.BUILDROOT, "pcre_h.jl"))

const PCRE_LIB = "libpcre2-8"

Expand Down
40 changes: 24 additions & 16 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,29 @@ let

# Stdlibs sorted in dependency, then alphabetical, order by contrib/print_sorted_stdlibs.jl
# Run with the `--exclude-jlls` option to filter out all JLL packages
stdlibs = [
# No dependencies
:FileWatching, # used by loading.jl -- implicit assumption that init runs
:Libdl, # Transitive through LinAlg
:Artifacts, # Transitive through LinAlg
:SHA, # transitive through Random
:Sockets, # used by stream.jl

# Transitive through LingAlg
# OpenBLAS_jll
# libblastrampoline_jll

# 1-depth packages
:LinearAlgebra, # Commits type-piracy and GEMM
:Random, # Can't be removed due to rand being exported by Base
]
if isdefined(Base.BuildSettings, :INCLUDE_STDLIBS)
# e.g. INCLUDE_STDLIBS = "FileWatching,Libdl,Artifacts,SHA,Sockets,LinearAlgebra,Random"
stdlibs = Symbol.(split(Base.BuildSettings.INCLUDE_STDLIBS, ","))
else
# TODO: this is included for compatibility with PackageCompiler, which looks for it.
# This should eventually be removed so we only use `BuildSettings`.
stdlibs = [
# No dependencies
:FileWatching, # used by loading.jl -- implicit assumption that init runs
:Libdl, # Transitive through LinAlg
:Artifacts, # Transitive through LinAlg
:SHA, # transitive through Random
:Sockets, # used by stream.jl

# Transitive through LingAlg
# OpenBLAS_jll
# libblastrampoline_jll

# 1-depth packages
:LinearAlgebra, # Commits type-piracy and GEMM
:Random, # Can't be removed due to rand being exported by Base
]
end
# PackageCompiler can filter out stdlibs so it can be empty
maxlen = maximum(textwidth.(string.(stdlibs)); init=0)

Expand Down Expand Up @@ -139,6 +146,7 @@ end

empty!(Base.TOML_CACHE.d)
Base.TOML.reinit!(Base.TOML_CACHE.p, "")
@eval Base BUILDROOT = ""
@eval Sys begin
BINDIR = ""
STDLIB = ""
Expand Down

0 comments on commit db687ad

Please sign in to comment.