Skip to content

Commit a6077d8

Browse files
committed
add aix is_dylib
1 parent 86d69c7 commit a6077d8

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ impl Step for CodegenBackend {
14581458
}
14591459
let mut files = files.into_iter().filter(|f| {
14601460
let filename = f.file_name().unwrap().to_str().unwrap();
1461-
is_dylib(filename) && filename.contains("rustc_codegen_")
1461+
is_dylib(f) && filename.contains("rustc_codegen_")
14621462
});
14631463
let codegen_backend = match files.next() {
14641464
Some(f) => f,
@@ -1936,7 +1936,7 @@ impl Step for Assemble {
19361936
let filename = f.file_name().into_string().unwrap();
19371937

19381938
let is_proc_macro = proc_macros.contains(&filename);
1939-
let is_dylib_or_debug = is_dylib(&filename) || is_debug_info(&filename);
1939+
let is_dylib_or_debug = is_dylib(&f.path()) || is_debug_info(&filename);
19401940

19411941
// If we link statically to stdlib, do not copy the libstd dynamic library file
19421942
// FIXME: Also do this for Windows once incremental post-optimization stage0 tests
@@ -2077,7 +2077,7 @@ pub fn run_cargo(
20772077
if filename.ends_with(".lib")
20782078
|| filename.ends_with(".a")
20792079
|| is_debug_info(&filename)
2080-
|| is_dylib(&filename)
2080+
|| is_dylib(Path::new(&*filename))
20812081
{
20822082
// Always keep native libraries, rust dylibs and debuginfo
20832083
keep = true;
@@ -2177,7 +2177,7 @@ pub fn run_cargo(
21772177
Some(triple) => triple.0.to_str().unwrap(),
21782178
None => panic!("no output generated for {prefix:?} {extension:?}"),
21792179
};
2180-
if is_dylib(path_to_add) {
2180+
if is_dylib(&Path::new(path_to_add)) {
21812181
let candidate = format!("{path_to_add}.lib");
21822182
let candidate = PathBuf::from(candidate);
21832183
if candidate.exists() {

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,10 @@ impl Step for Rustc {
436436
if libdir_relative.to_str() != Some("bin") {
437437
let libdir = builder.rustc_libdir(compiler);
438438
for entry in builder.read_dir(&libdir) {
439-
let name = entry.file_name();
440-
if let Some(s) = name.to_str() {
441-
if is_dylib(s) {
442-
// Don't use custom libdir here because ^lib/ will be resolved again
443-
// with installer
444-
builder.install(&entry.path(), &image.join("lib"), 0o644);
445-
}
439+
if is_dylib(entry.path().as_path()) {
440+
// Don't use custom libdir here because ^lib/ will be resolved again
441+
// with installer
442+
builder.install(&entry.path(), &image.join("lib"), 0o644);
446443
}
447444
}
448445
}

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,8 +2937,7 @@ impl Step for RemoteCopyLibs {
29372937
// Push all our dylibs to the emulator
29382938
for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
29392939
let f = t!(f);
2940-
let name = f.file_name().into_string().unwrap();
2941-
if helpers::is_dylib(&name) {
2940+
if helpers::is_dylib(f.path().as_path()) {
29422941
command(&tool).arg("push").arg(f.path()).run(builder);
29432942
}
29442943
}

src/bootstrap/src/utils/helpers.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! not a lot of interesting happenings here unfortunately.
55
66
use std::ffi::OsStr;
7+
use std::fs::File;
8+
use std::io::Read;
79
use std::path::{Path, PathBuf};
810
use std::process::{Command, Stdio};
911
use std::sync::OnceLock;
@@ -52,9 +54,22 @@ pub fn exe(name: &str, target: TargetSelection) -> String {
5254
crate::utils::shared_helpers::exe(name, &target.triple)
5355
}
5456

57+
/// On AIX, both static library and dynamic library end with '.a'. One is bigaf format,
58+
/// one is in xcoff format.
59+
fn is_aix_dylib(path: &Path) -> bool {
60+
let mut buffer = [0u8; 2];
61+
match File::open(path).and_then(|mut f| f.read_exact(&mut buffer)) {
62+
Ok(_) => matches!(buffer, [0x01, 0xF7]),
63+
Err(_) => false,
64+
}
65+
}
66+
5567
/// Returns `true` if the file name given looks like a dynamic library.
56-
pub fn is_dylib(name: &str) -> bool {
57-
name.ends_with(".dylib") || name.ends_with(".so") || name.ends_with(".dll")
68+
pub fn is_dylib(path: &Path) -> bool {
69+
match path.extension().and_then(|ext| ext.to_str()) {
70+
Some(name) => matches!(name, "dylib" | "so" | "dll") || (name == "a" && is_aix_dylib(path)),
71+
None => false,
72+
}
5873
}
5974

6075
/// Returns `true` if the file name given looks like a debug info file

0 commit comments

Comments
 (0)