@@ -26,7 +26,11 @@ pub struct Gcc {
2626
2727#[ derive( Clone ) ]
2828pub struct GccOutput {
29- pub libgccjit : PathBuf ,
29+ /// Path to a built or downloaded libgccjit.
30+ /// Is None when setting libgccjit-libs-dir.
31+ /// FIXME: it seems wrong to make this an Option.
32+ /// Perhaps it should be a Vec so that we can install all libs from libgccjit-libs-dir?
33+ pub libgccjit : Option < PathBuf > ,
3034 target : TargetSelection ,
3135}
3236
@@ -37,20 +41,22 @@ impl GccOutput {
3741 return ;
3842 }
3943
40- let target_filename = self . libgccjit . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
44+ if let Some ( ref path) = self . libgccjit {
45+ let mut target_filename = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
4146
42- // If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink.
43- // In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink,
44- // which wouldn't work.
45- let actual_libgccjit_path = t ! (
46- self . libgccjit . canonicalize( ) ,
47- format!( "Cannot find libgccjit at {}" , self . libgccjit . display( ) )
48- ) ;
47+ // If we build libgccjit ourselves, then `self.libgccjit` can actually be a symlink.
48+ // In that case, we have to resolve it first, otherwise we'd create a symlink to a symlink,
49+ // which wouldn't work.
50+ let actual_libgccjit_path = t ! (
51+ path . canonicalize( ) ,
52+ format!( "Cannot find libgccjit at {}" , path . display( ) )
53+ ) ;
4954
50- let dest_dir = directory. join ( "rustlib" ) . join ( self . target ) . join ( "lib" ) ;
51- t ! ( fs:: create_dir_all( & dest_dir) ) ;
52- let dst = dest_dir. join ( target_filename) ;
53- builder. copy_link ( & actual_libgccjit_path, & dst, FileType :: NativeLibrary ) ;
55+ let dest_dir = directory. join ( "rustlib" ) . join ( self . target ) . join ( "lib" ) ;
56+ t ! ( fs:: create_dir_all( & dest_dir) ) ;
57+ let dst = dest_dir. join ( target_filename) ;
58+ builder. copy_link ( & actual_libgccjit_path, & dst, FileType :: NativeLibrary ) ;
59+ }
5460
5561 if let Some ( ref path) = builder. config . libgccjit_libs_dir {
5662 let host_target = builder. config . host_target . triple ;
@@ -62,13 +68,14 @@ impl GccOutput {
6268 . map ( |target| target. triple )
6369 . chain ( std:: iter:: once ( host_target) ) ;
6470
71+ let target_filename = "libgccjit.so.0" ;
6572 for target in targets {
66- let source = source. join ( target) . join ( & target_filename) ;
73+ let source = source. join ( target) . join ( target_filename) ;
6774 // To support symlinks in libgccjit-libs-dir, we have to resolve it first,
6875 // otherwise we'd create a symlink to a symlink, which wouldn't work.
6976 let actual_libgccjit_path = t ! (
7077 source. canonicalize( ) ,
71- format!( "Cannot find libgccjit at {}" , self . libgccjit . display( ) )
78+ format!( "Cannot find libgccjit at {}" , source . display( ) )
7279 ) ;
7380 let target_dir = dst. join ( target) ;
7481 t ! (
@@ -102,7 +109,8 @@ impl Step for Gcc {
102109
103110 // If GCC has already been built, we avoid building it again.
104111 let metadata = match get_gcc_build_status ( builder, target) {
105- GccBuildStatus :: AlreadyBuilt ( path) => return GccOutput { libgccjit : path, target } ,
112+ GccBuildStatus :: AlreadyBuilt ( path) => return GccOutput { libgccjit : Some ( path) , target } ,
113+ GccBuildStatus :: InLibsDir => return GccOutput { libgccjit : None } ,
106114 GccBuildStatus :: ShouldBuild ( m) => m,
107115 } ;
108116
@@ -112,14 +120,14 @@ impl Step for Gcc {
112120
113121 let libgccjit_path = libgccjit_built_path ( & metadata. install_dir ) ;
114122 if builder. config . dry_run ( ) {
115- return GccOutput { libgccjit : libgccjit_path, target } ;
123+ return GccOutput { libgccjit : Some ( libgccjit_path) , target } ;
116124 }
117125
118126 build_gcc ( & metadata, builder, target) ;
119127
120128 t ! ( metadata. stamp. write( ) ) ;
121129
122- GccOutput { libgccjit : libgccjit_path, target }
130+ GccOutput { libgccjit : Some ( libgccjit_path) , target }
123131 }
124132}
125133
@@ -133,6 +141,7 @@ pub struct Meta {
133141pub enum GccBuildStatus {
134142 /// libgccjit is already built at this path
135143 AlreadyBuilt ( PathBuf ) ,
144+ InLibsDir ,
136145 ShouldBuild ( Meta ) ,
137146}
138147
@@ -197,6 +206,11 @@ fn try_download_gcc(_builder: &Builder<'_>, _target: TargetSelection) -> Option<
197206/// It's used to avoid busting caches during x.py check -- if we've already built
198207/// GCC, it's fine for us to not try to avoid doing so.
199208pub fn get_gcc_build_status ( builder : & Builder < ' _ > , target : TargetSelection ) -> GccBuildStatus {
209+ if matches ! ( builder. config. gcc_ci_mode, crate :: core:: config:: GccCiMode :: CopyFromLibsDir ) {
210+ // TODO: check if this is OK.
211+ return GccBuildStatus :: InLibsDir ;
212+ }
213+
200214 if let Some ( path) = try_download_gcc ( builder, target) {
201215 return GccBuildStatus :: AlreadyBuilt ( path) ;
202216 }
@@ -320,7 +334,9 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
320334/// Configures a Cargo invocation so that it can build the GCC codegen backend.
321335pub fn add_cg_gcc_cargo_flags ( cargo : & mut Cargo , gcc : & GccOutput ) {
322336 // Add the path to libgccjit.so to the linker search paths.
323- cargo. rustflag ( & format ! ( "-L{}" , gcc. libgccjit. parent( ) . unwrap( ) . to_str( ) . unwrap( ) ) ) ;
337+ if let Some ( ref path) = gcc. libgccjit {
338+ cargo. rustflag ( & format ! ( "-L{}" , path. parent( ) . unwrap( ) . to_str( ) . unwrap( ) ) ) ;
339+ }
324340}
325341
326342/// The absolute path to the downloaded GCC artifacts.
0 commit comments