Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

replace cc_detect::cc2ar with cc::try_get_archiver #140994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4 src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ dependencies = [

[[package]]
name = "cc"
version = "1.2.17"
version = "1.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a"
checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
dependencies = [
"shlex",
]
Expand Down
2 changes: 1 addition & 1 deletion 2 src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test = false
# Most of the time updating these dependencies requires modifications to the
# bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565);
# otherwise, some targets will fail. That's why these dependencies are explicitly pinned.
cc = "=1.2.17"
cc = "=1.2.23"
cmake = "=0.1.54"

build_helper = { path = "../build_helper" }
Expand Down
34 changes: 2 additions & 32 deletions 34 src/bootstrap/src/utils/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,13 @@
//! everything.

use std::collections::HashSet;
use std::iter;
use std::path::{Path, PathBuf};
use std::{env, iter};

use crate::core::config::TargetSelection;
use crate::utils::exec::{BootstrapCommand, command};
use crate::{Build, CLang, GitRepo};

/// Finds archiver tool for the given target if possible.
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> {
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) {
Some(PathBuf::from(ar))
} else if let Some(ar) = env::var_os("AR") {
Some(PathBuf::from(ar))
} else if target.is_msvc() {
None
} else if target.contains("musl") || target.contains("openbsd") {
Some(PathBuf::from("ar"))
} else if target.contains("vxworks") {
Some(PathBuf::from("wr-ar"))
} else if target.contains("-nto-") {
if target.starts_with("i586") {
Some(PathBuf::from("ntox86-ar"))
} else if target.starts_with("aarch64") {
Some(PathBuf::from("ntoaarch64-ar"))
} else if target.starts_with("x86_64") {
Some(PathBuf::from("ntox86_64-ar"))
} else {
panic!("Unknown architecture, cannot determine archiver for Neutrino QNX");
}
} else if target.contains("android") || target.contains("-wasi") {
Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar")))
} else {
Some(default_ar)
}
}

/// Creates and configures a new [`cc::Build`] instance for the given target.
fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
let mut cfg = cc::Build::new();
Expand Down Expand Up @@ -140,7 +110,7 @@ pub fn find_target(build: &Build, target: TargetSelection) {
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
ar
} else {
cc2ar(compiler.path(), target, PathBuf::from(cfg.get_archiver().get_program()))
cfg.try_get_archiver().map(|c| PathBuf::from(c.get_program())).ok()
};

build.cc.borrow_mut().insert(target, compiler.clone());
Expand Down
113 changes: 0 additions & 113 deletions 113 src/bootstrap/src/utils/cc_detect/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,119 +5,6 @@ use super::*;
use crate::core::config::{Target, TargetSelection};
use crate::{Build, Config, Flags};

#[test]
fn test_cc2ar_env_specific() {
let triple = "x86_64-unknown-linux-gnu";
let key = "AR_x86_64_unknown_linux_gnu";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::set_var(key, "custom-ar") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var(key) };
assert_eq!(result, Some(PathBuf::from("custom-ar")));
}

#[test]
fn test_cc2ar_musl() {
let triple = "x86_64-unknown-linux-musl";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_x86_64_unknown_linux_musl") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("ar")));
}

#[test]
fn test_cc2ar_openbsd() {
let triple = "x86_64-unknown-openbsd";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_x86_64_unknown_openbsd") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/cc");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("ar")));
}

#[test]
fn test_cc2ar_vxworks() {
let triple = "armv7-wrs-vxworks";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_armv7_wrs_vxworks") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("wr-ar")));
}

#[test]
fn test_cc2ar_nto_i586() {
let triple = "i586-unknown-nto-something";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_i586_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("ntox86-ar")));
}

#[test]
fn test_cc2ar_nto_aarch64() {
let triple = "aarch64-unknown-nto-something";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_aarch64_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("ntoaarch64-ar")));
}

#[test]
fn test_cc2ar_nto_x86_64() {
let triple = "x86_64-unknown-nto-something";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_x86_64_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let result = cc2ar(cc, target, default_ar);
assert_eq!(result, Some(PathBuf::from("ntox86_64-ar")));
}

#[test]
#[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")]
fn test_cc2ar_nto_unknown() {
let triple = "powerpc-unknown-nto-something";
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR_powerpc_unknown_nto_something") };
// SAFETY: bootstrap tests run on a single thread
unsafe { env::remove_var("AR") };
let target = TargetSelection::from_user(triple);
let cc = Path::new("/usr/bin/clang");
let default_ar = PathBuf::from("default-ar");
let _ = cc2ar(cc, target, default_ar);
}

#[test]
fn test_ndk_compiler_c() {
let ndk_path = PathBuf::from("/ndk");
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.