@@ -1652,23 +1652,7 @@ impl Step for CraneliftCodegenBackend {
16521652 return None ;
16531653 }
16541654
1655- // Get the relative path of where the codegen backend should be stored.
1656- let backends_dst = builder. sysroot_codegen_backends ( compilers. target_compiler ( ) ) ;
1657- let backends_rel = backends_dst
1658- . strip_prefix ( builder. sysroot ( compilers. target_compiler ( ) ) )
1659- . unwrap ( )
1660- . strip_prefix ( builder. sysroot_libdir_relative ( compilers. target_compiler ( ) ) )
1661- . unwrap ( ) ;
1662- // Don't use custom libdir here because ^lib/ will be resolved again with installer
1663- let backends_dst = PathBuf :: from ( "lib" ) . join ( backends_rel) ;
1664-
1665- let codegen_backend_dylib = get_codegen_backend_file ( & stamp) ;
1666- tarball. add_renamed_file (
1667- & codegen_backend_dylib,
1668- & backends_dst,
1669- & normalize_codegen_backend_name ( builder, & codegen_backend_dylib) ,
1670- FileType :: NativeLibrary ,
1671- ) ;
1655+ add_codegen_backend_to_tarball ( builder, & tarball, compilers. target_compiler ( ) , & stamp) ;
16721656
16731657 Some ( tarball. generate ( ) )
16741658 }
@@ -1681,6 +1665,113 @@ impl Step for CraneliftCodegenBackend {
16811665 }
16821666}
16831667
1668+ /// Builds a dist component containing the GCC codegen backend.
1669+ /// Note that for this backend to work, it must have a set of libgccjit dylibs available
1670+ /// at runtime.
1671+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
1672+ pub struct GccCodegenBackend {
1673+ pub compilers : RustcPrivateCompilers ,
1674+ pub target : TargetSelection ,
1675+ }
1676+
1677+ impl Step for GccCodegenBackend {
1678+ type Output = Option < GeneratedTarball > ;
1679+ const IS_HOST : bool = true ;
1680+
1681+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1682+ run. alias ( "rustc_codegen_gcc" )
1683+ }
1684+
1685+ fn is_default_step ( builder : & Builder < ' _ > ) -> bool {
1686+ // We only want to build the gcc backend in `x dist` if the backend was enabled
1687+ // in rust.codegen-backends.
1688+ // Sadly, we don't have access to the actual target for which we're disting clif here..
1689+ // So we just use the host target.
1690+ builder
1691+ . config
1692+ . enabled_codegen_backends ( builder. host_target )
1693+ . contains ( & CodegenBackendKind :: Gcc )
1694+ }
1695+
1696+ fn make_run ( run : RunConfig < ' _ > ) {
1697+ run. builder . ensure ( GccCodegenBackend {
1698+ compilers : RustcPrivateCompilers :: new ( run. builder , run. builder . top_stage , run. target ) ,
1699+ target : run. target ,
1700+ } ) ;
1701+ }
1702+
1703+ fn run ( self , builder : & Builder < ' _ > ) -> Option < GeneratedTarball > {
1704+ // This prevents rustc_codegen_gcc from being built for "dist"
1705+ // or "install" on the stable/beta channels. It is not yet stable and
1706+ // should not be included.
1707+ if !builder. build . unstable_features ( ) {
1708+ return None ;
1709+ }
1710+
1711+ let target = self . target ;
1712+ if target != "x86_64-unknown-linux-gnu" {
1713+ builder
1714+ . info ( & format ! ( "target `{target}` not supported by rustc_codegen_gcc. skipping" ) ) ;
1715+ return None ;
1716+ }
1717+
1718+ let mut tarball = Tarball :: new ( builder, "rustc-codegen-gcc" , & target. triple ) ;
1719+ tarball. set_overlay ( OverlayKind :: RustcCodegenGcc ) ;
1720+ tarball. is_preview ( true ) ;
1721+ tarball. add_legal_and_readme_to ( "share/doc/rustc_codegen_gcc" ) ;
1722+
1723+ let compilers = self . compilers ;
1724+ let backend = builder. ensure ( compile:: GccCodegenBackend :: for_target ( compilers, target) ) ;
1725+
1726+ if builder. config . dry_run ( ) {
1727+ return None ;
1728+ }
1729+
1730+ add_codegen_backend_to_tarball (
1731+ builder,
1732+ & tarball,
1733+ compilers. target_compiler ( ) ,
1734+ backend. stamp ( ) ,
1735+ ) ;
1736+
1737+ Some ( tarball. generate ( ) )
1738+ }
1739+
1740+ fn metadata ( & self ) -> Option < StepMetadata > {
1741+ Some (
1742+ StepMetadata :: dist ( "rustc_codegen_gcc" , self . target )
1743+ . built_by ( self . compilers . build_compiler ( ) ) ,
1744+ )
1745+ }
1746+ }
1747+
1748+ /// Add a codegen backend built for `compiler`, with its artifacts stored in `stamp`, to the given
1749+ /// `tarball` at the correct place.
1750+ fn add_codegen_backend_to_tarball (
1751+ builder : & Builder < ' _ > ,
1752+ tarball : & Tarball < ' _ > ,
1753+ compiler : Compiler ,
1754+ stamp : & BuildStamp ,
1755+ ) {
1756+ // Get the relative path of where the codegen backend should be stored.
1757+ let backends_dst = builder. sysroot_codegen_backends ( compiler) ;
1758+ let backends_rel = backends_dst
1759+ . strip_prefix ( builder. sysroot ( compiler) )
1760+ . unwrap ( )
1761+ . strip_prefix ( builder. sysroot_libdir_relative ( compiler) )
1762+ . unwrap ( ) ;
1763+ // Don't use custom libdir here because ^lib/ will be resolved again with installer
1764+ let backends_dst = PathBuf :: from ( "lib" ) . join ( backends_rel) ;
1765+
1766+ let codegen_backend_dylib = get_codegen_backend_file ( stamp) ;
1767+ tarball. add_renamed_file (
1768+ & codegen_backend_dylib,
1769+ & backends_dst,
1770+ & normalize_codegen_backend_name ( builder, & codegen_backend_dylib) ,
1771+ FileType :: NativeLibrary ,
1772+ ) ;
1773+ }
1774+
16841775#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
16851776pub struct Rustfmt {
16861777 pub compilers : RustcPrivateCompilers ,
0 commit comments