From 61b647e89a3e8b1bccb9de1242354f92373d60da Mon Sep 17 00:00:00 2001 From: Bonan Zhu Date: Tue, 15 Mar 2022 21:29:15 +0000 Subject: [PATCH] Allow certain denpendencies to be excluded for sysimg It is possible for a package to depend on more than it needs at runtime, for eaxmple, to allow switching backends. In some cases, it is desirable to exclude certain dependencies to avoid downloading or shipping with shipping artifacts that are not needed for an app. --- src/PackageCompiler.jl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 8c83d3c5..748b666c 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -391,6 +391,9 @@ compiler (can also include extra arguments to the compiler, like `-g`). transitive dependencies into the sysimage. This only makes a difference if some packages do not load all their dependencies when themselves are loaded. Defaults to `true`. +- `excluded_dependencies`: A Vector of names of the (tansitive) dependencies to be excluded + from the system image. + ### Advanced keyword arguments - `base_sysimage::Union{Nothing, String}`: If a `String`, names an existing sysimage upon which to build @@ -416,6 +419,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector script::Union{Nothing, String}=nothing, sysimage_build_args::Cmd=``, include_transitive_dependencies::Bool=true, + excluded_transitive_dependencies::Union{Nothing, Vector{String}}=nothing, # Internal args base_sysimage::Union{Nothing, String}=nothing, julia_init_c_file=nothing, @@ -490,7 +494,10 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector end pkgid_deps = [Base.PkgId(uuid, name) for (name, uuid) in deps] for pkgid_dep in pkgid_deps - if !(pkgid_dep in packages_sysimg) # + if !(pkgid_dep in packages_sysimg) # + if excluded_transitive_dependencies !== nothing && (pkgid_dep.name in excluded_transitive_dependencies) + continue + end push!(packages_sysimg, pkgid_dep) push!(new_frontier, pkgid_dep) end @@ -685,7 +692,9 @@ function create_app(package_dir::String, cpu_target::String=default_app_cpu_target(), include_lazy_artifacts::Bool=false, sysimage_build_args::Cmd=``, - include_transitive_dependencies::Bool=true) + include_transitive_dependencies::Bool=true, + excluded_transitive_dependencies::Union{Nothing, Vector{String}}=nothing, + ) warn_official() ctx = create_pkg_context(package_dir) @@ -723,6 +732,7 @@ function create_app(package_dir::String, cpu_target, sysimage_build_args, include_transitive_dependencies, + excluded_transitive_dependencies, extra_precompiles = join(precompiles, "\n")) for (app_name, julia_main) in executables