@@ -123,7 +123,7 @@ def VerifyStage0JsonHash():
123
123
sys .exit (1 )
124
124
125
125
126
- def Configure (llvm_libs_root ):
126
+ def Configure (llvm_bins_path , llvm_libs_root ):
127
127
# Read the config.toml template file...
128
128
with open (RUST_CONFIG_TEMPLATE_PATH , 'r' ) as input :
129
129
template = string .Template (input .read ())
@@ -134,15 +134,15 @@ def quote_string(s: str):
134
134
subs = {}
135
135
subs ['INSTALL_DIR' ] = quote_string (str (RUST_TOOLCHAIN_OUT_DIR ))
136
136
subs ['LLVM_LIB_ROOT' ] = quote_string (str (llvm_libs_root ))
137
- subs ['LLVM_BIN' ] = quote_string (str (os . path . join ( LLVM_BUILD_DIR , 'bin' ) ))
137
+ subs ['LLVM_BIN' ] = quote_string (str (llvm_bins_path ))
138
138
subs ['PACKAGE_VERSION' ] = GetPackageVersionForBuild ()
139
139
140
140
# ...and apply substitutions, writing to config.toml in Rust tree.
141
141
with open (os .path .join (RUST_SRC_DIR , 'config.toml' ), 'w' ) as output :
142
142
output .write (template .substitute (subs ))
143
143
144
144
145
- def RunXPy (sub , args , zlib_path , libxml2_dirs , build_mac_arm ,
145
+ def RunXPy (sub , args , llvm_bins_path , zlib_path , libxml2_dirs , build_mac_arm ,
146
146
gcc_toolchain_path , verbose ):
147
147
''' Run x.py, Rust's build script'''
148
148
# We append to these flags, make sure they exist.
@@ -158,45 +158,32 @@ def RunXPy(sub, args, zlib_path, libxml2_dirs, build_mac_arm,
158
158
for f in ENV_FLAGS :
159
159
RUSTENV .setdefault (f , '' )
160
160
161
- # The TARGET is consumed by the cc crate for building C/C++ sources, the
162
- # CARGO_BUILD_TARGET is used for building Rust sources.
163
- if sys .platform == 'win32' :
164
- RUSTENV ['TARGET' ] = 'x86_64-pc-windows-msvc'
165
- RUSTENV ['CARGO_BUILD_TARGET' ] = 'x86_64-pc-windows-msvc'
166
- elif sys .platform == 'darwin' :
167
- if build_mac_arm or platform .machine () == 'arm64' :
168
- RUSTENV ['TARGET' ] = 'arm64-apple-darwin'
169
- RUSTENV ['CARGO_BUILD_TARGET' ] = 'arm64-apple-darwin'
170
- else :
171
- RUSTENV ['TARGET' ] = 'amd64-apple-darwin'
172
- RUSTENV ['CARGO_BUILD_TARGET' ] = 'amd64-apple-darwin'
173
- else :
174
- RUSTENV ['TARGET' ] = 'x86_64-unknown-linux-gnu'
175
- RUSTENV ['CARGO_BUILD_TARGET' ] = 'x86_64-unknown-linux-gnu'
176
-
177
161
# The AR, CC, CXX flags control the C/C++ compiler used through the `cc`
178
162
# crate. There are also C/C++ targets that are part of the Rust toolchain
179
163
# build for which the tool is controlled from `config.toml`, so these must
180
164
# be duplicated there.
181
165
182
- clang_bin = os .path .join (LLVM_BUILD_DIR , 'bin' )
183
166
if sys .platform == 'win32' :
184
- RUSTENV ['AR' ] = os .path .join (clang_bin , 'llvm-lib.exe' )
185
- RUSTENV ['CC' ] = os .path .join (clang_bin , 'clang-cl.exe' )
186
- RUSTENV ['CXX' ] = os .path .join (clang_bin , 'clang-cl.exe' )
167
+ RUSTENV ['AR' ] = os .path .join (llvm_bins_path , 'llvm-lib.exe' )
168
+ RUSTENV ['CC' ] = os .path .join (llvm_bins_path , 'clang-cl.exe' )
169
+ RUSTENV ['CXX' ] = os .path .join (llvm_bins_path , 'clang-cl.exe' )
187
170
else :
188
- RUSTENV ['AR' ] = os .path .join (clang_bin , 'llvm-ar' )
189
- RUSTENV ['CC' ] = os .path .join (clang_bin , 'clang' )
190
- RUSTENV ['CXX' ] = os .path .join (clang_bin , 'clang++' )
171
+ RUSTENV ['AR' ] = os .path .join (llvm_bins_path , 'llvm-ar' )
172
+ RUSTENV ['CC' ] = os .path .join (llvm_bins_path , 'clang' )
173
+ RUSTENV ['CXX' ] = os .path .join (llvm_bins_path , 'clang++' )
191
174
192
- if RUSTENV [ 'CARGO_BUILD_TARGET' ]. endswith ( 'apple- darwin') :
193
- # The system/xcode compiler would find system headers correctly, but
175
+ if sys . platform == ' darwin' :
176
+ # The system/xcode compiler would find system SDK correctly, but
194
177
# the Clang we've built does not. See
195
178
# https://github.com/llvm/llvm-project/issues/45225
196
179
sdk_path = subprocess .check_output (['xcrun' , '--show-sdk-path' ],
197
180
text = True ).rstrip ()
198
181
RUSTENV ['CFLAGS' ] += f' -isysroot { sdk_path } '
199
182
RUSTENV ['CXXFLAGS' ] += f' -isysroot { sdk_path } '
183
+ RUSTENV ['LDFLAGS' ] += f' -isysroot { sdk_path } '
184
+ RUSTENV ['RUSTFLAGS_BOOTSTRAP' ] += (f' -Clink-arg=-isysroot { sdk_path } ' )
185
+ RUSTENV ['RUSTFLAGS_NOT_BOOTSTRAP' ] += (
186
+ f' -Clink-arg=-isysroot { sdk_path } ' )
200
187
201
188
if zlib_path :
202
189
RUSTENV ['CFLAGS' ] += f' -I{ zlib_path } '
@@ -236,6 +223,10 @@ def RunXPy(sub, args, zlib_path, libxml2_dirs, build_mac_arm,
236
223
# Cargo normally stores files in $HOME. Override this.
237
224
RUSTENV ['CARGO_HOME' ] = CARGO_HOME_DIR
238
225
226
+ # This enables the compiler to produce Mac ARM binaries.
227
+ if build_mac_arm :
228
+ args .extend (['--target' , 'aarch64-apple-darwin' ])
229
+
239
230
os .chdir (RUST_SRC_DIR )
240
231
cmd = [sys .executable , 'x.py' , sub ]
241
232
if verbose and verbose > 0 :
@@ -324,6 +315,15 @@ def main():
324
315
else :
325
316
llvm_libs_root = build .LLVM_BOOTSTRAP_DIR
326
317
318
+ # If we're building for Mac ARM on an x86_64 Mac, we can't use the final
319
+ # clang binaries as they don't have x86_64 support. Building them with that
320
+ # support would blow up their size a lot. So, we use the bootstrap binaries
321
+ # until such time as the Mac ARM builder becomes an actual Mac ARM machine.
322
+ if not args .build_mac_arm :
323
+ llvm_bins_path = os .path .join (LLVM_BUILD_DIR , 'bin' )
324
+ else :
325
+ llvm_bins_path = os .path .join (build .LLVM_BOOTSTRAP_DIR , 'bin' )
326
+
327
327
VerifyStage0JsonHash ()
328
328
if args .verify_stage0_hash :
329
329
# The above function exits and prints the actual hash if verification
@@ -342,7 +342,7 @@ def main():
342
342
build .MaybeDownloadHostGcc (args )
343
343
344
344
# Set up config.toml in Rust source tree to configure build.
345
- Configure (llvm_libs_root )
345
+ Configure (llvm_bins_path , llvm_libs_root )
346
346
347
347
AddCMakeToPath ()
348
348
@@ -366,21 +366,21 @@ def main():
366
366
if args .run_xpy :
367
367
if rest [0 ] == '--' :
368
368
rest = rest [1 :]
369
- RunXPy (rest [0 ], rest [1 :], zlib_path , libxml2_dirs , args . build_mac_arm ,
370
- args .gcc_toolchain , args .verbose )
369
+ RunXPy (rest [0 ], rest [1 :], llvm_bins_path , zlib_path , libxml2_dirs ,
370
+ args .build_mac_arm , args . gcc_toolchain , args .verbose )
371
371
return 0
372
372
else :
373
373
assert not rest
374
374
375
375
if not args .skip_clean :
376
376
print ('Cleaning build artifacts...' )
377
- RunXPy ('clean' , [], zlib_path , libxml2_dirs , args . build_mac_arm ,
378
- args .gcc_toolchain , args .verbose )
377
+ RunXPy ('clean' , [], llvm_bins_path , zlib_path , libxml2_dirs ,
378
+ args .build_mac_arm , args . gcc_toolchain , args .verbose )
379
379
380
380
if not args .skip_test :
381
381
print ('Running stage 2 tests...' )
382
382
# Run a subset of tests. Tell x.py to keep the rustc we already built.
383
- RunXPy ('test' , GetTestArgs (), zlib_path , libxml2_dirs ,
383
+ RunXPy ('test' , GetTestArgs (), llvm_bins_path , zlib_path , libxml2_dirs ,
384
384
args .build_mac_arm , args .gcc_toolchain , args .verbose )
385
385
386
386
targets = [
@@ -391,8 +391,8 @@ def main():
391
391
# Build stage 2 compiler, tools, and libraries. This should reuse earlier
392
392
# stages from the test command (if run).
393
393
print ('Building stage 2 artifacts...' )
394
- RunXPy ('build' , ['--stage' , '2' ] + targets , zlib_path , libxml2_dirs ,
395
- args .build_mac_arm , args .gcc_toolchain , args .verbose )
394
+ RunXPy ('build' , ['--stage' , '2' ] + targets , llvm_bins_path , zlib_path ,
395
+ libxml2_dirs , args .build_mac_arm , args .gcc_toolchain , args .verbose )
396
396
397
397
if args .skip_install :
398
398
# Rust is fully built. We can quit.
@@ -403,8 +403,8 @@ def main():
403
403
if os .path .exists (RUST_TOOLCHAIN_OUT_DIR ):
404
404
shutil .rmtree (RUST_TOOLCHAIN_OUT_DIR )
405
405
406
- RunXPy ('install' , DISTRIBUTION_ARTIFACTS , zlib_path , libxml2_dirs ,
407
- args .gcc_toolchain , args .verbose )
406
+ RunXPy ('install' , DISTRIBUTION_ARTIFACTS , llvm_bins_path , zlib_path ,
407
+ libxml2_dirs , args .gcc_toolchain , args .verbose )
408
408
409
409
with open (VERSION_STAMP_PATH , 'w' ) as stamp :
410
410
stamp .write (GetVersionStamp ())
0 commit comments