@@ -479,10 +479,29 @@ impl Step for Lld {
479
479
let llvm_config_shim = env:: current_exe ( ) . unwrap ( ) . with_file_name ( "llvm-config-wrapper" ) ;
480
480
cfg. out_dir ( & out_dir)
481
481
. profile ( "Release" )
482
- . env ( "LLVM_CONFIG_REAL" , llvm_config)
482
+ . env ( "LLVM_CONFIG_REAL" , & llvm_config)
483
483
. define ( "LLVM_CONFIG_PATH" , llvm_config_shim)
484
484
. define ( "LLVM_INCLUDE_TESTS" , "OFF" ) ;
485
485
486
+ // While we're using this horrible workaround to shim the execution of
487
+ // llvm-config, let's just pile on more. I can't seem to figure out how
488
+ // to build LLD as a standalone project and also cross-compile it at the
489
+ // same time. It wants a natively executable `llvm-config` to learn
490
+ // about LLVM, but then it learns about all the host configuration of
491
+ // LLVM and tries to link to host LLVM libraries.
492
+ //
493
+ // To work around that we tell our shim to replace anything with the
494
+ // build target with the actual target instead. This'll break parts of
495
+ // LLD though which try to execute host tools, such as llvm-tblgen, so
496
+ // we specifically tell it where to find those. This is likely super
497
+ // brittle and will break over time. If anyone knows better how to
498
+ // cross-compile LLD it would be much appreciated to fix this!
499
+ if target != builder. config . build {
500
+ cfg. env ( "LLVM_CONFIG_SHIM_REPLACE" , & builder. config . build )
501
+ . env ( "LLVM_CONFIG_SHIM_REPLACE_WITH" , & target)
502
+ . define ( "LLVM_TABLEGEN_EXE" , llvm_config. with_file_name ( "llvm-tblgen" ) ) ;
503
+ }
504
+
486
505
cfg. build ( ) ;
487
506
488
507
t ! ( File :: create( & done_stamp) ) ;
0 commit comments