Skip to content

Commit 0e12921

Browse files
committed
Add Julia compilation flags
1 parent 6849019 commit 0e12921

File tree

2 files changed

+91
-18
lines changed

2 files changed

+91
-18
lines changed

README.md

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

55
```
6-
usage: juliac.jl [-v] [-q] [-c] [-o] [-s] [-e] [-j] [--version] [-h]
7-
juliaprog [cprog] [builddir]
6+
usage: juliac.jl [-v] [-q] [-c] [-C <target>] [-O {0,1,2,3}]
7+
[-g {0,1,2}] [--inline {yes|no}]
8+
[--check-bounds {yes|no}] [--math-mode {ieee,fast}]
9+
[--depwarn {yes|no|error}] [-o] [-s] [-e] [-j]
10+
[--version] [-h] juliaprog [cprog] [builddir]
811
912
positional arguments:
10-
juliaprog Julia program to compile
11-
cprog C program to compile (if not provided, a minimal
12-
standard program is used)
13-
builddir build directory, either absolute or relative to
14-
the Julia program directory (default: "builddir")
13+
juliaprog Julia program to compile
14+
cprog C program to compile (if not provided, a
15+
minimal standard program is used)
16+
builddir build directory, either absolute or relative
17+
to the Julia program directory (default:
18+
"builddir")
1519
1620
optional arguments:
17-
-v, --verbose increase verbosity
18-
-q, --quiet suppress non-error messages
19-
-c, --clean delete builddir
20-
-o, --object build object file
21-
-s, --shared build shared library
22-
-e, --executable build executable file
23-
-j, --julialibs sync Julia libraries to builddir
24-
--version show version information and exit
25-
-h, --help show this help message and exit
21+
-v, --verbose increase verbosity
22+
-q, --quiet suppress non-error messages
23+
-c, --clean delete builddir
24+
-C, --cpu-target <target>
25+
limit usage of CPU features up to <target>
26+
-O, --optimize {0,1,2,3}
27+
set optimization level (type: Int64)
28+
-g {0,1,2} set debugging information level (type: Int64)
29+
--inline {yes|no} control whether inlining is permitted
30+
--check-bounds {yes|no}
31+
emit bounds checks always or never
32+
--math-mode {ieee,fast}
33+
set floating point optimizations
34+
--depwarn {yes|no|error}
35+
set syntax and method deprecation warnings
36+
-o, --object build object file
37+
-s, --shared build shared library
38+
-e, --executable build executable file
39+
-j, --julialibs sync Julia libraries to builddir
40+
--version show version information and exit
41+
-h, --help show this help message and exit
2642
2743
examples:
2844
juliac.jl -ve hello.jl # verbose, build executable

juliac.jl

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,48 @@ function main(args)
3333
"--clean", "-c"
3434
action = :store_true
3535
help = "delete builddir"
36+
"--cpu-target", "-C"
37+
arg_type = String
38+
default = nothing
39+
metavar = "<target>"
40+
help = "limit usage of CPU features up to <target>"
41+
"--optimize", "-O"
42+
arg_type = Int
43+
default = nothing
44+
range_tester = (x -> 0 <= x <= 3)
45+
metavar = "{0,1,2,3}"
46+
help = "set optimization level"
47+
"-g"
48+
arg_type = Int
49+
default = nothing
50+
range_tester = (x -> 0 <= x <= 2)
51+
dest_name = "debug"
52+
metavar = "{0,1,2}"
53+
help = "set debugging information level"
54+
"--inline"
55+
arg_type = String
56+
default = nothing
57+
range_tester = (x -> x == "yes" || x == "no")
58+
metavar = "{yes|no}"
59+
help = "control whether inlining is permitted"
60+
"--check-bounds"
61+
arg_type = String
62+
default = nothing
63+
range_tester = (x -> x == "yes" || x == "no")
64+
metavar = "{yes|no}"
65+
help = "emit bounds checks always or never"
66+
"--math-mode"
67+
arg_type = String
68+
default = nothing
69+
range_tester = (x -> x == "ieee" || x == "fast")
70+
metavar = "{ieee,fast}"
71+
help = "set floating point optimizations"
72+
"--depwarn"
73+
arg_type = String
74+
default = nothing
75+
range_tester = (x -> x == "yes" || x == "no" || x == "error")
76+
metavar = "{yes|no|error}"
77+
help = "set syntax and method deprecation warnings"
3678
"--object", "-o"
3779
action = :store_true
3880
help = "build object file"
@@ -69,15 +111,23 @@ function main(args)
69111
parsed_args["verbose"],
70112
parsed_args["quiet"],
71113
parsed_args["clean"],
114+
parsed_args["cpu-target"],
115+
parsed_args["optimize"],
116+
parsed_args["debug"],
117+
parsed_args["inline"],
118+
parsed_args["check-bounds"],
119+
parsed_args["math-mode"],
120+
parsed_args["depwarn"],
72121
parsed_args["object"],
73122
parsed_args["shared"],
74123
parsed_args["executable"],
75124
parsed_args["julialibs"]
76125
)
77126
end
78127

79-
function julia_compile(julia_program, c_program=nothing, build_dir="builddir", verbose=false, quiet=false,
80-
clean=false, object=false, shared=false, executable=true, julialibs=true)
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,
130+
object=false, shared=false, executable=true, julialibs=true)
81131

82132
verbose && quiet && (verbose = false)
83133

@@ -127,6 +177,13 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
127177
delete_object = false
128178
if object || shared || executable
129179
julia_cmd = `$(Base.julia_cmd()) --startup-file=no`
180+
cpu_target == nothing || splice!(julia_cmd.exec, 2, ["-C$cpu_target"])
181+
optimize == nothing || push!(julia_cmd.exec, "-O$optimize")
182+
debug == nothing || push!(julia_cmd.exec, "-g$debug")
183+
inline == nothing || push!(julia_cmd.exec, "--inline=$inline")
184+
check_bounds == nothing || push!(julia_cmd.exec, "--check-bounds=$check_bounds")
185+
math_mode == nothing || push!(julia_cmd.exec, "--math-mode=$math_mode")
186+
depwarn == nothing || splice!(julia_cmd.exec, 5, ["--depwarn=$depwarn"])
130187
is_windows() && (julia_program = replace(julia_program, "\\", "\\\\"))
131188
expr = "
132189
VERSION >= v\"0.7+\" && Base.init_load_path($(repr(JULIA_HOME))) # initialize location of site-packages

0 commit comments

Comments
 (0)