@@ -106,12 +106,9 @@ fn cleanup_sysroot_previous_build(library_dir: &Path) {
106106 ) ;
107107}
108108
109- pub fn build_sysroot ( env : & HashMap < String , String > , config : & ConfigInfo ) -> Result < ( ) , String > {
110- let start_dir = get_sysroot_dir ( ) ;
111-
112- // Symlink libgccjit.so to sysroot.
113- let lib_path = start_dir. join ( "sysroot" ) . join ( "lib" ) ;
114- let rustlib_target_path = lib_path
109+ pub fn link_libgccjit_in_sysroot ( config : & ConfigInfo , sysroot_path : & Path ) -> Result < ( ) , String > {
110+ let rustlib_target_path = sysroot_path
111+ . join ( "lib" )
115112 . join ( "rustlib" )
116113 . join ( & config. host_triple )
117114 . join ( "codegen-backends" )
@@ -124,8 +121,18 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
124121 // First remove the file to be able to create the symlink even when the file already exists.
125122 let _ = fs:: remove_file ( & libgccjit_in_sysroot_path) ;
126123 create_dir ( & rustlib_target_path) ?;
127- symlink ( libgccjit_path, & libgccjit_in_sysroot_path)
124+ symlink ( & libgccjit_path, & libgccjit_in_sysroot_path)
128125 . map_err ( |error| format ! ( "Cannot create symlink for libgccjit.so: {}" , error) ) ?;
126+ println ! ( "Created symlink of `libgccjit.so` at {libgccjit_in_sysroot_path:?}" ) ;
127+ Ok ( ( ) )
128+ }
129+
130+ pub fn build_sysroot ( env : & HashMap < String , String > , config : & ConfigInfo ) -> Result < ( ) , String > {
131+ let start_dir = get_sysroot_dir ( ) ;
132+
133+ // Symlink libgccjit.so to sysroot.
134+ let sysroot_path = start_dir. join ( "sysroot" ) ;
135+ link_libgccjit_in_sysroot ( config, & sysroot_path) ?;
129136
130137 let library_dir = start_dir. join ( "sysroot_src" ) . join ( "library" ) ;
131138 cleanup_sysroot_previous_build ( & library_dir) ;
@@ -179,7 +186,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
179186 run_command_with_output_and_env ( & args, Some ( & sysroot_dir) , Some ( & env) ) ?;
180187
181188 // Copy files to sysroot
182- let sysroot_path = lib_path . join ( format ! ( "rustlib/{}/lib/" , config. target_triple) ) ;
189+ let sysroot_path = sysroot_path . join ( format ! ( "lib/ rustlib/{}/lib/" , config. target_triple) ) ;
183190 // To avoid errors like "multiple candidates for `rmeta` dependency `core` found", we clean the
184191 // sysroot directory before copying the sysroot build artifacts.
185192 let _ = fs:: remove_dir_all ( & sysroot_path) ;
@@ -227,7 +234,9 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
227234 }
228235 run_command_with_output_and_env ( & command, None , Some ( & env) ) ?;
229236
230- args. config_info . setup ( & mut env, false ) ?;
237+ // We always build the sysroot with `cg_gcc` so we don't need to build the sysroot with
238+ // `cg_llvm` since it's already distributed by rustup.
239+ args. config_info . setup ( & mut env, false , false ) ?;
231240
232241 // We voluntarily ignore the error.
233242 let _ = fs:: remove_dir_all ( "target/out" ) ;
0 commit comments