@@ -250,6 +250,8 @@ pub struct Config {
250250 pub llvm_ldflags : Option < String > ,
251251 pub llvm_use_libcxx : bool ,
252252
253+ pub gcc_download_gccjit : bool ,
254+
253255 // rust codegen options
254256 pub rust_optimize : RustOptimize ,
255257 pub rust_codegen_units : Option < u32 > ,
@@ -592,6 +594,7 @@ pub(crate) struct TomlConfig {
592594 build : Option < Build > ,
593595 install : Option < Install > ,
594596 llvm : Option < Llvm > ,
597+ gcc : Option < Gcc > ,
595598 rust : Option < Rust > ,
596599 target : Option < HashMap < String , TomlTarget > > ,
597600 dist : Option < Dist > ,
@@ -626,7 +629,7 @@ trait Merge {
626629impl Merge for TomlConfig {
627630 fn merge (
628631 & mut self ,
629- TomlConfig { build, install, llvm, rust, dist, target, profile : _, change_id } : Self ,
632+ TomlConfig { build, install, llvm, rust, dist, target, profile : _, change_id, gcc } : Self ,
630633 replace : ReplaceOpt ,
631634 ) {
632635 fn do_merge < T : Merge > ( x : & mut Option < T > , y : Option < T > , replace : ReplaceOpt ) {
@@ -644,6 +647,7 @@ impl Merge for TomlConfig {
644647 do_merge ( & mut self . llvm , llvm, replace) ;
645648 do_merge ( & mut self . rust , rust, replace) ;
646649 do_merge ( & mut self . dist , dist, replace) ;
650+ do_merge ( & mut self . gcc , gcc, replace) ;
647651 assert ! ( target. is_none( ) , "merging target-specific config is not currently supported" ) ;
648652 }
649653}
@@ -899,6 +903,13 @@ define_config! {
899903 }
900904}
901905
906+ define_config ! {
907+ /// TOML representation of how the GCC backend is configured.
908+ struct Gcc {
909+ download_gccjit: Option <bool > = "download-gccjit" ,
910+ }
911+ }
912+
902913#[ derive( Clone , Debug , Deserialize ) ]
903914#[ serde( untagged) ]
904915pub enum StringOrBool {
@@ -1724,6 +1735,14 @@ impl Config {
17241735 ci_channel. clone_into ( & mut config. channel ) ;
17251736 }
17261737
1738+ if let Some ( gcc) = toml. gcc {
1739+ let Gcc { download_gccjit } = gcc;
1740+ config. gcc_download_gccjit = download_gccjit. unwrap_or ( false ) ;
1741+ }
1742+ if config. gcc_enabled ( config. build ) {
1743+ config. maybe_download_gccjit ( ) ;
1744+ }
1745+
17271746 if let Some ( llvm) = toml. llvm {
17281747 let Llvm {
17291748 optimize : optimize_toml,
@@ -2329,6 +2348,18 @@ impl Config {
23292348 self . codegen_backends ( target) . contains ( & "llvm" . to_owned ( ) )
23302349 }
23312350
2351+ pub fn gcc_enabled ( & self , target : TargetSelection ) -> bool {
2352+ self . codegen_backends ( target) . contains ( & "gcc" . to_owned ( ) )
2353+ }
2354+
2355+ pub fn libgccjit_folder ( & self , gcc_sha : & str ) -> PathBuf {
2356+ assert ! ( self . gcc_download_gccjit) ;
2357+ let cache_prefix = format ! ( "libgccjit-{gcc_sha}" ) ;
2358+ let cache_dst =
2359+ self . bootstrap_cache_path . as_ref ( ) . cloned ( ) . unwrap_or_else ( || self . out . join ( "cache" ) ) ;
2360+ cache_dst. join ( cache_prefix)
2361+ }
2362+
23322363 pub fn llvm_libunwind ( & self , target : TargetSelection ) -> LlvmLibunwind {
23332364 self . target_config
23342365 . get ( & target)
0 commit comments