3535function build_shared_lib (
3636 library, library_name;
3737 verbose = false , quiet = false ,
38- cpu_target = " native " , optimize = nothing , debug = nothing ,
38+ cpu_target = nothing , optimize = nothing , debug = nothing ,
3939 inline = nothing , check_bounds = nothing , math_mode = nothing
4040 )
4141 julia_compile (
@@ -53,13 +53,66 @@ function build_shared_lib(
5353 )
5454end
5555
56+ """
57+ build_executable(
58+ library,
59+ library_name = splitext(basename(library))[1],
60+ cprogram = joinpath(@__DIR__, "..", "examples", "program.c");
61+
62+ snoopfile = nothing, builddir = "build",
63+ verbose = false, quiet = false,
64+ cpu_target = nothing, optimize = nothing, debug = nothing,
65+ inline = nothing, check_bounds = nothing, math_mode = nothing
66+ )
67+
68+ `library` needs to be a julia file containing a julia main, e.g. like examples/hello.jl
69+ `snoopfile` is optional and can be julia file that calls functions that you want to make sure to have precompiled
70+ `builddir` is where library_name.exe and shared libraries will end up
71+ """
72+ function build_executable (
73+ library,
74+ library_name = splitext (basename (library))[1 ],
75+ cprogram = joinpath (@__DIR__ , " .." , " examples" , " program.c" );
76+
77+ snoopfile = nothing , builddir = " build" ,
78+ verbose = false , quiet = false ,
79+ cpu_target = nothing , optimize = nothing , debug = nothing ,
80+ inline = nothing , check_bounds = nothing , math_mode = nothing
81+ )
82+ if snoopfile != nothing
83+ precompfile = joinpath (builddir, " precompiled.jl" )
84+ snoop (snoopfile, precompfile, joinpath (builddir, " snoop.csv" ))
85+ jlmain = joinpath (builddir, " julia_main.jl" )
86+ open (jlmain, " w" ) do io
87+ println (io, " include(\" $(escape_string (precompfile)) \" )" )
88+ println (io, " include(\" $(escape_string (library)) \" )" )
89+ end
90+ library = jlmain
91+ end
92+ julia_compile (
93+
94+ library, julia_program_basename = library_name,
95+
96+ cpu_target = cpu_target, optimize = optimize,
97+ debug = debug, inline = inline, check_bounds = check_bounds,
98+ math_mode = math_mode, verbose = verbose, quiet = quiet,
99+
100+ cprog = cprogram, builddir = builddir,
101+ clean = false , sysimage = nothing ,
102+ compile = nothing , depwarn = nothing , autodeps = false ,
103+ object = true , shared = true , executable = true , julialibs = true ,
104+ )
105+ end
106+
56107
57108"""
109+ build_native_image()
58110Builds a clean system image, similar to a fresh Julia install.
59111Can also be used to build a native system image for a downloaded cross compiled julia binary.
60112"""
61- function build_native_image (debug = false )
113+ function build_native_image (debug = false ) # debug is ignored right now
62114 backup = sysimgbackup_folder ()
115+ # Build in backup dir, so we have a clean backup!
63116 compile_system_image (joinpath (backup, " sys" ), " native" )
64117 copy_system_image (backup, default_sysimg_path (debug))
65118end
0 commit comments