@@ -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 > ,
@@ -617,6 +619,7 @@ pub(crate) struct TomlConfig {
617619 build : Option < Build > ,
618620 install : Option < Install > ,
619621 llvm : Option < Llvm > ,
622+ gcc : Option < Gcc > ,
620623 rust : Option < Rust > ,
621624 target : Option < HashMap < String , TomlTarget > > ,
622625 dist : Option < Dist > ,
@@ -651,7 +654,7 @@ trait Merge {
651654impl Merge for TomlConfig {
652655 fn merge (
653656 & mut self ,
654- TomlConfig { build, install, llvm, rust, dist, target, profile : _, change_id } : Self ,
657+ TomlConfig { build, install, llvm, rust, dist, target, profile : _, change_id, gcc } : Self ,
655658 replace : ReplaceOpt ,
656659 ) {
657660 fn do_merge < T : Merge > ( x : & mut Option < T > , y : Option < T > , replace : ReplaceOpt ) {
@@ -669,6 +672,7 @@ impl Merge for TomlConfig {
669672 do_merge ( & mut self . llvm , llvm, replace) ;
670673 do_merge ( & mut self . rust , rust, replace) ;
671674 do_merge ( & mut self . dist , dist, replace) ;
675+ do_merge ( & mut self . gcc , gcc, replace) ;
672676 assert ! ( target. is_none( ) , "merging target-specific config is not currently supported" ) ;
673677 }
674678}
@@ -923,6 +927,13 @@ define_config! {
923927 }
924928}
925929
930+ define_config ! {
931+ /// TOML representation of how the GCC backend is configured.
932+ struct Gcc {
933+ download_gccjit: Option <bool > = "download-gccjit" ,
934+ }
935+ }
936+
926937#[ derive( Clone , Debug , Deserialize ) ]
927938#[ serde( untagged) ]
928939pub enum StringOrBool {
@@ -1749,6 +1760,14 @@ impl Config {
17491760 config. omit_git_hash = omit_git_hash. unwrap_or ( default) ;
17501761 config. rust_info = GitInfo :: new ( config. omit_git_hash , & config. src ) ;
17511762
1763+ if let Some ( gcc) = toml. gcc {
1764+ let Gcc { download_gccjit } = gcc;
1765+ config. gcc_download_gccjit = download_gccjit. unwrap_or ( false ) ;
1766+ }
1767+ if config. gcc_enabled ( config. build ) {
1768+ config. maybe_download_gccjit ( ) ;
1769+ }
1770+
17521771 if let Some ( llvm) = toml. llvm {
17531772 let Llvm {
17541773 optimize : optimize_toml,
@@ -2315,6 +2334,18 @@ impl Config {
23152334 self . codegen_backends ( target) . contains ( & "llvm" . to_owned ( ) )
23162335 }
23172336
2337+ pub fn gcc_enabled ( & self , target : TargetSelection ) -> bool {
2338+ self . codegen_backends ( target) . contains ( & "gcc" . to_owned ( ) )
2339+ }
2340+
2341+ pub fn libgccjit_folder ( & self , gcc_sha : & str ) -> PathBuf {
2342+ assert ! ( self . gcc_download_gccjit) ;
2343+ let cache_prefix = format ! ( "libgccjit-{gcc_sha}" ) ;
2344+ let cache_dst =
2345+ self . bootstrap_cache_path . as_ref ( ) . cloned ( ) . unwrap_or_else ( || self . out . join ( "cache" ) ) ;
2346+ cache_dst. join ( cache_prefix)
2347+ }
2348+
23182349 pub fn llvm_libunwind ( & self , target : TargetSelection ) -> LlvmLibunwind {
23192350 self . target_config
23202351 . get ( & target)
0 commit comments