@@ -31,14 +31,33 @@ pub(crate) fn build_sysroot(
3131
3232 let is_native = bootstrap_host_compiler. triple == target_triple;
3333
34- let cg_clif_dylib_path = match cg_clif_dylib_src {
34+ let cg_clif_backend_name = match cg_clif_dylib_src {
3535 CodegenBackend :: Local ( src_path) => {
36- // Copy the backend
37- let cg_clif_dylib_path = dist_dir. join ( "lib" ) . join ( src_path. file_name ( ) . unwrap ( ) ) ;
36+ // Create the codegen-backends dir in the sysroot
37+ let dylib_dir = dist_dir
38+ . join ( "lib" )
39+ . join ( "rustlib" )
40+ . join ( & bootstrap_host_compiler. triple )
41+ . join ( "codegen-backends" ) ;
42+ fs:: create_dir_all ( & dylib_dir) . unwrap ( ) ;
43+
44+ // Copy the backend into the sysroot
45+ let target_dylib_name = get_file_name (
46+ & bootstrap_host_compiler. rustc ,
47+ "rustc_codegen_cranelift_local" ,
48+ "dylib" ,
49+ )
50+ . replace ( "cranelift_local" , "cranelift-local" ) ;
51+ let cg_clif_dylib_path = dylib_dir. join ( target_dylib_name) ;
3852 try_hard_link ( src_path, & cg_clif_dylib_path) ;
39- CodegenBackend :: Local ( cg_clif_dylib_path)
53+
54+ // This is using a different name from rustup distributed versions of cg_clif to allow
55+ // switching between a locally built and rustup distributed version and to ensure that
56+ // the rustup distributed version doesn't accidentally gets picked when trying to use
57+ // the locally built version.
58+ "cranelift-local" . to_owned ( )
4059 }
41- CodegenBackend :: Builtin ( name) => CodegenBackend :: Builtin ( name. clone ( ) ) ,
60+ CodegenBackend :: Builtin ( name) => name. clone ( ) ,
4261 } ;
4362
4463 // Build and copy rustc and cargo wrappers
@@ -70,17 +89,16 @@ pub(crate) fn build_sysroot(
7089 . env ( "RUSTC" , & bootstrap_host_compiler. rustc )
7190 . env ( "RUSTDOC" , & bootstrap_host_compiler. rustdoc ) ;
7291 }
73- if let CodegenBackend :: Builtin ( name) = cg_clif_dylib_src {
74- build_cargo_wrapper_cmd. env ( "BUILTIN_BACKEND" , name) ;
75- }
92+ build_cargo_wrapper_cmd. env ( "HOST_TUPLE" , & bootstrap_host_compiler. triple ) ;
93+ build_cargo_wrapper_cmd. env ( "BUILTIN_BACKEND" , & cg_clif_backend_name) ;
7694 spawn_and_wait ( build_cargo_wrapper_cmd) ;
7795 try_hard_link ( wrapper_path, dist_dir. join ( "bin" ) . join ( wrapper_name) ) ;
7896 }
7997
8098 let host = build_sysroot_for_triple (
8199 dirs,
82100 bootstrap_host_compiler. clone ( ) ,
83- & cg_clif_dylib_path ,
101+ & cg_clif_dylib_src ,
84102 sysroot_kind,
85103 panic_unwind_support,
86104 ) ;
@@ -95,7 +113,7 @@ pub(crate) fn build_sysroot(
95113 bootstrap_target_compiler. set_cross_linker_and_runner ( ) ;
96114 bootstrap_target_compiler
97115 } ,
98- & cg_clif_dylib_path ,
116+ & cg_clif_dylib_src ,
99117 sysroot_kind,
100118 panic_unwind_support,
101119 )
0 commit comments