3
3
4
4
# Build a system image binary at sysimg_path.dlext. Allow insertion of a userimg via
5
5
# userimg_path. If sysimg_path.dlext is currently loaded into memory, don't continue
6
- # unless force is set to true. Allow targeting of a CPU architecture via cpu_target.
6
+ # unless force is set to true. Allow targeting of a CPU architecture via cpu_target.
7
7
function default_sysimg_path (debug= false )
8
8
if Sys. isunix ()
9
9
splitext (Libdl. dlpath (debug ? " sys-debug" : " sys" ))[1 ]
@@ -47,7 +47,7 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
47
47
base_dir = dirname (Base. find_source_file (" sysimg.jl" ))
48
48
cd (base_dir) do
49
49
julia = joinpath (JULIA_HOME, debug ? " julia-debug" : " julia" )
50
- cc = find_system_compiler ()
50
+ cc, warn_msg = find_system_compiler ()
51
51
52
52
# Ensure we have write-permissions to wherever we're trying to write to
53
53
try
@@ -64,7 +64,7 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
64
64
error (" $userimg_path is not found, ensure it is an absolute path." )
65
65
end
66
66
if isfile (" userimg.jl" )
67
- error (" $base_dir / userimg.jl already exists, delete manually to continue." )
67
+ error (" $( joinpath ( base_dir, " userimg.jl" )) already exists, delete manually to continue." )
68
68
end
69
69
cp (userimg_path, " userimg.jl" )
70
70
end
@@ -82,12 +82,14 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
82
82
83
83
if cc != = nothing
84
84
link_sysimg (sysimg_path, cc, debug)
85
+ ! isempty (warn_msg) && foreach (warn, warn_msg)
85
86
else
87
+ ! isempty (warn_msg) && foreach (warn, warn_msg)
86
88
info (" System image successfully built at $sysimg_path .ji." )
87
89
end
88
90
89
91
if ! Base. samefile (" $(default_sysimg_path (debug)) .ji" , " $sysimg_path .ji" )
90
- if Base . isfile (" $sysimg_path .$(Libdl. dlext) " )
92
+ if isfile (" $sysimg_path .$(Libdl. dlext) " )
91
93
info (" To run Julia with this image loaded, run: `julia -J $sysimg_path .$(Libdl. dlext) `." )
92
94
else
93
95
info (" To run Julia with this image loaded, run: `julia -J $sysimg_path .ji`." )
@@ -104,14 +106,10 @@ function build_sysimg(sysimg_path=nothing, cpu_target="native", userimg_path=not
104
106
end
105
107
end
106
108
107
- # Search for a compiler to link sys.o into sys.dl_ext. Honor LD environment variable.
109
+ # Search for a compiler to link sys.o into sys.dl_ext. Honor LD environment variable.
108
110
function find_system_compiler ()
109
- if haskey (ENV , " CC" )
110
- if ! success (` $(ENV [" CC" ]) -v` )
111
- warn (" Using compiler override $(ENV [" CC" ]) , but unable to run `$(ENV [" CC" ]) -v`." )
112
- end
113
- return ENV [" CC" ]
114
- end
111
+ cc = nothing
112
+ warn_msg = String[] # save warning messages into an array
115
113
116
114
# On Windows, check to see if WinRPM is installed, and if so, see if gcc is installed
117
115
if Sys. iswindows ()
@@ -120,24 +118,34 @@ function find_system_compiler()
120
118
winrpmgcc = joinpath (WinRPM. installdir, " usr" , " $(Sys. ARCH) -w64-mingw32" ,
121
119
" sys-root" , " mingw" , " bin" , " gcc.exe" )
122
120
if success (` $winrpmgcc --version` )
123
- return winrpmgcc
121
+ cc = winrpmgcc
124
122
else
125
123
throw ()
126
124
end
127
125
catch
128
- warn ( " Install GCC via `Pkg.add(\" WinRPM\" ); WinRPM.install(\" gcc\" )` to generate sys.dll for faster startup times." )
126
+ push! (warn_msg, " Install GCC via `Pkg.add(\" WinRPM\" ); WinRPM.install(\" gcc\" )` to generate sys.dll for faster startup times." )
129
127
end
130
128
end
131
129
130
+ if haskey (ENV , " CC" )
131
+ if ! success (` $(ENV [" CC" ]) -v` )
132
+ push! (warn_msg, " Using compiler override $(ENV [" CC" ]) , but unable to run `$(ENV [" CC" ]) -v`." )
133
+ end
134
+ cc = ENV [" CC" ]
135
+ end
132
136
133
137
# See if `cc` exists
134
138
try
135
139
if success (` cc -v` )
136
- return " cc"
140
+ cc = " cc"
137
141
end
138
142
end
139
143
140
- warn (" No supported compiler found; startup times will be longer." )
144
+ if cc === nothing
145
+ push! (warn_msg, " No supported compiler found; startup times will be longer." )
146
+ end
147
+
148
+ return cc, warn_msg
141
149
end
142
150
143
151
# Link sys.o into sys.$(dlext)
@@ -168,11 +176,11 @@ function link_sysimg(sysimg_path=nothing, cc=find_system_compiler(), debug=false
168
176
run (` $cc $FLAGS -o $sysimg_file $sysimg_path .o` )
169
177
end
170
178
info (" System image successfully built at $sysimg_path .$(Libdl. dlext) " )
179
+ return
171
180
end
172
181
173
- # When running this file as a script, try to do so with default values. If arguments are passed
182
+ # When running this file as a script, try to do so with default values. If arguments are passed
174
183
# in, use them as the arguments to build_sysimg above.
175
- #
176
184
# Also check whether we are running `genstdlib.jl`, in which case we don't want to build a
177
185
# system image and instead only need `build_sysimg`'s docstring to be available.
178
186
if ! isdefined (Main, :GenStdLib ) && ! isinteractive ()
0 commit comments