Skip to content

Instantly share code, notes, and snippets.

@tkf
Last active February 24, 2019 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkf/bb020c3e2d64d049696c7e549f0120ad to your computer and use it in GitHub Desktop.
Save tkf/bb020c3e2d64d049696c7e549f0120ad to your computer and use it in GitHub Desktop.
#!/bin/bash
code_print_image_file="print(unsafe_string(Base.JLOptions().image_file))"
JULIA="${JULIA:-julia}"
IMAGE="$("$JULIA" -e "$code_print_image_file")"
OUTPUT_O=sys.a
OUTPUT_S=sys.so
set -ex
${JULIA} --output-o="$OUTPUT_O" \
-g1 --startup-file=no --code-coverage=none \
--history-file=yes --inline=yes --math-mode=ieee --handle-signals=yes \
--startup-file=no --warn-overwrite=no --compile=yes --depwarn=yes \
--cpu-target=native --track-allocation=none --sysimage-native-code=yes \
--sysimage="$IMAGE" \
--compiled-modules=yes --optimize=2 \
./precompile_wrapper.jl
${JULIA} --startup-file=no \
-e "
using PackageCompiler
s_file = \"$OUTPUT_S\"
o_file = \"$OUTPUT_O\"
init_shared = false
builddir = \"$PWD\"
verbose = true
optimize = \"3\"
debug = false
cc = PackageCompiler.system_compiler
cc_flags = nothing
PackageCompiler.build_shared(
s_file, o_file, init_shared, builddir, verbose, optimize,
debug, cc, cc_flags)
"
${JULIA} --startup-file=no --sysimage "$OUTPUT_S" -e "$code_print_image_file"
#!/bin/bash
JULIA="${JULIA:-julia}"
JULIA_PROJECT="${JULIA_PROJECT:-$PWD}"
export JULIA_PROJECT
set -ex
${JULIA} --startup-file=no -e "using Pkg; Pkg.instantiate(); using PyCall"
exec "$(dirname "${BASH_SOURCE[0]}")"/compile.bash
using MacroTools
isdefined(MacroTools, :__init__) && MacroTools.__init__()
# Put `println(MacroTools.@expand @time foo())` (say) in
# `PyCall.__init__` (say) and then comment out above. You'll get an
# exception below.
using PyCall
PyCall.__init__() # https://github.com/JuliaLang/julia/issues/22910
PyCall.pyimport("sys")[:executable]
atexit_hook_copy = copy(Base.atexit_hooks) # make backup
# clean state so that any package we use can carelessly call atexit
empty!(Base.atexit_hooks)
Base.__init__()
Sys.__init__() #fix https://github.com/JuliaLang/julia/issues/30479
using REPL
Base.REPL_MODULE_REF[] = REPL
M = Module()
# Include into anonymous module to not polute namespace
@eval(M, (Base.include($M, $(joinpath(@__DIR__, "precompile.jl")))))
Base._atexit() # run all exit hooks we registered during precompile
empty!(Base.atexit_hooks) # don't serialize the exit hooks we run + added
# atexit_hook_copy should be empty, but who knows what base will do in the future
append!(Base.atexit_hooks, atexit_hook_copy)
[deps]
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment