11use std:: collections:: HashMap ;
22use std:: ffi:: OsStr ;
33use std:: fs;
4- use std:: path:: Path ;
4+ use std:: os:: unix:: fs:: symlink;
5+ use std:: path:: { Path , PathBuf } ;
56
67use crate :: config:: { Channel , ConfigInfo } ;
78use crate :: utils:: {
@@ -100,6 +101,20 @@ fn cleanup_sysroot_previous_build(library_dir: &Path) {
100101pub fn build_sysroot ( env : & HashMap < String , String > , config : & ConfigInfo ) -> Result < ( ) , String > {
101102 let start_dir = get_sysroot_dir ( ) ;
102103
104+ // Copy libgccjit.so to sysroot.
105+ let lib_path = start_dir. join ( "sysroot" ) . join ( "lib" ) ;
106+ let libgccjit_path =
107+ PathBuf :: from ( config. gcc_path . as_ref ( ) . expect ( "libgccjit should be set by this point" ) )
108+ . join ( "libgccjit.so" ) ;
109+ let libgccjit_in_sysroot_path = lib_path. join ( "libgccjit.so" ) ;
110+ // First remove the file to be able to create the symlink even when the file exists.
111+ let _ = fs:: remove_file ( & libgccjit_in_sysroot_path) ;
112+ println ! ( "Directory {:?} exists: {:?}" , libgccjit_path, std:: fs:: exists( & libgccjit_path) ) ;
113+ create_dir ( & lib_path) ?;
114+ println ! ( "Directory {:?} exists: {:?}" , lib_path, std:: fs:: exists( & lib_path) ) ;
115+ symlink ( libgccjit_path, libgccjit_in_sysroot_path)
116+ . map_err ( |error| format ! ( "Cannot create symlink for libgccjit.so: {}" , error) ) ?;
117+
103118 let library_dir = start_dir. join ( "sysroot_src" ) . join ( "library" ) ;
104119 cleanup_sysroot_previous_build ( & library_dir) ;
105120
@@ -148,7 +163,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
148163 run_command_with_output_and_env ( & args, Some ( & sysroot_dir) , Some ( & env) ) ?;
149164
150165 // Copy files to sysroot
151- let sysroot_path = start_dir . join ( format ! ( "sysroot/lib/ rustlib/{}/lib/" , config. target_triple) ) ;
166+ let sysroot_path = lib_path . join ( format ! ( "rustlib/{}/lib/" , config. target_triple) ) ;
152167 // To avoid errors like "multiple candidates for `rmeta` dependency `core` found", we clean the
153168 // sysroot directory before copying the sysroot build artifacts.
154169 let _ = fs:: remove_dir_all ( & sysroot_path) ;
@@ -175,13 +190,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
175190fn build_codegen ( args : & mut BuildArg ) -> Result < ( ) , String > {
176191 let mut env = HashMap :: new ( ) ;
177192
178- let gcc_path =
179- args. config_info . gcc_path . clone ( ) . expect (
180- "The config module should have emitted an error if the GCC path wasn't provided" ,
181- ) ;
182- env. insert ( "LD_LIBRARY_PATH" . to_string ( ) , gcc_path. clone ( ) ) ;
183- env. insert ( "LIBRARY_PATH" . to_string ( ) , gcc_path) ;
184-
185193 if args. config_info . no_default_features {
186194 env. insert ( "RUSTFLAGS" . to_string ( ) , "-Csymbol-mangling-version=v0" . to_string ( ) ) ;
187195 }
0 commit comments