|
1 | | -using PackageCompiler, ArgParse |
2 | | - |
3 | | -Base.@ccallable function julia_main(args::Vector{String})::Cint |
4 | | - |
5 | | - s = ArgParseSettings("Static Julia Compiler", |
6 | | - version = "$(basename(@__FILE__)) version 0.7-DEV", |
7 | | - add_version = true) |
8 | | - |
9 | | - @add_arg_table s begin |
10 | | - "juliaprog" |
11 | | - arg_type = String |
12 | | - required = true |
13 | | - help = "Julia program to compile" |
14 | | - "cprog" |
15 | | - arg_type = String |
16 | | - default = nothing |
17 | | - help = "C program to compile (required only when building an executable; if not provided a minimal driver program is used)" |
18 | | - "builddir" |
19 | | - arg_type = String |
20 | | - default = "builddir" |
21 | | - help = "build directory, either absolute or relative to the Julia program directory" |
22 | | - "--verbose", "-v" |
23 | | - action = :store_true |
24 | | - help = "increase verbosity" |
25 | | - "--quiet", "-q" |
26 | | - action = :store_true |
27 | | - help = "suppress non-error messages" |
28 | | - "--clean", "-c" |
29 | | - action = :store_true |
30 | | - help = "delete builddir" |
31 | | - "--sysimage", "-J" |
32 | | - arg_type = String |
33 | | - default = nothing |
34 | | - metavar = "<file>" |
35 | | - help = "start up with the given system image file" |
36 | | - "--compile" |
37 | | - arg_type = String |
38 | | - default = nothing |
39 | | - metavar = "{yes|no|all|min}" |
40 | | - range_tester = (x -> x == "yes" || x == "no" || x == "all" || x == "min") |
41 | | - help = "enable or disable JIT compiler, or request exhaustive compilation" |
42 | | - "--cpu-target", "-C" |
43 | | - arg_type = String |
44 | | - default = nothing |
45 | | - metavar = "<target>" |
46 | | - help = "limit usage of CPU features up to <target>" |
47 | | - "--optimize", "-O" |
48 | | - arg_type = Int |
49 | | - default = nothing |
50 | | - metavar = "{0,1,2,3}" |
51 | | - range_tester = (x -> 0 <= x <= 3) |
52 | | - help = "set optimization level" |
53 | | - "-g" |
54 | | - arg_type = Int |
55 | | - default = nothing |
56 | | - dest_name = "debug" |
57 | | - metavar = "{0,1,2}" |
58 | | - range_tester = (x -> 0 <= x <= 2) |
59 | | - help = "set debugging information level" |
60 | | - "--inline" |
61 | | - arg_type = String |
62 | | - default = nothing |
63 | | - metavar = "{yes|no}" |
64 | | - range_tester = (x -> x == "yes" || x == "no") |
65 | | - help = "control whether inlining is permitted" |
66 | | - "--check-bounds" |
67 | | - arg_type = String |
68 | | - default = nothing |
69 | | - metavar = "{yes|no}" |
70 | | - range_tester = (x -> x == "yes" || x == "no") |
71 | | - help = "emit bounds checks always or never" |
72 | | - "--math-mode" |
73 | | - arg_type = String |
74 | | - default = nothing |
75 | | - metavar = "{ieee,fast}" |
76 | | - range_tester = (x -> x == "ieee" || x == "fast") |
77 | | - help = "set floating point optimizations" |
78 | | - "--depwarn" |
79 | | - arg_type = String |
80 | | - default = nothing |
81 | | - metavar = "{yes|no|error}" |
82 | | - range_tester = (x -> x == "yes" || x == "no" || x == "error") |
83 | | - help = "set syntax and method deprecation warnings" |
84 | | - "--autodeps", "-a" |
85 | | - action = :store_true |
86 | | - help = "automatically build required dependencies" |
87 | | - "--object", "-o" |
88 | | - action = :store_true |
89 | | - help = "build object file" |
90 | | - "--shared", "-s" |
91 | | - action = :store_true |
92 | | - help = "build shared library" |
93 | | - "--executable", "-e" |
94 | | - action = :store_true |
95 | | - help = "build executable file" |
96 | | - "--julialibs", "-j" |
97 | | - action = :store_true |
98 | | - help = "sync Julia libraries to builddir" |
99 | | - end |
100 | | - |
101 | | - s.epilog = """ |
102 | | - examples:\n |
103 | | - \ua0\ua0juliac.jl -vae hello.jl # verbose, build executable and deps\n |
104 | | - \ua0\ua0juliac.jl -vae hello.jl prog.c # embed into user defined C program\n |
105 | | - \ua0\ua0juliac.jl -qo hello.jl # quiet, build object file only\n |
106 | | - \ua0\ua0juliac.jl -vosej hello.jl # build all and sync Julia libs\n |
107 | | - """ |
108 | | - |
109 | | - parsed_args = parse_args(args, s) |
110 | | - |
111 | | - # TODO: in future it may be possible to broadcast dictionary indexing, see: https://discourse.julialang.org/t/accessing-multiple-values-of-a-dictionary/8648 |
112 | | - if !any(getindex.(parsed_args, ["clean", "object", "shared", "executable", "julialibs"])) |
113 | | - parsed_args["quiet"] || println("Nothing to do, exiting\nTry \"$(basename(@__FILE__)) -h\" for more information") |
114 | | - exit(0) |
115 | | - end |
116 | | - |
117 | | - kw_args = map(parsed_args) do kv |
118 | | - Symbol(replace(kv[1], "-", "_")) => kv[2] |
119 | | - end |
120 | | - kw_args = filter((k, v)-> k != :juliaprog, kw_args) |
121 | | - PackageCompiler.julia_compile( |
122 | | - parsed_args["juliaprog"]; |
123 | | - kw_args... |
124 | | - ) |
125 | | -end |
126 | | - |
127 | | -if get(ENV, "COMPILE_STATIC", "false") == "false" |
128 | | - julia_main(ARGS) |
129 | | -end |
| 1 | +using PackageCompiler, ArgParse |
| 2 | + |
| 3 | +Base.@ccallable function julia_main(args::Vector{String})::Cint |
| 4 | + |
| 5 | + s = ArgParseSettings("Static Julia Compiler", |
| 6 | + version = "$(basename(@__FILE__)) version 0.7-DEV", |
| 7 | + add_version = true) |
| 8 | + |
| 9 | + @add_arg_table s begin |
| 10 | + "juliaprog" |
| 11 | + arg_type = String |
| 12 | + required = true |
| 13 | + help = "Julia program to compile" |
| 14 | + "cprog" |
| 15 | + arg_type = String |
| 16 | + default = nothing |
| 17 | + help = "C program to compile (required only when building an executable; if not provided a minimal driver program is used)" |
| 18 | + "builddir" |
| 19 | + arg_type = String |
| 20 | + default = "builddir" |
| 21 | + help = "build directory, either absolute or relative to the Julia program directory" |
| 22 | + "--verbose", "-v" |
| 23 | + action = :store_true |
| 24 | + help = "increase verbosity" |
| 25 | + "--quiet", "-q" |
| 26 | + action = :store_true |
| 27 | + help = "suppress non-error messages" |
| 28 | + "--clean", "-c" |
| 29 | + action = :store_true |
| 30 | + help = "delete builddir" |
| 31 | + "--sysimage", "-J" |
| 32 | + arg_type = String |
| 33 | + default = nothing |
| 34 | + metavar = "<file>" |
| 35 | + help = "start up with the given system image file" |
| 36 | + "--compile" |
| 37 | + arg_type = String |
| 38 | + default = nothing |
| 39 | + metavar = "{yes|no|all|min}" |
| 40 | + range_tester = (x -> x == "yes" || x == "no" || x == "all" || x == "min") |
| 41 | + help = "enable or disable JIT compiler, or request exhaustive compilation" |
| 42 | + "--cpu-target", "-C" |
| 43 | + arg_type = String |
| 44 | + default = nothing |
| 45 | + metavar = "<target>" |
| 46 | + help = "limit usage of CPU features up to <target>" |
| 47 | + "--optimize", "-O" |
| 48 | + arg_type = Int |
| 49 | + default = nothing |
| 50 | + metavar = "{0,1,2,3}" |
| 51 | + range_tester = (x -> 0 <= x <= 3) |
| 52 | + help = "set optimization level" |
| 53 | + "-g" |
| 54 | + arg_type = Int |
| 55 | + default = nothing |
| 56 | + dest_name = "debug" |
| 57 | + metavar = "{0,1,2}" |
| 58 | + range_tester = (x -> 0 <= x <= 2) |
| 59 | + help = "set debugging information level" |
| 60 | + "--inline" |
| 61 | + arg_type = String |
| 62 | + default = nothing |
| 63 | + metavar = "{yes|no}" |
| 64 | + range_tester = (x -> x == "yes" || x == "no") |
| 65 | + help = "control whether inlining is permitted" |
| 66 | + "--check-bounds" |
| 67 | + arg_type = String |
| 68 | + default = nothing |
| 69 | + metavar = "{yes|no}" |
| 70 | + range_tester = (x -> x == "yes" || x == "no") |
| 71 | + help = "emit bounds checks always or never" |
| 72 | + "--math-mode" |
| 73 | + arg_type = String |
| 74 | + default = nothing |
| 75 | + metavar = "{ieee,fast}" |
| 76 | + range_tester = (x -> x == "ieee" || x == "fast") |
| 77 | + help = "set floating point optimizations" |
| 78 | + "--depwarn" |
| 79 | + arg_type = String |
| 80 | + default = nothing |
| 81 | + metavar = "{yes|no|error}" |
| 82 | + range_tester = (x -> x == "yes" || x == "no" || x == "error") |
| 83 | + help = "set syntax and method deprecation warnings" |
| 84 | + "--autodeps", "-a" |
| 85 | + action = :store_true |
| 86 | + help = "automatically build required dependencies" |
| 87 | + "--object", "-o" |
| 88 | + action = :store_true |
| 89 | + help = "build object file" |
| 90 | + "--shared", "-s" |
| 91 | + action = :store_true |
| 92 | + help = "build shared library" |
| 93 | + "--executable", "-e" |
| 94 | + action = :store_true |
| 95 | + help = "build executable file" |
| 96 | + "--julialibs", "-j" |
| 97 | + action = :store_true |
| 98 | + help = "sync Julia libraries to builddir" |
| 99 | + end |
| 100 | + |
| 101 | + s.epilog = """ |
| 102 | + examples:\n |
| 103 | + \ua0\ua0juliac.jl -vae hello.jl # verbose, build executable and deps\n |
| 104 | + \ua0\ua0juliac.jl -vae hello.jl prog.c # embed into user defined C program\n |
| 105 | + \ua0\ua0juliac.jl -qo hello.jl # quiet, build object file only\n |
| 106 | + \ua0\ua0juliac.jl -vosej hello.jl # build all and sync Julia libs\n |
| 107 | + """ |
| 108 | + |
| 109 | + parsed_args = parse_args(args, s) |
| 110 | + |
| 111 | + # TODO: in future it may be possible to broadcast dictionary indexing, see: https://discourse.julialang.org/t/accessing-multiple-values-of-a-dictionary/8648 |
| 112 | + if !any(getindex.(parsed_args, ["clean", "object", "shared", "executable", "julialibs"])) |
| 113 | + parsed_args["quiet"] || println("Nothing to do, exiting\nTry \"$(basename(@__FILE__)) -h\" for more information") |
| 114 | + exit(0) |
| 115 | + end |
| 116 | + |
| 117 | + kw_args = map(parsed_args) do kv |
| 118 | + Symbol(replace(kv[1], "-", "_")) => kv[2] |
| 119 | + end |
| 120 | + kw_args = filter((k, v)-> k != :juliaprog, kw_args) |
| 121 | + PackageCompiler.julia_compile( |
| 122 | + parsed_args["juliaprog"]; |
| 123 | + kw_args... |
| 124 | + ) |
| 125 | +end |
| 126 | + |
| 127 | +if get(ENV, "COMPILE_STATIC", "false") == "false" |
| 128 | + julia_main(ARGS) |
| 129 | +end |
0 commit comments