Warn if the MUSL target is missing when using --musl

This commit is contained in:
Colin Woodbury
2020-08-11 14:14:26 -07:00
parent b1383ff6ff
commit 8e223c5a2d
2 changed files with 30 additions and 0 deletions

View File

@@ -2,6 +2,11 @@
## Unreleased
#### Added
- When using `--musl`, the user is warned if they don't have the
`x86_64-unknown-linux-musl` target installed.
#### Changed
- Run `strip` on the release binary before `tar`ring it.

View File

@@ -1,9 +1,11 @@
use anyhow::anyhow;
use gumdrop::{Options, ParsingStyle};
use hmac_sha256::Hash;
use itertools::Itertools;
use serde_derive::Deserialize;
use std::fs;
use std::process::{self, Command};
use std::str;
#[derive(Options)]
struct Args {
@@ -79,6 +81,12 @@ fn main() {
}
fn work(args: Args) -> anyhow::Result<()> {
// We can't proceed if the user has specified `--musl` but doesn't have the
// target installed.
if args.musl {
musl_check()?
}
let config = cargo_config()?;
release_build(args.musl)?;
tarball(args.musl, &config.package)?;
@@ -179,3 +187,20 @@ fn sha256sum(package: &Package) -> anyhow::Result<String> {
let hex = digest.iter().map(|u| format!("{:02x}", u)).collect();
Ok(hex)
}
/// Does the user have the `x86_64-unknown-linux-musl` target installed?
fn musl_check() -> anyhow::Result<()> {
let args = vec!["target", "list", "--installed"];
let output = Command::new("rustup").args(args).output()?.stdout;
let installed = str::from_utf8(&output)?
.lines()
.any(|tc| tc == "x86_64-unknown-linux-musl");
if installed {
Ok(())
} else {
Err(anyhow!(
"Missing target! Try: rustup target add x86_64-unknown-linux-musl"
))
}
}