@@ -2012,14 +2012,52 @@ impl Step for Assemble {
2012
2012
if builder. config . llvm_enabled ( target_compiler. host ) {
2013
2013
trace ! ( "target_compiler.host" = ?target_compiler. host, "LLVM enabled" ) ;
2014
2014
2015
- let llvm :: LlvmResult { host_llvm_config , .. } =
2016
- builder. ensure ( llvm:: Llvm { target : target_compiler . host } ) ;
2015
+ let target = target_compiler . host ;
2016
+ let llvm :: LlvmResult { host_llvm_config , .. } = builder. ensure ( llvm:: Llvm { target } ) ;
2017
2017
if !builder. config . dry_run ( ) && builder. config . llvm_tools_enabled {
2018
2018
trace ! ( "LLVM tools enabled" ) ;
2019
2019
2020
- let llvm_bin_dir =
2021
- command ( host_llvm_config) . arg ( "--bindir" ) . run_capture_stdout ( builder) . stdout ( ) ;
2022
- let llvm_bin_dir = Path :: new ( llvm_bin_dir. trim ( ) ) ;
2020
+ let host_llvm_bin_dir = command ( & host_llvm_config)
2021
+ . arg ( "--bindir" )
2022
+ . run_capture_stdout ( builder)
2023
+ . stdout ( )
2024
+ . trim ( )
2025
+ . to_string ( ) ;
2026
+
2027
+ let llvm_bin_dir = if target == builder. host_target {
2028
+ PathBuf :: from ( host_llvm_bin_dir)
2029
+ } else {
2030
+ // If we're cross-compiling, we cannot run the target llvm-config in order to
2031
+ // figure out where binaries are located. We thus have to guess.
2032
+ let external_llvm_config = builder
2033
+ . config
2034
+ . target_config
2035
+ . get ( & target)
2036
+ . and_then ( |t| t. llvm_config . clone ( ) ) ;
2037
+ if let Some ( external_llvm_config) = external_llvm_config {
2038
+ // If we have an external LLVM, just hope that the bindir is the directory
2039
+ // where the LLVM config is located
2040
+ external_llvm_config. parent ( ) . unwrap ( ) . to_path_buf ( )
2041
+ } else {
2042
+ // If we have built LLVM locally, then take the path of the host bindir
2043
+ // relative to its output build directory, and then apply it to the target
2044
+ // LLVM output build directory.
2045
+ let host_llvm_out = builder. llvm_out ( builder. host_target ) ;
2046
+ let target_llvm_out = builder. llvm_out ( target) ;
2047
+ if let Ok ( relative_path) =
2048
+ Path :: new ( & host_llvm_bin_dir) . strip_prefix ( host_llvm_out)
2049
+ {
2050
+ target_llvm_out. join ( relative_path)
2051
+ } else {
2052
+ // This is the most desperate option, just replace the host target with
2053
+ // the actual target in the directory path...
2054
+ PathBuf :: from (
2055
+ host_llvm_bin_dir
2056
+ . replace ( & * builder. host_target . triple , & target. triple ) ,
2057
+ )
2058
+ }
2059
+ }
2060
+ } ;
2023
2061
2024
2062
// Since we've already built the LLVM tools, install them to the sysroot.
2025
2063
// This is the equivalent of installing the `llvm-tools-preview` component via
0 commit comments