@@ -32,7 +32,7 @@ use crate::utils::helpers::{
32
32
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
33
33
} ;
34
34
use 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} ;
36
36
37
37
pub fn pkgname ( builder : & Builder < ' _ > , component : & str ) -> String {
38
38
format ! ( "{}-{}" , component, builder. rust_package_vers( ) )
@@ -53,6 +53,22 @@ fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
53
53
builder. config . tools . as_ref ( ) . is_none_or ( |tools| tools. contains ( tool) )
54
54
}
55
55
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
+
56
72
#[ derive( Debug , PartialOrd , Ord , Clone , Hash , PartialEq , Eq ) ]
57
73
pub struct Docs {
58
74
pub host : TargetSelection ,
@@ -432,7 +448,14 @@ impl Step for Rustc {
432
448
} ,
433
449
builder. kind ,
434
450
) {
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
+ }
436
459
}
437
460
438
461
let libdir_relative = builder. libdir_relative ( compiler) ;
@@ -463,15 +486,20 @@ impl Step for Rustc {
463
486
if builder. config . lld_enabled {
464
487
let src_dir = builder. sysroot_target_bindir ( compiler, host) ;
465
488
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
+ ) ;
467
494
let self_contained_lld_src_dir = src_dir. join ( "gcc-ld" ) ;
468
495
let self_contained_lld_dst_dir = dst_dir. join ( "gcc-ld" ) ;
469
496
t ! ( fs:: create_dir( & self_contained_lld_dst_dir) ) ;
470
497
for name in crate :: LLD_FILE_NAMES {
471
498
let exe_name = exe ( name, compiler. host ) ;
472
- builder. copy_link (
499
+ builder. copy_link_binary (
473
500
& self_contained_lld_src_dir. join ( & exe_name) ,
474
501
& self_contained_lld_dst_dir. join ( & exe_name) ,
502
+ host,
475
503
) ;
476
504
}
477
505
}
@@ -480,13 +508,17 @@ impl Step for Rustc {
480
508
let src_dir = builder. sysroot_target_bindir ( compiler, host) ;
481
509
let llvm_objcopy = exe ( "llvm-objcopy" , compiler. host ) ;
482
510
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
+ ) ;
484
516
}
485
517
486
518
if builder. tool_enabled ( "wasm-component-ld" ) {
487
519
let src_dir = builder. sysroot_target_bindir ( compiler, host) ;
488
520
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 ) ;
490
522
}
491
523
492
524
// Man pages
@@ -640,9 +672,13 @@ fn copy_target_libs(
640
672
t ! ( fs:: create_dir_all( & self_contained_dst) ) ;
641
673
for ( path, dependency_type) in builder. read_stamp_file ( stamp) {
642
674
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
+ ) ;
644
680
} 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 ) ;
646
682
}
647
683
}
648
684
}
@@ -1147,7 +1183,7 @@ impl Step for Cargo {
1147
1183
let mut tarball = Tarball :: new ( builder, "cargo" , & target. triple ) ;
1148
1184
tarball. set_overlay ( OverlayKind :: Cargo ) ;
1149
1185
1150
- tarball . add_file ( cargo. tool_path , "bin" , 0o755 ) ;
1186
+ tarball_add_binary ( & tarball , & cargo. tool_path , "bin" , target ) ;
1151
1187
tarball. add_file ( etc. join ( "_cargo" ) , "share/zsh/site-functions" , 0o644 ) ;
1152
1188
tarball. add_renamed_file ( etc. join ( "cargo.bashcomp.sh" ) , "etc/bash_completion.d" , "cargo" ) ;
1153
1189
tarball. add_dir ( etc. join ( "man" ) , "share/man/man1" ) ;
@@ -1193,7 +1229,7 @@ impl Step for Rls {
1193
1229
let mut tarball = Tarball :: new ( builder, "rls" , & target. triple ) ;
1194
1230
tarball. set_overlay ( OverlayKind :: Rls ) ;
1195
1231
tarball. is_preview ( true ) ;
1196
- tarball . add_file ( rls. tool_path , "bin" , 0o755 ) ;
1232
+ tarball_add_binary ( & tarball , & rls. tool_path , "bin" , target ) ;
1197
1233
tarball. add_legal_and_readme_to ( "share/doc/rls" ) ;
1198
1234
Some ( tarball. generate ( ) )
1199
1235
}
@@ -1235,7 +1271,7 @@ impl Step for RustAnalyzer {
1235
1271
let mut tarball = Tarball :: new ( builder, "rust-analyzer" , & target. triple ) ;
1236
1272
tarball. set_overlay ( OverlayKind :: RustAnalyzer ) ;
1237
1273
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 ) ;
1239
1275
tarball. add_legal_and_readme_to ( "share/doc/rust-analyzer" ) ;
1240
1276
Some ( tarball. generate ( ) )
1241
1277
}
@@ -1281,8 +1317,8 @@ impl Step for Clippy {
1281
1317
let mut tarball = Tarball :: new ( builder, "clippy" , & target. triple ) ;
1282
1318
tarball. set_overlay ( OverlayKind :: Clippy ) ;
1283
1319
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 ) ;
1286
1322
tarball. add_legal_and_readme_to ( "share/doc/clippy" ) ;
1287
1323
Some ( tarball. generate ( ) )
1288
1324
}
@@ -1331,8 +1367,8 @@ impl Step for Miri {
1331
1367
let mut tarball = Tarball :: new ( builder, "miri" , & target. triple ) ;
1332
1368
tarball. set_overlay ( OverlayKind :: Miri ) ;
1333
1369
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 ) ;
1336
1372
tarball. add_legal_and_readme_to ( "share/doc/miri" ) ;
1337
1373
Some ( tarball. generate ( ) )
1338
1374
}
@@ -1416,7 +1452,12 @@ impl Step for CodegenBackend {
1416
1452
for backend in fs:: read_dir ( & backends_src) . unwrap ( ) {
1417
1453
let file_name = backend. unwrap ( ) . file_name ( ) ;
1418
1454
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
+ ) ;
1420
1461
found_backend = true ;
1421
1462
}
1422
1463
}
@@ -1462,8 +1503,8 @@ impl Step for Rustfmt {
1462
1503
let mut tarball = Tarball :: new ( builder, "rustfmt" , & target. triple ) ;
1463
1504
tarball. set_overlay ( OverlayKind :: Rustfmt ) ;
1464
1505
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 ) ;
1467
1508
tarball. add_legal_and_readme_to ( "share/doc/rustfmt" ) ;
1468
1509
Some ( tarball. generate ( ) )
1469
1510
}
@@ -2229,7 +2270,7 @@ impl Step for LlvmTools {
2229
2270
let dst_bindir = format ! ( "lib/rustlib/{}/bin" , target. triple) ;
2230
2271
for tool in tools_to_install ( & builder. paths ) {
2231
2272
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 ) ;
2233
2274
}
2234
2275
}
2235
2276
@@ -2284,7 +2325,7 @@ impl Step for LlvmBitcodeLinker {
2284
2325
tarball. set_overlay ( OverlayKind :: LlvmBitcodeLinker ) ;
2285
2326
tarball. is_preview ( true ) ;
2286
2327
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 ) ;
2288
2329
2289
2330
Some ( tarball. generate ( ) )
2290
2331
}
@@ -2345,7 +2386,7 @@ impl Step for RustDev {
2345
2386
let entry = t ! ( entry) ;
2346
2387
if entry. file_type ( ) . is_file ( ) && !entry. path_is_symlink ( ) {
2347
2388
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 ) ;
2349
2390
}
2350
2391
}
2351
2392
}
@@ -2357,11 +2398,11 @@ impl Step for RustDev {
2357
2398
// We don't build LLD on some platforms, so only add it if it exists
2358
2399
let lld_path = lld_out. join ( "bin" ) . join ( exe ( "lld" , target) ) ;
2359
2400
if lld_path. exists ( ) {
2360
- tarball . add_file ( lld_path, "bin" , 0o755 ) ;
2401
+ tarball_add_binary ( & tarball , & lld_path, "bin" , target ) ;
2361
2402
}
2362
2403
}
2363
2404
2364
- tarball . add_file ( builder. llvm_filecheck ( target) , "bin" , 0o755 ) ;
2405
+ tarball_add_binary ( & tarball , & builder. llvm_filecheck ( target) , "bin" , target ) ;
2365
2406
2366
2407
// Copy the include directory as well; needed mostly to build
2367
2408
// librustc_llvm properly (e.g., llvm-config.h is in here). But also
@@ -2422,7 +2463,12 @@ impl Step for Bootstrap {
2422
2463
2423
2464
let bootstrap_outdir = & builder. bootstrap_out ;
2424
2465
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
+ ) ;
2426
2472
}
2427
2473
2428
2474
Some ( tarball. generate ( ) )
@@ -2455,7 +2501,7 @@ impl Step for BuildManifest {
2455
2501
let build_manifest = builder. tool_exe ( Tool :: BuildManifest ) ;
2456
2502
2457
2503
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 ) ;
2459
2505
tarball. generate ( )
2460
2506
}
2461
2507
}
@@ -2524,7 +2570,7 @@ impl Step for Gcc {
2524
2570
fn run ( self , builder : & Builder < ' _ > ) -> Self :: Output {
2525
2571
let tarball = Tarball :: new ( builder, "gcc" , & self . target . triple ) ;
2526
2572
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 ) ;
2528
2574
tarball. generate ( )
2529
2575
}
2530
2576
}
0 commit comments