3
3
# Julia compiler wrapper script
4
4
# NOTE: The interface and location of this script are considered unstable/experimental
5
5
6
+ using LazyArtifacts
7
+
6
8
module JuliaConfig
7
- include (joinpath (@__DIR__ , " julia-config.jl" ))
9
+ include (joinpath (@__DIR__ , " .. " , " julia-config.jl" ))
8
10
end
9
11
10
12
julia_cmd = ` $(Base. julia_cmd ()) --startup-file=no --history-file=no`
@@ -30,6 +32,57 @@ if help !== nothing
30
32
exit (0 )
31
33
end
32
34
35
+ # Copied from PackageCompiler
36
+ # https://github.com/JuliaLang/PackageCompiler.jl/blob/1c35331d8ef81494f054bbc71214811253101993/src/PackageCompiler.jl#L147-L190
37
+ function get_compiler_cmd (; cplusplus:: Bool = false )
38
+ cc = get (ENV , " JULIA_CC" , nothing )
39
+ path = nothing
40
+ @static if Sys. iswindows ()
41
+ path = joinpath (LazyArtifacts. artifact " mingw-w64" ,
42
+ " extracted_files" ,
43
+ (Int== Int64 ? " mingw64" : " mingw32" ),
44
+ " bin" ,
45
+ cplusplus ? " g++.exe" : " gcc.exe" )
46
+ compiler_cmd = ` $path `
47
+ end
48
+ if cc != = nothing
49
+ compiler_cmd = Cmd (Base. shell_split (cc))
50
+ path = nothing
51
+ elseif ! Sys. iswindows ()
52
+ compilers_cpp = (" g++" , " clang++" )
53
+ compilers_c = (" gcc" , " clang" )
54
+ found_compiler = false
55
+ if cplusplus
56
+ for compiler in compilers_cpp
57
+ if Sys. which (compiler) != = nothing
58
+ compiler_cmd = ` $compiler `
59
+ found_compiler = true
60
+ break
61
+ end
62
+ end
63
+ end
64
+ if ! found_compiler
65
+ for compiler in compilers_c
66
+ if Sys. which (compiler) != = nothing
67
+ compiler_cmd = ` $compiler `
68
+ found_compiler = true
69
+ if cplusplus && ! WARNED_CPP_COMPILER[]
70
+ @warn " could not find a c++ compiler (g++ or clang++), falling back to $compiler , this might cause link errors"
71
+ WARNED_CPP_COMPILER[] = true
72
+ end
73
+ break
74
+ end
75
+ end
76
+ end
77
+ found_compiler || error (" could not find a compiler, looked for " ,
78
+ join (((cplusplus ? compilers_cpp : ()). .. , compilers_c... ), " , " , " and " ))
79
+ end
80
+ if path != = nothing
81
+ compiler_cmd = addenv (compiler_cmd, " PATH" => string (ENV [" PATH" ], " ;" , dirname (path)))
82
+ end
83
+ return compiler_cmd
84
+ end
85
+
33
86
# arguments to forward to julia compilation process
34
87
julia_args = []
35
88
enable_trim:: Bool = false
@@ -82,6 +135,7 @@ function get_rpath(; relative::Bool = false)
82
135
end
83
136
end
84
137
138
+ cc = get_compiler_cmd ()
85
139
absfile = abspath (file)
86
140
cflags = JuliaConfig. cflags (; framework= false )
87
141
cflags = Base. shell_split (cflags)
@@ -93,7 +147,6 @@ tmpdir = mktempdir(cleanup=false)
93
147
img_path = joinpath (tmpdir, " img.a" )
94
148
bc_path = joinpath (tmpdir, " img-bc.a" )
95
149
96
-
97
150
function precompile_env ()
98
151
# Pre-compile the environment
99
152
# (otherwise obscure error messages will occur)
@@ -121,7 +174,6 @@ function compile_products(enable_trim::Bool)
121
174
println (stderr , " \n Failed to compile $file " )
122
175
exit (1 )
123
176
end
124
-
125
177
end
126
178
127
179
function link_products ()
@@ -137,11 +189,11 @@ function link_products()
137
189
julia_libs = Base. shell_split (Base. isdebugbuild () ? " -ljulia-debug -ljulia-internal-debug" : " -ljulia -ljulia-internal" )
138
190
try
139
191
if output_type == " --output-lib"
140
- cmd2 = ` cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
192
+ cmd2 = ` $(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
141
193
elseif output_type == " --output-sysimage"
142
- cmd2 = ` cc $(allflags) $(rpath) -o $outname -shared -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
194
+ cmd2 = ` $(cc) $(allflags) $(rpath) -o $outname -shared -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
143
195
else
144
- cmd2 = ` cc $(allflags) $(rpath) -o $outname -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
196
+ cmd2 = ` $(cc) $(allflags) $(rpath) -o $outname -Wl,$(Base. Linking. WHOLE_ARCHIVE) $img_path -Wl,$(Base. Linking. NO_WHOLE_ARCHIVE) $(julia_libs) `
145
197
end
146
198
verbose && println (" Running: $cmd2 " )
147
199
run (cmd2)
0 commit comments