mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Use CARGO
env variable if present (#453)
* Run `$CARGO -vV` in `detect-targets` if env `CARGO` present * Improve crate doc for `detect-targets` * Use env var `CARGO` in `install_from_source` if present * Test use of `CARGO` env in `tests.sh` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
448542f0c8
commit
ec2bdb551e
5 changed files with 48 additions and 18 deletions
|
@ -1,4 +1,7 @@
|
|||
use std::{
|
||||
borrow::Cow,
|
||||
env,
|
||||
ffi::OsStr,
|
||||
io::{BufRead, Cursor},
|
||||
process::{Output, Stdio},
|
||||
};
|
||||
|
@ -65,8 +68,17 @@ pub async fn detect_targets() -> Vec<String> {
|
|||
|
||||
/// Figure out what the host target is using `rustc`.
|
||||
/// If `rustc` is absent, then it would return `None`.
|
||||
///
|
||||
/// If environment variable `CARGO` is present, then
|
||||
/// `$CARGO -vV` will be run instead.
|
||||
///
|
||||
/// Otherwise, it will run `rustc -vV` to detect target.
|
||||
async fn get_target_from_rustc() -> Option<String> {
|
||||
let Output { status, stdout, .. } = Command::new("rustc")
|
||||
let cmd = env::var_os("CARGO")
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or_else(|| Cow::Borrowed(OsStr::new("rustc")));
|
||||
|
||||
let Output { status, stdout, .. } = Command::new(cmd)
|
||||
.arg("-vV")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
//! Detect the target at the runtime.
|
||||
//!
|
||||
//! It runs `$CARGO -vV` if environment variable `CARGO` is present
|
||||
//! for cargo subcommands, otherwise it would try running `rustc -vV`.
|
||||
//!
|
||||
//! If both `rustc` isn't present on the system, it will fallback
|
||||
//! to using syscalls plus `ldd` on Linux to detect targets.
|
||||
//!
|
||||
//! Example use cases:
|
||||
//! - The binary is built with musl libc to run on anywhere, but
|
||||
//! the runtime supports glibc.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue