mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 15:07:59 +00:00
wasm-builder: allow default cargo nightly (#3195)
* wasm-builder: use default cargo command if nightly is default toolchain * wasm-builder: use get_nightly_cargo in prereq check * wasm-builder: fix check_nightly_installed * wasm-builder: add cargo command builder struct * wasm-builder: remove unnecessary stuff * wasm-builder: just use Strings
This commit is contained in:
committed by
Bastian Köcher
parent
f7ff339ebd
commit
407970406d
@@ -151,18 +151,66 @@ fn create_out_file(file_name: &str, content: String) {
|
||||
}
|
||||
|
||||
/// Get a cargo command that compiles with nightly
|
||||
fn get_nightly_cargo() -> Command {
|
||||
if Command::new("rustup")
|
||||
.args(&["run", "nightly", "cargo"])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.map(|s| s.success()).unwrap_or(false)
|
||||
{
|
||||
let mut cmd = Command::new("rustup");
|
||||
cmd.args(&["run", "nightly", "cargo"]);
|
||||
cmd
|
||||
fn get_nightly_cargo() -> CargoCommand {
|
||||
let default_cargo = CargoCommand::new("cargo");
|
||||
let mut rustup_run_nightly = CargoCommand::new("rustup");
|
||||
rustup_run_nightly.args(&["run", "nightly", "cargo"]);
|
||||
|
||||
if default_cargo.is_nightly() {
|
||||
default_cargo
|
||||
} else if rustup_run_nightly.works() {
|
||||
rustup_run_nightly
|
||||
} else {
|
||||
Command::new("cargo")
|
||||
default_cargo
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder for cargo commands
|
||||
#[derive(Debug)]
|
||||
struct CargoCommand {
|
||||
program: String,
|
||||
args: Vec<String>,
|
||||
}
|
||||
|
||||
impl CargoCommand {
|
||||
fn new(program: &str) -> Self {
|
||||
CargoCommand { program: program.into(), args: Vec::new() }
|
||||
}
|
||||
|
||||
fn arg(&mut self, arg: &str) -> &mut Self {
|
||||
self.args.push(arg.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn args(&mut self, args: &[&str]) -> &mut Self {
|
||||
for arg in args {
|
||||
self.arg(arg);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
fn command(&self) -> Command {
|
||||
let mut cmd = Command::new(&self.program);
|
||||
cmd.args(&self.args);
|
||||
cmd
|
||||
}
|
||||
|
||||
fn works(&self) -> bool {
|
||||
self.command()
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.map(|s| s.success()).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Check if the supplied cargo command is a nightly version
|
||||
fn is_nightly(&self) -> bool {
|
||||
self.command()
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|_| ())
|
||||
.and_then(|o| String::from_utf8(o.stdout).map_err(|_| ()))
|
||||
.unwrap_or_default()
|
||||
.contains("-nightly")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,21 +44,8 @@ pub fn check() -> Option<&'static str> {
|
||||
}
|
||||
|
||||
fn check_nightly_installed() -> bool {
|
||||
let version = Command::new("cargo")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|_| ())
|
||||
.and_then(|o| String::from_utf8(o.stdout).map_err(|_| ()))
|
||||
.unwrap_or_default();
|
||||
|
||||
let version2 = Command::new("rustup")
|
||||
.args(&["run", "nightly", "cargo", "--version"])
|
||||
.output()
|
||||
.map_err(|_| ())
|
||||
.and_then(|o| String::from_utf8(o.stdout).map_err(|_| ()))
|
||||
.unwrap_or_default();
|
||||
|
||||
version.contains("-nightly") || version2.contains("-nightly")
|
||||
let command = crate::get_nightly_cargo();
|
||||
command.is_nightly()
|
||||
}
|
||||
|
||||
fn check_wasm_toolchain_installed() -> bool {
|
||||
@@ -87,10 +74,11 @@ fn check_wasm_toolchain_installed() -> bool {
|
||||
|
||||
let manifest_path = manifest_path.display().to_string();
|
||||
crate::get_nightly_cargo()
|
||||
.command()
|
||||
.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path])
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ fn is_release_build() -> bool {
|
||||
/// Build the project to create the WASM binary.
|
||||
fn build_project(project: &Path) {
|
||||
let manifest_path = project.join("Cargo.toml");
|
||||
let mut build_cmd = crate::get_nightly_cargo();
|
||||
let mut build_cmd = crate::get_nightly_cargo().command();
|
||||
|
||||
let rustflags = format!(
|
||||
"-C link-arg=--export-table {}",
|
||||
|
||||
Reference in New Issue
Block a user