@@ -804,6 +804,12 @@ impl Step for Lld {
804804 let target = self . target ;
805805
806806 let llvm_config = builder. ensure ( Llvm { target : self . target } ) ;
807+ let mut llvm_cmake_dir = llvm_config;
808+ llvm_cmake_dir. pop ( ) ;
809+ llvm_cmake_dir. pop ( ) ;
810+ llvm_cmake_dir. push ( "lib" ) ;
811+ llvm_cmake_dir. push ( "cmake" ) ;
812+ llvm_cmake_dir. push ( "llvm" ) ;
807813
808814 let out_dir = builder. lld_out ( target) ;
809815 let done_stamp = out_dir. join ( "lld-finished-building" ) ;
@@ -834,22 +840,6 @@ impl Step for Lld {
834840 configure_cmake ( builder, target, & mut cfg, true , ldflags) ;
835841 configure_llvm ( builder, target, & mut cfg) ;
836842
837- // This is an awful, awful hack. Discovered when we migrated to using
838- // clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
839- // tree, will execute `llvm-config --cmakedir` and then tell CMake about
840- // that directory for later processing. Unfortunately if this path has
841- // forward slashes in it (which it basically always does on Windows)
842- // then CMake will hit a syntax error later on as... something isn't
843- // escaped it seems?
844- //
845- // Instead of attempting to fix this problem in upstream CMake and/or
846- // LLVM/LLD we just hack around it here. This thin wrapper will take the
847- // output from llvm-config and replace all instances of `\` with `/` to
848- // ensure we don't hit the same bugs with escaping. It means that you
849- // can't build on a system where your paths require `\` on Windows, but
850- // there's probably a lot of reasons you can't do that other than this.
851- let llvm_config_shim = env:: current_exe ( ) . unwrap ( ) . with_file_name ( "llvm-config-wrapper" ) ;
852-
853843 // Re-use the same flags as llvm to control the level of debug information
854844 // generated for lld.
855845 let profile = match ( builder. config . llvm_optimize , builder. config . llvm_release_debuginfo ) {
@@ -860,32 +850,9 @@ impl Step for Lld {
860850
861851 cfg. out_dir ( & out_dir)
862852 . profile ( profile)
863- . env ( "LLVM_CONFIG_REAL" , & llvm_config)
864- . define ( "LLVM_CONFIG_PATH" , llvm_config_shim)
853+ . define ( "LLVM_CMAKE_DIR" , llvm_cmake_dir)
865854 . define ( "LLVM_INCLUDE_TESTS" , "OFF" ) ;
866855
867- // While we're using this horrible workaround to shim the execution of
868- // llvm-config, let's just pile on more. I can't seem to figure out how
869- // to build LLD as a standalone project and also cross-compile it at the
870- // same time. It wants a natively executable `llvm-config` to learn
871- // about LLVM, but then it learns about all the host configuration of
872- // LLVM and tries to link to host LLVM libraries.
873- //
874- // To work around that we tell our shim to replace anything with the
875- // build target with the actual target instead. This'll break parts of
876- // LLD though which try to execute host tools, such as llvm-tblgen, so
877- // we specifically tell it where to find those. This is likely super
878- // brittle and will break over time. If anyone knows better how to
879- // cross-compile LLD it would be much appreciated to fix this!
880- if target != builder. config . build {
881- cfg. env ( "LLVM_CONFIG_SHIM_REPLACE" , & builder. config . build . triple )
882- . env ( "LLVM_CONFIG_SHIM_REPLACE_WITH" , & target. triple )
883- . define (
884- "LLVM_TABLEGEN_EXE" ,
885- llvm_config. with_file_name ( "llvm-tblgen" ) . with_extension ( EXE_EXTENSION ) ,
886- ) ;
887- }
888-
889856 cfg. build ( ) ;
890857
891858 t ! ( File :: create( & done_stamp) ) ;
0 commit comments