Skip to content

Commit 05a3345

Browse files
authored
Merge pull request #53 from lucatrv/add-sysimage-flag
Add "--sysimage" flag
2 parents 49fb929 + 98c4163 commit 05a3345

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
Helper script to build libraries and executables from Julia code.
44

55
```
6-
usage: juliac.jl [-v] [-q] [-c] [-C <target>] [-O {0,1,2,3}]
7-
[-g {0,1,2}] [--inline {yes|no}]
6+
usage: juliac.jl [-v] [-q] [-c] [-J <file>] [-C <target>]
7+
[-O {0,1,2,3}] [-g {0,1,2}] [--inline {yes|no}]
88
[--check-bounds {yes|no}] [--math-mode {ieee,fast}]
99
[--depwarn {yes|no|error}] [-o] [-s] [-e] [-j]
1010
[--version] [-h] juliaprog [cprog] [builddir]
1111
1212
positional arguments:
1313
juliaprog Julia program to compile
14-
cprog C program to compile (if not provided, a
14+
cprog C program to compile (required only when
15+
building an executable; if not provided a
1516
minimal standard program is used)
1617
builddir build directory, either absolute or relative
1718
to the Julia program directory (default:
@@ -21,6 +22,8 @@ optional arguments:
2122
-v, --verbose increase verbosity
2223
-q, --quiet suppress non-error messages
2324
-c, --clean delete builddir
25+
-J, --sysimage <file>
26+
start up with the given system image file
2427
-C, --cpu-target <target>
2528
limit usage of CPU features up to <target>
2629
-O, --optimize {0,1,2,3}

juliac.jl

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function main(args)
1919
"cprog"
2020
arg_type = String
2121
default = nothing
22-
help = "C program to compile (if not provided, a minimal standard program is used)"
22+
help = "C program to compile (required only when building an executable; if not provided a minimal standard program is used)"
2323
"builddir"
2424
arg_type = String
2525
default = "builddir"
@@ -33,6 +33,11 @@ function main(args)
3333
"--clean", "-c"
3434
action = :store_true
3535
help = "delete builddir"
36+
"--sysimage", "-J"
37+
arg_type = String
38+
default = nothing
39+
metavar = "<file>"
40+
help = "start up with the given system image file"
3641
"--cpu-target", "-C"
3742
arg_type = String
3843
default = nothing
@@ -111,6 +116,7 @@ function main(args)
111116
parsed_args["verbose"],
112117
parsed_args["quiet"],
113118
parsed_args["clean"],
119+
parsed_args["sysimage"],
114120
parsed_args["cpu-target"],
115121
parsed_args["optimize"],
116122
parsed_args["debug"],
@@ -125,8 +131,9 @@ function main(args)
125131
)
126132
end
127133

128-
function julia_compile(julia_program, c_program=nothing, build_dir="builddir", verbose=false, quiet=false, clean=false,
129-
cpu_target=nothing, optimize=nothing, debug=nothing, inline=nothing, check_bounds=nothing, math_mode=nothing, depwarn=nothing,
134+
function julia_compile(julia_program, c_program=nothing, build_dir="builddir", verbose=false, quiet=false,
135+
clean=false, sysimage = nothing, cpu_target=nothing, optimize=nothing, debug=nothing,
136+
inline=nothing, check_bounds=nothing, math_mode=nothing, depwarn=nothing,
130137
object=false, shared=false, executable=true, julialibs=true)
131138

132139
verbose && quiet && (verbose = false)
@@ -135,9 +142,11 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
135142
isfile(julia_program) || error("Cannot find file:\n \"$julia_program\"")
136143
quiet || println("Julia program file:\n \"$julia_program\"")
137144

138-
c_program = c_program == nothing ? joinpath(@__DIR__, "program.c") : abspath(c_program)
139-
isfile(c_program) || error("Cannot find file:\n \"$c_program\"")
140-
quiet || println("C program file:\n \"$c_program\"")
145+
if executable
146+
c_program = c_program == nothing ? joinpath(@__DIR__, "program.c") : abspath(c_program)
147+
isfile(c_program) || error("Cannot find file:\n \"$c_program\"")
148+
quiet || println("C program file:\n \"$c_program\"")
149+
end
141150

142151
cd(dirname(julia_program))
143152

@@ -176,14 +185,19 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
176185

177186
delete_object = false
178187
if object || shared || executable
179-
julia_cmd = `$(Base.julia_cmd()) --startup-file=no`
180-
cpu_target == nothing || splice!(julia_cmd.exec, 2, ["-C$cpu_target"])
188+
julia_cmd = `$(Base.julia_cmd())`
189+
if length(julia_cmd.exec) != 5 || !all(startswith.(julia_cmd.exec[2:5], ["-C", "-J", "--compile", "--depwarn"]))
190+
error("Unexpected format of \"Base.julia_cmd()\", you may be using an incompatible version of Julia")
191+
end
192+
sysimage == nothing || (julia_cmd.exec[3] = "-J$sysimage")
193+
push!(julia_cmd.exec, "--startup-file=no")
194+
cpu_target == nothing || (julia_cmd.exec[2] = "-C$cpu_target")
181195
optimize == nothing || push!(julia_cmd.exec, "-O$optimize")
182196
debug == nothing || push!(julia_cmd.exec, "-g$debug")
183197
inline == nothing || push!(julia_cmd.exec, "--inline=$inline")
184198
check_bounds == nothing || push!(julia_cmd.exec, "--check-bounds=$check_bounds")
185199
math_mode == nothing || push!(julia_cmd.exec, "--math-mode=$math_mode")
186-
depwarn == nothing || splice!(julia_cmd.exec, 5, ["--depwarn=$depwarn"])
200+
depwarn == nothing || (julia_cmd.exec[5] = "--depwarn=$depwarn")
187201
is_windows() && (julia_program = replace(julia_program, "\\", "\\\\"))
188202
expr = "
189203
VERSION >= v\"0.7+\" && Base.init_load_path($(repr(JULIA_HOME))) # initialize location of site-packages
@@ -192,7 +206,7 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
192206
include($(repr(julia_program))) # include \"julia_program\" file
193207
empty!(Base.LOAD_CACHE_PATH) # reset / remove build-system-relative paths"
194208
command = `$julia_cmd -e $expr`
195-
verbose && println("Populate \".ji\" local cache:\n $command")
209+
verbose && println("Build \".ji\" files local cache:\n $command")
196210
run(command)
197211
command = `$julia_cmd --output-o $o_file -e $expr`
198212
verbose && println("Build object file \"$o_file\":\n $command")

0 commit comments

Comments
 (0)