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,18 @@ 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+ // Symlink 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 already exists.
111+ let _ = fs:: remove_file ( & libgccjit_in_sysroot_path) ;
112+ create_dir ( & lib_path) ?;
113+ symlink ( libgccjit_path, libgccjit_in_sysroot_path)
114+ . map_err ( |error| format ! ( "Cannot create symlink for libgccjit.so: {}" , error) ) ?;
115+
103116 let library_dir = start_dir. join ( "sysroot_src" ) . join ( "library" ) ;
104117 cleanup_sysroot_previous_build ( & library_dir) ;
105118
@@ -148,7 +161,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
148161 run_command_with_output_and_env ( & args, Some ( & sysroot_dir) , Some ( & env) ) ?;
149162
150163 // Copy files to sysroot
151- let sysroot_path = start_dir . join ( format ! ( "sysroot/lib/ rustlib/{}/lib/" , config. target_triple) ) ;
164+ let sysroot_path = lib_path . join ( format ! ( "rustlib/{}/lib/" , config. target_triple) ) ;
152165 // To avoid errors like "multiple candidates for `rmeta` dependency `core` found", we clean the
153166 // sysroot directory before copying the sysroot build artifacts.
154167 let _ = fs:: remove_dir_all ( & sysroot_path) ;
@@ -175,13 +188,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
175188fn build_codegen ( args : & mut BuildArg ) -> Result < ( ) , String > {
176189 let mut env = HashMap :: new ( ) ;
177190
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-
185191 if args. config_info . no_default_features {
186192 env. insert ( "RUSTFLAGS" . to_string ( ) , "-Csymbol-mangling-version=v0" . to_string ( ) ) ;
187193 }
0 commit comments