mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Fix fallback to cargo-install
: Use the default target unless user override (#1430)
* Fix fallback to `cargo-install`: Use the default target which is guaranteed to work, instead of providing a custom `--target` from `detect-targets`. The one from `detect-targets` might report musl even if the `rustc` reports gnu, since OSes like NixOS could use a custom glibc location that prevent glibc binaries built for other OSes be run for them. However, if we are compiling the crate and `rustc` defaults to glibc, then it should be guaranteed to work. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Impl fn `DesiredTargets::get_initialized` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix fallback to `cargo-install`: Use user-provided override targets Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
b56a8c3579
commit
8e08c65946
2 changed files with 22 additions and 11 deletions
|
@ -126,10 +126,11 @@ impl ResolutionFetch {
|
|||
|
||||
impl ResolutionSource {
|
||||
pub async fn install(self, opts: Arc<Options>) -> Result<(), BinstallError> {
|
||||
let desired_targets = opts.desired_targets.get().await;
|
||||
let target = desired_targets
|
||||
.first()
|
||||
.ok_or(BinstallError::NoViableTargets)?;
|
||||
let target = if let Some(targets) = opts.desired_targets.get_initialized() {
|
||||
Some(targets.first().ok_or(BinstallError::NoViableTargets)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let name = &self.name;
|
||||
let version = &self.version;
|
||||
|
@ -138,21 +139,18 @@ impl ResolutionSource {
|
|||
.map(Cow::Owned)
|
||||
.unwrap_or_else(|| Cow::Borrowed(OsStr::new("cargo")));
|
||||
|
||||
debug!(
|
||||
"Running `{} install {name} --version {version} --target {target}`",
|
||||
Path::new(&cargo).display(),
|
||||
);
|
||||
|
||||
let mut cmd = Command::new(cargo);
|
||||
|
||||
cmd.arg("install")
|
||||
.arg(name)
|
||||
.arg("--version")
|
||||
.arg(version)
|
||||
.arg("--target")
|
||||
.arg(target)
|
||||
.kill_on_drop(true);
|
||||
|
||||
if let Some(target) = target {
|
||||
cmd.arg("--target").arg(target);
|
||||
}
|
||||
|
||||
if opts.quiet {
|
||||
cmd.arg("--quiet");
|
||||
}
|
||||
|
@ -173,6 +171,8 @@ impl ResolutionSource {
|
|||
cmd.arg("--no-track");
|
||||
}
|
||||
|
||||
debug!("Running `{}`", format_cmd(&cmd),);
|
||||
|
||||
if !opts.dry_run {
|
||||
let mut child = opts
|
||||
.jobserver_client
|
||||
|
|
|
@ -41,6 +41,17 @@ impl DesiredTargets {
|
|||
AutoDetect(once_cell) => once_cell.get_or_init(detect_targets).await,
|
||||
}
|
||||
}
|
||||
|
||||
/// If `DesiredTargets` is provided with a list of desired targets instead
|
||||
/// of detecting the targets, then this function would return `Some`.
|
||||
pub fn get_initialized(&self) -> Option<&[String]> {
|
||||
use DesiredTargetsInner::*;
|
||||
|
||||
match &self.0 {
|
||||
Initialized(targets) => Some(targets),
|
||||
AutoDetect(..) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If opts_targets is `Some`, then it will be used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue