Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add excluded_packages keyword argument for create_sysimage #791

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/sysimages.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,7 @@ in your current project.

- When creating a sysimage incrementally, you can use a different sysimage as the "base sysimage" by passing the `base_sysimage` keyword argument.
- The "cpu target" can be specified with the `cpu_target` keyword. For more information about the syntax of this option, see the [Julia manual](https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets).
- If you need to run some code in the process creating the sysimage, the `script` argument that points to a file can be passed.
- If you need to run some code in the process creating the sysimage, the `script` argument that points to a file can be passed.
- To exclude certain packages in the sysimage, the `excluded_packages` keyword can be used to pass their names. This option can be useful when one want to compile a sysimage for package development where the dependences contain *heavy* packages with long load times (can be found using `@time_imports using MyDevPackage` in Julia >= 1.8).
In this case, building a system image including the dependencies can significantly reduce the load times of the package in development.
As an example, one can create a system image with `MyDevPackage` included in the `packages` keyword argument with `include_transitive_dependencies=true` to ensure its dependencies are included while excluding `MyDevPackage` itself.
9 changes: 9 additions & 0 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).

- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
for example `-O1 --check-bounds=yes`.

- `excluded_packages::Union{Vector{String}, Vector{Symbol}}`: Names of the packages to
be excluded in the sysimge.
"""
function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector{Symbol}}=nothing;
sysimage_path::String,
Expand All @@ -483,6 +486,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
cpu_target::String=NATIVE_CPU_TARGET,
script::Union{Nothing, String}=nothing,
sysimage_build_args::Cmd=``,
excluded_packages::Union{Vector{String}, Vector{Symbol}}=String[],
include_transitive_dependencies::Bool=true,
# Internal args
base_sysimage::Union{Nothing, String}=nothing,
Expand Down Expand Up @@ -510,6 +514,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
end

packages = string.(vcat(packages))
excluded_packages = string.(vcat(excluded_packages))
precompile_execution_file = vcat(precompile_execution_file)
precompile_statements_file = vcat(precompile_statements_file)

Expand Down Expand Up @@ -572,6 +577,10 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
end
end

# Exclude requested packages
packages = filter(x -> !(x in excluded_packages), packages)
packages_sysimg = filter(x -> !(x.name in excluded_packages), packages_sysimg)

# Create the sysimage
object_file = tempname() * ".o"

Expand Down