Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/utils/build_sysimage.jl
2055 views
1
#!/usr/bin/env julia
2
#
3
# Script to create a sysimage with all of Trixi.jl's dependencies and, optionally, Trixi.jl itself.
4
# Note: You need to have `OrdinaryDiffEq`, `Plots`, and `Trixi2Vtk` installed as packages in the
5
# general environment.
6
#
7
# After the sysimage has been generated, you can use it by starting Julia with
8
#
9
# julia --sysimage=path/to/new/sysimage
10
#
11
# Usage:
12
#
13
# julia build_sysimage.jl
14
# [TRIXI_SYSIMAGE_PATH=...] [TRIXI_SYSIMAGE_INCLUDE_TRIXI=...] julia build_sysimage.jl
15
#
16
# Optional environment variables:
17
#
18
# TRIXI_SYSIMAGE_PATH:
19
# Path where the resulting sysimage will be stored.
20
# (default: `TrixiSysimage.<ext>` where `<ext>` is `.so`, `.dylib`, or `.dll`)
21
#
22
# TRIXI_SYSIMAGE_INCLUDE_TRIXI:
23
# If "no", "1", or "false" (all case-insensitive), only Trixi.jl's direct dependencies +
24
# `OrdinaryDiffEq`, `Plots`, and `Trixi2Vtk` are stored in the sysimage. This is useful when
25
# doing development with Trixi.jl and only the startup time due to dependencies should be
26
# reduced. If "yes", "1", or "true" (all case-insensitive), `Trixi` itself is included. Note
27
# that in this case it is not possible to change existing functionality in Trixi.jl anymore
28
# (e.g., overwriting methods etc. will not work).
29
# (default: `no`)
30
#
31
# Examples:
32
#
33
# To include Trixi.jl in the sysimage that should be created as `Trixi.so`, execute this script as
34
# follows:
35
#
36
# TRIXI_SYSIMAGE_PATH=Trixi.so TRIXI_SYSIMAGE_INCLUDE_TRIXI=yes julia build_sysimage.jl
37
#
38
# Special thanks to the people at the CliMA project with the ClimateMachine.jl package
39
# (https://github.com/CliMA/ClimateMachine.jl), from which most of this code is inspired!
40
41
using Pkg, Libdl
42
43
@info "Creating sysimage for Trixi.jl..."
44
start_time = time()
45
46
# Create a temporary environment to install all necessary packages without modifying
47
# the users environment
48
Pkg.activate(temp = true)
49
50
# Add package compiler, Trixi.jl, and additional packages that shall be built into the sysimage
51
Pkg.add("PackageCompiler")
52
Pkg.add("Trixi")
53
54
# Note that all packages built into a sysimage need to be in the current project as
55
# direct dependencies. Hence, we add direct dependencies of Trixi.jl as direct dependencies
56
# of the current temporary project if we do not want to bundle Trixi.jl into the sysimage.
57
packages = Symbol[:OrdinaryDiffEq, :Plots, :Trixi2Vtk]
58
if lowercase(get(ENV, "TRIXI_SYSIMAGE_INCLUDE_TRIXI", "no")) in ("yes", "1", "true")
59
# If Trixi.jl is to be included, just add it to the list
60
push!(packages, :Trixi)
61
else
62
# Otherwise, figure out all direct dependencies and add them instead
63
# Inspired by: https://github.com/CliMA/ClimateMachine.jl/blob/8c57fb55acc20ee824ea37478395a7cb07c5a93c/.dev/systemimage/climate_machine_image.jl
64
trixi_uuid = Base.UUID("a7f1ee26-1774-49b1-8366-f1abc58fbfcb")
65
append!(packages,
66
Symbol[Symbol(v) for v in keys(Pkg.dependencies()[trixi_uuid].dependencies)])
67
end
68
69
map(Pkg.add string, packages)
70
Pkg.precompile()
71
72
# Collect remaining arguments
73
sysimage_path = get(ENV, "TRIXI_SYSIMAGE_PATH",
74
joinpath(@__DIR__, "TrixiSysimage." * Libdl.dlext))
75
precompile_execution_file = joinpath(@__DIR__, "precompile_execution_file.jl")
76
77
# Create system image
78
@info "Included packages: $packages"
79
@info "Sysimage path: $sysimage_path"
80
@info "Precompile execution file: $precompile_execution_file"
81
82
using PackageCompiler
83
PackageCompiler.create_sysimage(packages,
84
sysimage_path = sysimage_path,
85
precompile_execution_file = precompile_execution_file,
86
cpu_target = PackageCompiler.default_app_cpu_target())
87
88
duration = time() - start_time
89
@info "Done. Created sysimage in $duration seconds."
90
91