@@ -32,7 +32,7 @@ use crate::utils::helpers::{
3232    exe,  is_dylib,  move_file,  t,  target_supports_cranelift_backend,  timeit, 
3333} ; 
3434use  crate :: utils:: tarball:: { GeneratedTarball ,  OverlayKind ,  Tarball } ; 
35- use  crate :: { Compiler ,  DependencyType ,  LLVM_TOOLS ,  Mode ,  trace} ; 
35+ use  crate :: { Compiler ,  DependencyType ,  LLVM_TOOLS ,  Mode ,  split_debuginfo ,   trace} ; 
3636
3737pub  fn  pkgname ( builder :  & Builder < ' _ > ,  component :  & str )  -> String  { 
3838    format ! ( "{}-{}" ,  component,  builder. rust_package_vers( ) ) 
@@ -53,6 +53,22 @@ fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
5353    builder. config . tools . as_ref ( ) . is_none_or ( |tools| tools. contains ( tool) ) 
5454} 
5555
56+ /// Add a binary file to the tarball with the appropriate permissions set. 
57+ /// If split debuginfo for the binary is present, it is also added to the tarball. 
58+ fn  tarball_add_binary ( 
59+     tarball :  & Tarball < ' _ > , 
60+     binary :  & Path , 
61+     dst :  impl  AsRef < Path > , 
62+     target :  TargetSelection , 
63+ )  { 
64+     let  dst = dst. as_ref ( ) ; 
65+     tarball. add_file ( binary,  dst,  0o755 ) ; 
66+ 
67+     if  let  Some ( debuginfo)  = split_debuginfo ( binary,  target)  { 
68+         tarball. add_file ( debuginfo,  dst,  0o644 ) ; 
69+     } 
70+ } 
71+ 
5672#[ derive( Debug ,  PartialOrd ,  Ord ,  Clone ,  Hash ,  PartialEq ,  Eq ) ]  
5773pub  struct  Docs  { 
5874    pub  host :  TargetSelection , 
@@ -432,7 +448,14 @@ impl Step for Rustc {
432448                } , 
433449                builder. kind , 
434450            )  { 
435-                 builder. install ( & ra_proc_macro_srv. tool_path ,  & image. join ( "libexec" ) ,  0o755 ) ; 
451+                 let  dst = image. join ( "libexec" ) ; 
452+                 builder. install ( & ra_proc_macro_srv. tool_path ,  & dst,  0o755 ) ; 
453+ 
454+                 if  let  Some ( debuginfo)  =
455+                     split_debuginfo ( & ra_proc_macro_srv. tool_path ,  compiler. host ) 
456+                 { 
457+                     builder. install ( & debuginfo,  & dst,  0o644 ) ; 
458+                 } 
436459            } 
437460
438461            let  libdir_relative = builder. libdir_relative ( compiler) ; 
@@ -463,15 +486,20 @@ impl Step for Rustc {
463486            if  builder. config . lld_enabled  { 
464487                let  src_dir = builder. sysroot_target_bindir ( compiler,  host) ; 
465488                let  rust_lld = exe ( "rust-lld" ,  compiler. host ) ; 
466-                 builder. copy_link ( & src_dir. join ( & rust_lld) ,  & dst_dir. join ( & rust_lld) ) ; 
489+                 builder. copy_link_binary ( 
490+                     & src_dir. join ( & rust_lld) , 
491+                     & dst_dir. join ( & rust_lld) , 
492+                     compiler. host , 
493+                 ) ; 
467494                let  self_contained_lld_src_dir = src_dir. join ( "gcc-ld" ) ; 
468495                let  self_contained_lld_dst_dir = dst_dir. join ( "gcc-ld" ) ; 
469496                t ! ( fs:: create_dir( & self_contained_lld_dst_dir) ) ; 
470497                for  name in  crate :: LLD_FILE_NAMES  { 
471498                    let  exe_name = exe ( name,  compiler. host ) ; 
472-                     builder. copy_link ( 
499+                     builder. copy_link_binary ( 
473500                        & self_contained_lld_src_dir. join ( & exe_name) , 
474501                        & self_contained_lld_dst_dir. join ( & exe_name) , 
502+                         host, 
475503                    ) ; 
476504                } 
477505            } 
@@ -480,13 +508,17 @@ impl Step for Rustc {
480508                let  src_dir = builder. sysroot_target_bindir ( compiler,  host) ; 
481509                let  llvm_objcopy = exe ( "llvm-objcopy" ,  compiler. host ) ; 
482510                let  rust_objcopy = exe ( "rust-objcopy" ,  compiler. host ) ; 
483-                 builder. copy_link ( & src_dir. join ( & llvm_objcopy) ,  & dst_dir. join ( & rust_objcopy) ) ; 
511+                 builder. copy_link_binary ( 
512+                     & src_dir. join ( & llvm_objcopy) , 
513+                     & dst_dir. join ( & rust_objcopy) , 
514+                     host, 
515+                 ) ; 
484516            } 
485517
486518            if  builder. tool_enabled ( "wasm-component-ld" )  { 
487519                let  src_dir = builder. sysroot_target_bindir ( compiler,  host) ; 
488520                let  ld = exe ( "wasm-component-ld" ,  compiler. host ) ; 
489-                 builder. copy_link ( & src_dir. join ( & ld) ,  & dst_dir. join ( & ld) ) ; 
521+                 builder. copy_link_binary ( & src_dir. join ( & ld) ,  & dst_dir. join ( & ld) ,  host ) ; 
490522            } 
491523
492524            // Man pages 
@@ -640,9 +672,13 @@ fn copy_target_libs(
640672    t ! ( fs:: create_dir_all( & self_contained_dst) ) ; 
641673    for  ( path,  dependency_type)  in  builder. read_stamp_file ( stamp)  { 
642674        if  dependency_type == DependencyType :: TargetSelfContained  { 
643-             builder. copy_link ( & path,  & self_contained_dst. join ( path. file_name ( ) . unwrap ( ) ) ) ; 
675+             builder. copy_link_binary ( 
676+                 & path, 
677+                 & self_contained_dst. join ( path. file_name ( ) . unwrap ( ) ) , 
678+                 target, 
679+             ) ; 
644680        }  else  if  dependency_type == DependencyType :: Target  || builder. is_builder_target ( target)  { 
645-             builder. copy_link ( & path,  & dst. join ( path. file_name ( ) . unwrap ( ) ) ) ; 
681+             builder. copy_link_binary ( & path,  & dst. join ( path. file_name ( ) . unwrap ( ) ) ,  target ) ; 
646682        } 
647683    } 
648684} 
@@ -1147,7 +1183,7 @@ impl Step for Cargo {
11471183        let  mut  tarball = Tarball :: new ( builder,  "cargo" ,  & target. triple ) ; 
11481184        tarball. set_overlay ( OverlayKind :: Cargo ) ; 
11491185
1150-         tarball . add_file ( cargo. tool_path ,  "bin" ,  0o755 ) ; 
1186+         tarball_add_binary ( & tarball ,   & cargo. tool_path ,  "bin" ,  target ) ; 
11511187        tarball. add_file ( etc. join ( "_cargo" ) ,  "share/zsh/site-functions" ,  0o644 ) ; 
11521188        tarball. add_renamed_file ( etc. join ( "cargo.bashcomp.sh" ) ,  "etc/bash_completion.d" ,  "cargo" ) ; 
11531189        tarball. add_dir ( etc. join ( "man" ) ,  "share/man/man1" ) ; 
@@ -1193,7 +1229,7 @@ impl Step for Rls {
11931229        let  mut  tarball = Tarball :: new ( builder,  "rls" ,  & target. triple ) ; 
11941230        tarball. set_overlay ( OverlayKind :: Rls ) ; 
11951231        tarball. is_preview ( true ) ; 
1196-         tarball . add_file ( rls. tool_path ,  "bin" ,  0o755 ) ; 
1232+         tarball_add_binary ( & tarball ,   & rls. tool_path ,  "bin" ,  target ) ; 
11971233        tarball. add_legal_and_readme_to ( "share/doc/rls" ) ; 
11981234        Some ( tarball. generate ( ) ) 
11991235    } 
@@ -1235,7 +1271,7 @@ impl Step for RustAnalyzer {
12351271        let  mut  tarball = Tarball :: new ( builder,  "rust-analyzer" ,  & target. triple ) ; 
12361272        tarball. set_overlay ( OverlayKind :: RustAnalyzer ) ; 
12371273        tarball. is_preview ( true ) ; 
1238-         tarball . add_file ( rust_analyzer. tool_path ,  "bin" ,  0o755 ) ; 
1274+         tarball_add_binary ( & tarball ,   & rust_analyzer. tool_path ,  "bin" ,  target ) ; 
12391275        tarball. add_legal_and_readme_to ( "share/doc/rust-analyzer" ) ; 
12401276        Some ( tarball. generate ( ) ) 
12411277    } 
@@ -1281,8 +1317,8 @@ impl Step for Clippy {
12811317        let  mut  tarball = Tarball :: new ( builder,  "clippy" ,  & target. triple ) ; 
12821318        tarball. set_overlay ( OverlayKind :: Clippy ) ; 
12831319        tarball. is_preview ( true ) ; 
1284-         tarball . add_file ( clippy. tool_path ,  "bin" ,  0o755 ) ; 
1285-         tarball . add_file ( cargoclippy. tool_path ,  "bin" ,  0o755 ) ; 
1320+         tarball_add_binary ( & tarball ,   & clippy. tool_path ,  "bin" ,  target ) ; 
1321+         tarball_add_binary ( & tarball ,   & cargoclippy. tool_path ,  "bin" ,  target ) ; 
12861322        tarball. add_legal_and_readme_to ( "share/doc/clippy" ) ; 
12871323        Some ( tarball. generate ( ) ) 
12881324    } 
@@ -1331,8 +1367,8 @@ impl Step for Miri {
13311367        let  mut  tarball = Tarball :: new ( builder,  "miri" ,  & target. triple ) ; 
13321368        tarball. set_overlay ( OverlayKind :: Miri ) ; 
13331369        tarball. is_preview ( true ) ; 
1334-         tarball . add_file ( miri. tool_path ,  "bin" ,  0o755 ) ; 
1335-         tarball . add_file ( cargomiri. tool_path ,  "bin" ,  0o755 ) ; 
1370+         tarball_add_binary ( & tarball ,   & miri. tool_path ,  "bin" ,  target ) ; 
1371+         tarball_add_binary ( & tarball ,   & cargomiri. tool_path ,  "bin" ,  target ) ; 
13361372        tarball. add_legal_and_readme_to ( "share/doc/miri" ) ; 
13371373        Some ( tarball. generate ( ) ) 
13381374    } 
@@ -1416,7 +1452,12 @@ impl Step for CodegenBackend {
14161452        for  backend in  fs:: read_dir ( & backends_src) . unwrap ( )  { 
14171453            let  file_name = backend. unwrap ( ) . file_name ( ) ; 
14181454            if  file_name. to_str ( ) . unwrap ( ) . contains ( & backend_name)  { 
1419-                 tarball. add_file ( backends_src. join ( file_name) ,  & backends_dst,  0o644 ) ; 
1455+                 tarball_add_binary ( 
1456+                     & tarball, 
1457+                     & backends_src. join ( file_name) , 
1458+                     & backends_dst, 
1459+                     compiler. host , 
1460+                 ) ; 
14201461                found_backend = true ; 
14211462            } 
14221463        } 
@@ -1462,8 +1503,8 @@ impl Step for Rustfmt {
14621503        let  mut  tarball = Tarball :: new ( builder,  "rustfmt" ,  & target. triple ) ; 
14631504        tarball. set_overlay ( OverlayKind :: Rustfmt ) ; 
14641505        tarball. is_preview ( true ) ; 
1465-         tarball . add_file ( rustfmt. tool_path ,  "bin" ,  0o755 ) ; 
1466-         tarball . add_file ( cargofmt. tool_path ,  "bin" ,  0o755 ) ; 
1506+         tarball_add_binary ( & tarball ,   & rustfmt. tool_path ,  "bin" ,  target ) ; 
1507+         tarball_add_binary ( & tarball ,   & cargofmt. tool_path ,  "bin" ,  target ) ; 
14671508        tarball. add_legal_and_readme_to ( "share/doc/rustfmt" ) ; 
14681509        Some ( tarball. generate ( ) ) 
14691510    } 
@@ -2229,7 +2270,7 @@ impl Step for LlvmTools {
22292270            let  dst_bindir = format ! ( "lib/rustlib/{}/bin" ,  target. triple) ; 
22302271            for  tool in  tools_to_install ( & builder. paths )  { 
22312272                let  exe = src_bindir. join ( exe ( tool,  target) ) ; 
2232-                 tarball . add_file ( & exe,  & dst_bindir,  0o755 ) ; 
2273+                 tarball_add_binary ( & tarball ,   & exe,  & dst_bindir,  target ) ; 
22332274            } 
22342275        } 
22352276
@@ -2284,7 +2325,7 @@ impl Step for LlvmBitcodeLinker {
22842325        tarball. set_overlay ( OverlayKind :: LlvmBitcodeLinker ) ; 
22852326        tarball. is_preview ( true ) ; 
22862327
2287-         tarball . add_file ( llbc_linker. tool_path ,  self_contained_bin_dir,  0o755 ) ; 
2328+         tarball_add_binary ( & tarball ,   & llbc_linker. tool_path ,  self_contained_bin_dir,  target ) ; 
22882329
22892330        Some ( tarball. generate ( ) ) 
22902331    } 
@@ -2345,7 +2386,7 @@ impl Step for RustDev {
23452386                let  entry = t ! ( entry) ; 
23462387                if  entry. file_type ( ) . is_file ( )  && !entry. path_is_symlink ( )  { 
23472388                    let  name = entry. file_name ( ) . to_str ( ) . unwrap ( ) ; 
2348-                     tarball . add_file ( src_bindir. join ( name) ,  "bin" ,  0o755 ) ; 
2389+                     tarball_add_binary ( & tarball ,   & src_bindir. join ( name) ,  "bin" ,  target ) ; 
23492390                } 
23502391            } 
23512392        } 
@@ -2357,11 +2398,11 @@ impl Step for RustDev {
23572398            // We don't build LLD on some platforms, so only add it if it exists 
23582399            let  lld_path = lld_out. join ( "bin" ) . join ( exe ( "lld" ,  target) ) ; 
23592400            if  lld_path. exists ( )  { 
2360-                 tarball . add_file ( lld_path,  "bin" ,  0o755 ) ; 
2401+                 tarball_add_binary ( & tarball ,   & lld_path,  "bin" ,  target ) ; 
23612402            } 
23622403        } 
23632404
2364-         tarball . add_file ( builder. llvm_filecheck ( target) ,  "bin" ,  0o755 ) ; 
2405+         tarball_add_binary ( & tarball ,   & builder. llvm_filecheck ( target) ,  "bin" ,  target ) ; 
23652406
23662407        // Copy the include directory as well; needed mostly to build 
23672408        // librustc_llvm properly (e.g., llvm-config.h is in here). But also 
@@ -2422,7 +2463,12 @@ impl Step for Bootstrap {
24222463
24232464        let  bootstrap_outdir = & builder. bootstrap_out ; 
24242465        for  file in  & [ "bootstrap" ,  "rustc" ,  "rustdoc" ,  "sccache-plus-cl" ]  { 
2425-             tarball. add_file ( bootstrap_outdir. join ( exe ( file,  target) ) ,  "bootstrap/bin" ,  0o755 ) ; 
2466+             tarball_add_binary ( 
2467+                 & tarball, 
2468+                 & bootstrap_outdir. join ( exe ( file,  target) ) , 
2469+                 "bootstrap/bin" , 
2470+                 target, 
2471+             ) ; 
24262472        } 
24272473
24282474        Some ( tarball. generate ( ) ) 
@@ -2455,7 +2501,7 @@ impl Step for BuildManifest {
24552501        let  build_manifest = builder. tool_exe ( Tool :: BuildManifest ) ; 
24562502
24572503        let  tarball = Tarball :: new ( builder,  "build-manifest" ,  & self . target . triple ) ; 
2458-         tarball . add_file ( build_manifest,  "bin" ,  0o755 ) ; 
2504+         tarball_add_binary ( & tarball ,   & build_manifest,  "bin" ,  self . target ) ; 
24592505        tarball. generate ( ) 
24602506    } 
24612507} 
@@ -2524,7 +2570,7 @@ impl Step for Gcc {
25242570    fn  run ( self ,  builder :  & Builder < ' _ > )  -> Self :: Output  { 
25252571        let  tarball = Tarball :: new ( builder,  "gcc" ,  & self . target . triple ) ; 
25262572        let  output = builder. ensure ( super :: gcc:: Gcc  {  target :  self . target  } ) ; 
2527-         tarball . add_file ( output. libgccjit ,  "." ,  0o644 ) ; 
2573+         tarball_add_binary ( & tarball ,   & output. libgccjit ,  "." ,  self . target ) ; 
25282574        tarball. generate ( ) 
25292575    } 
25302576} 
0 commit comments