#!/usr/bin/env julia1#2# Script to create a sysimage with all of Trixi.jl's dependencies and, optionally, Trixi.jl itself.3# Note: You need to have `OrdinaryDiffEq`, `Plots`, and `Trixi2Vtk` installed as packages in the4# general environment.5#6# After the sysimage has been generated, you can use it by starting Julia with7#8# julia --sysimage=path/to/new/sysimage9#10# Usage:11#12# julia build_sysimage.jl13# [TRIXI_SYSIMAGE_PATH=...] [TRIXI_SYSIMAGE_INCLUDE_TRIXI=...] julia build_sysimage.jl14#15# Optional environment variables:16#17# TRIXI_SYSIMAGE_PATH:18# Path where the resulting sysimage will be stored.19# (default: `TrixiSysimage.<ext>` where `<ext>` is `.so`, `.dylib`, or `.dll`)20#21# TRIXI_SYSIMAGE_INCLUDE_TRIXI:22# If "no", "1", or "false" (all case-insensitive), only Trixi.jl's direct dependencies +23# `OrdinaryDiffEq`, `Plots`, and `Trixi2Vtk` are stored in the sysimage. This is useful when24# doing development with Trixi.jl and only the startup time due to dependencies should be25# reduced. If "yes", "1", or "true" (all case-insensitive), `Trixi` itself is included. Note26# that in this case it is not possible to change existing functionality in Trixi.jl anymore27# (e.g., overwriting methods etc. will not work).28# (default: `no`)29#30# Examples:31#32# To include Trixi.jl in the sysimage that should be created as `Trixi.so`, execute this script as33# follows:34#35# TRIXI_SYSIMAGE_PATH=Trixi.so TRIXI_SYSIMAGE_INCLUDE_TRIXI=yes julia build_sysimage.jl36#37# Special thanks to the people at the CliMA project with the ClimateMachine.jl package38# (https://github.com/CliMA/ClimateMachine.jl), from which most of this code is inspired!3940using Pkg, Libdl4142@info "Creating sysimage for Trixi.jl..."43start_time = time()4445# Create a temporary environment to install all necessary packages without modifying46# the users environment47Pkg.activate(temp = true)4849# Add package compiler, Trixi.jl, and additional packages that shall be built into the sysimage50Pkg.add("PackageCompiler")51Pkg.add("Trixi")5253# Note that all packages built into a sysimage need to be in the current project as54# direct dependencies. Hence, we add direct dependencies of Trixi.jl as direct dependencies55# of the current temporary project if we do not want to bundle Trixi.jl into the sysimage.56packages = Symbol[:OrdinaryDiffEq, :Plots, :Trixi2Vtk]57if lowercase(get(ENV, "TRIXI_SYSIMAGE_INCLUDE_TRIXI", "no")) in ("yes", "1", "true")58# If Trixi.jl is to be included, just add it to the list59push!(packages, :Trixi)60else61# Otherwise, figure out all direct dependencies and add them instead62# Inspired by: https://github.com/CliMA/ClimateMachine.jl/blob/8c57fb55acc20ee824ea37478395a7cb07c5a93c/.dev/systemimage/climate_machine_image.jl63trixi_uuid = Base.UUID("a7f1ee26-1774-49b1-8366-f1abc58fbfcb")64append!(packages,65Symbol[Symbol(v) for v in keys(Pkg.dependencies()[trixi_uuid].dependencies)])66end6768map(Pkg.add ∘ string, packages)69Pkg.precompile()7071# Collect remaining arguments72sysimage_path = get(ENV, "TRIXI_SYSIMAGE_PATH",73joinpath(@__DIR__, "TrixiSysimage." * Libdl.dlext))74precompile_execution_file = joinpath(@__DIR__, "precompile_execution_file.jl")7576# Create system image77@info "Included packages: $packages"78@info "Sysimage path: $sysimage_path"79@info "Precompile execution file: $precompile_execution_file"8081using PackageCompiler82PackageCompiler.create_sysimage(packages,83sysimage_path = sysimage_path,84precompile_execution_file = precompile_execution_file,85cpu_target = PackageCompiler.default_app_cpu_target())8687duration = time() - start_time88@info "Done. Created sysimage in $duration seconds."899091