@@ -30,14 +30,33 @@ pub(crate) fn build_sysroot(
3030
3131 let is_native = bootstrap_host_compiler. triple == target_triple;
3232
33- let cg_clif_dylib_path = match cg_clif_dylib_src {
33+ let cg_clif_backend_name = match cg_clif_dylib_src {
3434 CodegenBackend :: Local ( src_path) => {
35- // Copy the backend
36- let cg_clif_dylib_path = dist_dir. join ( "lib" ) . join ( src_path. file_name ( ) . unwrap ( ) ) ;
35+ // Create the codegen-backends dir in the sysroot
36+ let dylib_dir = dist_dir
37+ . join ( "lib" )
38+ . join ( "rustlib" )
39+ . join ( & bootstrap_host_compiler. triple )
40+ . join ( "codegen-backends" ) ;
41+ fs:: create_dir_all ( & dylib_dir) . unwrap ( ) ;
42+
43+ // Copy the backend into the sysroot
44+ let target_dylib_name = get_file_name (
45+ & bootstrap_host_compiler. rustc ,
46+ "rustc_codegen_cranelift_local" ,
47+ "dylib" ,
48+ )
49+ . replace ( "cranelift_local" , "cranelift-local" ) ;
50+ let cg_clif_dylib_path = dylib_dir. join ( target_dylib_name) ;
3751 try_hard_link ( src_path, & cg_clif_dylib_path) ;
38- CodegenBackend :: Local ( cg_clif_dylib_path)
52+
53+ // This is using a different name from rustup distributed versions of cg_clif to allow
54+ // switching between a locally built and rustup distributed version and to ensure that
55+ // the rustup distributed version doesn't accidentally gets picked when trying to use
56+ // the locally built version.
57+ "cranelift-local" . to_owned ( )
3958 }
40- CodegenBackend :: Builtin ( name) => CodegenBackend :: Builtin ( name. clone ( ) ) ,
59+ CodegenBackend :: Builtin ( name) => name. clone ( ) ,
4160 } ;
4261
4362 // Build and copy rustc and cargo wrappers
@@ -65,17 +84,16 @@ pub(crate) fn build_sysroot(
6584 . env ( "RUSTC" , & bootstrap_host_compiler. rustc )
6685 . env ( "RUSTDOC" , & bootstrap_host_compiler. rustdoc ) ;
6786 }
68- if let CodegenBackend :: Builtin ( name) = cg_clif_dylib_src {
69- build_cargo_wrapper_cmd. env ( "BUILTIN_BACKEND" , name) ;
70- }
87+ build_cargo_wrapper_cmd. env ( "HOST_TUPLE" , & bootstrap_host_compiler. triple ) ;
88+ build_cargo_wrapper_cmd. env ( "BUILTIN_BACKEND" , & cg_clif_backend_name) ;
7189 spawn_and_wait ( build_cargo_wrapper_cmd) ;
7290 try_hard_link ( wrapper_path, dist_dir. join ( "bin" ) . join ( wrapper_name) ) ;
7391 }
7492
7593 let host = build_sysroot_for_triple (
7694 dirs,
7795 bootstrap_host_compiler. clone ( ) ,
78- & cg_clif_dylib_path ,
96+ & cg_clif_dylib_src ,
7997 sysroot_kind,
8098 ) ;
8199 host. install_into_sysroot ( dist_dir) ;
@@ -89,7 +107,7 @@ pub(crate) fn build_sysroot(
89107 bootstrap_target_compiler. set_cross_linker_and_runner ( ) ;
90108 bootstrap_target_compiler
91109 } ,
92- & cg_clif_dylib_path ,
110+ & cg_clif_dylib_src ,
93111 sysroot_kind,
94112 )
95113 . install_into_sysroot ( dist_dir) ;
0 commit comments