feat(cli): add feature to disable downloads (#3465)
* feat(cli): add feature to disable downloads --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
cd121f2828
commit
c7951b7dd5
11 files changed
+485
-536
No files matched your search
+367
-329
@@ -1,9 +1,8 @@
|
||||
use crate::{CliSettings, Result};
|
||||
use anyhow::{anyhow, Context};
|
||||
use flate2::read::GzDecoder;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Stdio,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use std::{path::Path, process::Stdio};
|
||||
use tar::Archive;
|
||||
use tempfile::TempDir;
|
||||
use tokio::{fs, process::Command};
|
||||
@@ -22,295 +21,9 @@ pub(crate) struct WasmBindgen {
|
||||
}
|
||||
|
||||
impl WasmBindgen {
|
||||
pub async fn run(&self) -> anyhow::Result<()> {
|
||||
let binary = Self::final_binary(&self.version).await?;
|
||||
|
||||
let mut args = Vec::new();
|
||||
|
||||
// Target
|
||||
args.push("--target");
|
||||
args.push(&self.target);
|
||||
|
||||
// Options
|
||||
if self.debug {
|
||||
args.push("--debug");
|
||||
}
|
||||
|
||||
if !self.demangle {
|
||||
args.push("--no-demangle");
|
||||
}
|
||||
|
||||
if self.keep_debug {
|
||||
args.push("--keep-debug");
|
||||
}
|
||||
|
||||
if self.remove_name_section {
|
||||
args.push("--remove-name-section");
|
||||
}
|
||||
|
||||
if self.remove_producers_section {
|
||||
args.push("--remove-producers-section");
|
||||
}
|
||||
|
||||
// wbg generates typescript bindnings by default - we don't want those
|
||||
args.push("--no-typescript");
|
||||
|
||||
// Out name
|
||||
args.push("--out-name");
|
||||
args.push(&self.out_name);
|
||||
|
||||
// Out dir
|
||||
let out_dir = self
|
||||
.out_dir
|
||||
.to_str()
|
||||
.expect("input_path should be valid utf8");
|
||||
|
||||
args.push("--out-dir");
|
||||
args.push(out_dir);
|
||||
|
||||
// Input path
|
||||
let input_path = self
|
||||
.input_path
|
||||
.to_str()
|
||||
.expect("input_path should be valid utf8");
|
||||
args.push(input_path);
|
||||
|
||||
// Run bindgen
|
||||
Command::new(binary)
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verify that the required wasm-bindgen version is installed.
|
||||
pub async fn verify_install(version: &str) -> anyhow::Result<bool> {
|
||||
let binary_name = Self::installed_bin_name(version);
|
||||
let path = Self::install_dir().await?.join(binary_name);
|
||||
Ok(path.exists())
|
||||
}
|
||||
|
||||
/// Install the specified wasm-bingen version.
|
||||
///
|
||||
/// This will overwrite any existing wasm-bindgen binaries of the same version.
|
||||
///
|
||||
/// This will attempt to install wasm-bindgen from:
|
||||
/// 1. Direct GitHub release download.
|
||||
/// 2. `cargo binstall` if installed.
|
||||
/// 3. Compile from source with `cargo install`.
|
||||
pub async fn install(version: &str) -> anyhow::Result<()> {
|
||||
tracing::info!("Installing wasm-bindgen-cli@{version}...");
|
||||
|
||||
// Attempt installation from GitHub
|
||||
if let Err(e) = Self::install_github(version).await {
|
||||
tracing::error!("Failed to install wasm-bindgen-cli@{version}: {e}");
|
||||
} else {
|
||||
tracing::info!("wasm-bindgen-cli@{version} was successfully installed from GitHub.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Attempt installation from binstall.
|
||||
if let Err(e) = Self::install_binstall(version).await {
|
||||
tracing::error!("Failed to install wasm-bindgen-cli@{version}: {e}");
|
||||
tracing::info!("Failed to install prebuilt binary for wasm-bindgen-cli@{version}. Compiling from source instead. This may take a while.");
|
||||
} else {
|
||||
tracing::info!(
|
||||
"wasm-bindgen-cli@{version} was successfully installed from cargo-binstall."
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Attempt installation from cargo.
|
||||
Self::install_cargo(version)
|
||||
.await
|
||||
.context("failed to install wasm-bindgen-cli from cargo")?;
|
||||
|
||||
tracing::info!("wasm-bindgen-cli@{version} was successfully installed from source.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Try installing wasm-bindgen-cli from GitHub.
|
||||
async fn install_github(version: &str) -> anyhow::Result<()> {
|
||||
tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from GitHub");
|
||||
|
||||
let url = git_install_url(version)
|
||||
.ok_or_else(|| anyhow!("no available GitHub binary for wasm-bindgen-cli@{version}"))?;
|
||||
|
||||
// Get the final binary location.
|
||||
let final_binary = Self::final_binary(version).await?;
|
||||
|
||||
// Download then extract wasm-bindgen-cli.
|
||||
let bytes = reqwest::get(url).await?.bytes().await?;
|
||||
|
||||
// Unpack the first tar entry to the final binary location
|
||||
Archive::new(GzDecoder::new(bytes.as_ref()))
|
||||
.entries()?
|
||||
.find(|entry| {
|
||||
entry
|
||||
.as_ref()
|
||||
.map(|e| {
|
||||
e.path_bytes()
|
||||
.ends_with(Self::downloaded_bin_name().as_bytes())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.context("Failed to find entry")??
|
||||
.unpack(&final_binary)
|
||||
.context("failed to unpack wasm-bindgen-cli binary")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Try installing wasm-bindgen-cli through cargo-binstall.
|
||||
async fn install_binstall(version: &str) -> anyhow::Result<()> {
|
||||
tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from cargo-binstall");
|
||||
|
||||
let package = Self::cargo_bin_name(version);
|
||||
let tempdir = TempDir::new()?;
|
||||
|
||||
// Run install command
|
||||
Command::new("cargo")
|
||||
.args([
|
||||
"binstall",
|
||||
&package,
|
||||
"--no-confirm",
|
||||
"--force",
|
||||
"--no-track",
|
||||
"--install-path",
|
||||
])
|
||||
.arg(tempdir.path())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
fs::copy(
|
||||
tempdir.path().join(Self::downloaded_bin_name()),
|
||||
Self::final_binary(version).await?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Try installing wasm-bindgen-cli from source using cargo install.
|
||||
async fn install_cargo(version: &str) -> anyhow::Result<()> {
|
||||
tracing::debug!("Attempting to install wasm-bindgen-cli@{version} from cargo-install");
|
||||
let package = Self::cargo_bin_name(version);
|
||||
let tempdir = TempDir::new()?;
|
||||
|
||||
// Run install command
|
||||
Command::new("cargo")
|
||||
.args([
|
||||
"install",
|
||||
&package,
|
||||
"--bin",
|
||||
"wasm-bindgen",
|
||||
"--no-track",
|
||||
"--force",
|
||||
"--root",
|
||||
])
|
||||
.arg(tempdir.path())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.context("failed to install wasm-bindgen-cli from cargo-install")?;
|
||||
|
||||
tracing::info!("Copying into path: {}", tempdir.path().display());
|
||||
|
||||
// copy the wasm-bindgen out of the tempdir to the final location
|
||||
fs::copy(
|
||||
tempdir.path().join("bin").join(Self::downloaded_bin_name()),
|
||||
Self::final_binary(version).await?,
|
||||
)
|
||||
.await
|
||||
.context("failed to copy wasm-bindgen binary")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the installation directory for the wasm-bindgen executable.
|
||||
async fn install_dir() -> anyhow::Result<PathBuf> {
|
||||
let bindgen_dir = dirs::data_local_dir()
|
||||
.expect("user should be running on a compatible operating system")
|
||||
.join("dioxus/wasm-bindgen/");
|
||||
|
||||
fs::create_dir_all(&bindgen_dir).await?;
|
||||
|
||||
Ok(bindgen_dir)
|
||||
}
|
||||
|
||||
/// Get the name of a potentially installed wasm-bindgen binary.
|
||||
fn installed_bin_name(version: &str) -> String {
|
||||
let mut name = format!("wasm-bindgen-{version}");
|
||||
if cfg!(windows) {
|
||||
name = format!("{name}.exe");
|
||||
}
|
||||
name
|
||||
}
|
||||
|
||||
/// Get the crates.io package name of wasm-bindgen-cli.
|
||||
fn cargo_bin_name(version: &str) -> String {
|
||||
format!("wasm-bindgen-cli@{version}")
|
||||
}
|
||||
|
||||
async fn final_binary(version: &str) -> Result<PathBuf, anyhow::Error> {
|
||||
let installed_name = Self::installed_bin_name(version);
|
||||
let install_dir = Self::install_dir().await?;
|
||||
Ok(install_dir.join(installed_name))
|
||||
}
|
||||
|
||||
fn downloaded_bin_name() -> &'static str {
|
||||
if cfg!(windows) {
|
||||
"wasm-bindgen.exe"
|
||||
} else {
|
||||
"wasm-bindgen"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the GitHub installation URL for wasm-bindgen if it exists.
|
||||
fn git_install_url(version: &str) -> Option<String> {
|
||||
let platform = if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
|
||||
"x86_64-pc-windows-msvc"
|
||||
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
|
||||
"x86_64-unknown-linux-musl"
|
||||
} else if cfg!(all(target_os = "linux", target_arch = "aarch64")) {
|
||||
"aarch64-unknown-linux-gnu"
|
||||
} else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
|
||||
"x86_64-apple-darwin"
|
||||
} else if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
|
||||
"aarch64-apple-darwin"
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(format!("https://github.com/rustwasm/wasm-bindgen/releases/download/{version}/wasm-bindgen-{version}-{platform}.tar.gz"))
|
||||
}
|
||||
|
||||
/// A builder for WasmBindgen options.
|
||||
pub(crate) struct WasmBindgenBuilder {
|
||||
version: String,
|
||||
input_path: PathBuf,
|
||||
out_dir: PathBuf,
|
||||
out_name: String,
|
||||
target: String,
|
||||
debug: bool,
|
||||
keep_debug: bool,
|
||||
demangle: bool,
|
||||
remove_name_section: bool,
|
||||
remove_producers_section: bool,
|
||||
}
|
||||
|
||||
impl WasmBindgenBuilder {
|
||||
pub fn new(version: String) -> Self {
|
||||
pub fn new(version: &str) -> Self {
|
||||
Self {
|
||||
version,
|
||||
version: version.to_string(),
|
||||
input_path: PathBuf::new(),
|
||||
out_dir: PathBuf::new(),
|
||||
out_name: String::new(),
|
||||
@@ -323,21 +36,6 @@ impl WasmBindgenBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self) -> WasmBindgen {
|
||||
WasmBindgen {
|
||||
version: self.version,
|
||||
input_path: self.input_path,
|
||||
out_dir: self.out_dir,
|
||||
out_name: self.out_name,
|
||||
target: self.target,
|
||||
debug: self.debug,
|
||||
keep_debug: self.keep_debug,
|
||||
demangle: self.demangle,
|
||||
remove_name_section: self.remove_name_section,
|
||||
remove_producers_section: self.remove_producers_section,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_path(self, input_path: &Path) -> Self {
|
||||
Self {
|
||||
input_path: input_path.to_path_buf(),
|
||||
@@ -391,6 +89,347 @@ impl WasmBindgenBuilder {
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the bindgen command with the current settings
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
let binary = self.get_binary_path().await?;
|
||||
|
||||
let mut args = Vec::new();
|
||||
|
||||
// Target
|
||||
args.push("--target");
|
||||
args.push(&self.target);
|
||||
|
||||
// Options
|
||||
if self.debug {
|
||||
args.push("--debug");
|
||||
}
|
||||
|
||||
if !self.demangle {
|
||||
args.push("--no-demangle");
|
||||
}
|
||||
|
||||
if self.keep_debug {
|
||||
args.push("--keep-debug");
|
||||
}
|
||||
|
||||
if self.remove_name_section {
|
||||
args.push("--remove-name-section");
|
||||
}
|
||||
|
||||
if self.remove_producers_section {
|
||||
args.push("--remove-producers-section");
|
||||
}
|
||||
|
||||
// Out name
|
||||
args.push("--out-name");
|
||||
args.push(&self.out_name);
|
||||
|
||||
// wbg generates typescript bindnings by default - we don't want those
|
||||
args.push("--no-typescript");
|
||||
|
||||
// Out dir
|
||||
let out_dir = self
|
||||
.out_dir
|
||||
.to_str()
|
||||
.expect("input_path should be valid utf8");
|
||||
|
||||
args.push("--out-dir");
|
||||
args.push(out_dir);
|
||||
|
||||
// Input path
|
||||
let input_path = self
|
||||
.input_path
|
||||
.to_str()
|
||||
.expect("input_path should be valid utf8");
|
||||
args.push(input_path);
|
||||
|
||||
// Run bindgen
|
||||
Command::new(binary)
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verify the installed version of wasm-bindgen-cli
|
||||
///
|
||||
/// For local installations, this will check that the installed version matches the specified version.
|
||||
/// For managed installations, this will check that the version managed by `dx` is the specified version.
|
||||
pub async fn verify_install(version: &str) -> anyhow::Result<()> {
|
||||
let settings = Self::new(version);
|
||||
if CliSettings::prefer_no_downloads() {
|
||||
settings.verify_local_install().await
|
||||
} else {
|
||||
settings.verify_managed_install().await
|
||||
}
|
||||
}
|
||||
|
||||
/// Install the specified wasm-bingen version.
|
||||
///
|
||||
/// This will overwrite any existing wasm-bindgen binaries of the same version.
|
||||
///
|
||||
/// This will attempt to install wasm-bindgen from:
|
||||
/// 1. Direct GitHub release download.
|
||||
/// 2. `cargo binstall` if installed.
|
||||
/// 3. Compile from source with `cargo install`.
|
||||
async fn install(&self) -> anyhow::Result<()> {
|
||||
tracing::info!("Installing wasm-bindgen-cli@{}...", self.version);
|
||||
|
||||
// Attempt installation from GitHub
|
||||
if let Err(e) = self.install_github().await {
|
||||
tracing::error!("Failed to install wasm-bindgen-cli@{}: {e}", self.version);
|
||||
} else {
|
||||
tracing::info!(
|
||||
"wasm-bindgen-cli@{} was successfully installed from GitHub.",
|
||||
self.version
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Attempt installation from binstall.
|
||||
if let Err(e) = self.install_binstall().await {
|
||||
tracing::error!("Failed to install wasm-bindgen-cli@{}: {e}", self.version);
|
||||
tracing::info!("Failed to install prebuilt binary for wasm-bindgen-cli@{}. Compiling from source instead. This may take a while.", self.version);
|
||||
} else {
|
||||
tracing::info!(
|
||||
"wasm-bindgen-cli@{} was successfully installed from cargo-binstall.",
|
||||
self.version
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Attempt installation from cargo.
|
||||
self.install_cargo()
|
||||
.await
|
||||
.context("failed to install wasm-bindgen-cli from cargo")?;
|
||||
|
||||
tracing::info!(
|
||||
"wasm-bindgen-cli@{} was successfully installed from source.",
|
||||
self.version
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn install_github(&self) -> anyhow::Result<()> {
|
||||
tracing::debug!(
|
||||
"Attempting to install wasm-bindgen-cli@{} from GitHub",
|
||||
self.version
|
||||
);
|
||||
|
||||
let url = self.git_install_url().ok_or_else(|| {
|
||||
anyhow!(
|
||||
"no available GitHub binary for wasm-bindgen-cli@{}",
|
||||
self.version
|
||||
)
|
||||
})?;
|
||||
|
||||
// Get the final binary location.
|
||||
let binary_path = self.get_binary_path().await?;
|
||||
|
||||
// Download then extract wasm-bindgen-cli.
|
||||
let bytes = reqwest::get(url).await?.bytes().await?;
|
||||
|
||||
// Unpack the first tar entry to the final binary location
|
||||
Archive::new(GzDecoder::new(bytes.as_ref()))
|
||||
.entries()?
|
||||
.find(|entry| {
|
||||
entry
|
||||
.as_ref()
|
||||
.map(|e| {
|
||||
e.path_bytes()
|
||||
.ends_with(self.downloaded_bin_name().as_bytes())
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.context("Failed to find entry")??
|
||||
.unpack(&binary_path)
|
||||
.context("failed to unpack wasm-bindgen-cli binary")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn install_binstall(&self) -> anyhow::Result<()> {
|
||||
tracing::debug!(
|
||||
"Attempting to install wasm-bindgen-cli@{} from cargo-binstall",
|
||||
self.version
|
||||
);
|
||||
|
||||
let package = self.cargo_bin_name();
|
||||
let tempdir = TempDir::new()?;
|
||||
|
||||
// Run install command
|
||||
Command::new("cargo")
|
||||
.args([
|
||||
"binstall",
|
||||
&package,
|
||||
"--no-confirm",
|
||||
"--force",
|
||||
"--no-track",
|
||||
"--install-path",
|
||||
])
|
||||
.arg(tempdir.path())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
fs::copy(
|
||||
tempdir.path().join(self.downloaded_bin_name()),
|
||||
self.get_binary_path().await?,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn install_cargo(&self) -> anyhow::Result<()> {
|
||||
tracing::debug!(
|
||||
"Attempting to install wasm-bindgen-cli@{} from cargo-install",
|
||||
self.version
|
||||
);
|
||||
let package = self.cargo_bin_name();
|
||||
let tempdir = TempDir::new()?;
|
||||
|
||||
// Run install command
|
||||
Command::new("cargo")
|
||||
.args([
|
||||
"install",
|
||||
&package,
|
||||
"--bin",
|
||||
"wasm-bindgen",
|
||||
"--no-track",
|
||||
"--force",
|
||||
"--root",
|
||||
])
|
||||
.arg(tempdir.path())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.context("failed to install wasm-bindgen-cli from cargo-install")?;
|
||||
|
||||
tracing::info!("Copying into path: {}", tempdir.path().display());
|
||||
|
||||
// copy the wasm-bindgen out of the tempdir to the final location
|
||||
fs::copy(
|
||||
tempdir.path().join("bin").join(self.downloaded_bin_name()),
|
||||
self.get_binary_path().await?,
|
||||
)
|
||||
.await
|
||||
.context("failed to copy wasm-bindgen binary")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn verify_local_install(&self) -> anyhow::Result<()> {
|
||||
tracing::info!(
|
||||
"Verifying wasm-bindgen-cli@{} is installed in the path",
|
||||
self.version
|
||||
);
|
||||
|
||||
let binary = self.get_binary_path().await?;
|
||||
let output = Command::new(binary)
|
||||
.args(["--version"])
|
||||
.output()
|
||||
.await
|
||||
.context("Failed to check wasm-bindgen-cli version")?;
|
||||
|
||||
let stdout = String::from_utf8(output.stdout)
|
||||
.context("Failed to extract wasm-bindgen-cli output")?;
|
||||
|
||||
let installed_version = stdout.trim_start_matches("wasm-bindgen").trim();
|
||||
if installed_version != self.version {
|
||||
return Err(anyhow!(
|
||||
"Incorrect wasm-bindgen-cli version: project requires version {} but version {} is installed",
|
||||
self.version,
|
||||
installed_version,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn verify_managed_install(&self) -> anyhow::Result<()> {
|
||||
tracing::info!(
|
||||
"Verifying wasm-bindgen-cli@{} is installed in the tool directory",
|
||||
self.version
|
||||
);
|
||||
|
||||
let binary_name = self.installed_bin_name();
|
||||
let path = self.install_dir().await?.join(binary_name);
|
||||
|
||||
if !path.exists() {
|
||||
self.install().await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_binary_path(&self) -> anyhow::Result<PathBuf> {
|
||||
if CliSettings::prefer_no_downloads() {
|
||||
which::which("wasm-bindgen")
|
||||
.map_err(|_| anyhow!("Missing wasm-bindgen-cli@{}", self.version))
|
||||
} else {
|
||||
let installed_name = self.installed_bin_name();
|
||||
let install_dir = self.install_dir().await?;
|
||||
Ok(install_dir.join(installed_name))
|
||||
}
|
||||
}
|
||||
|
||||
async fn install_dir(&self) -> anyhow::Result<PathBuf> {
|
||||
let bindgen_dir = dirs::data_local_dir()
|
||||
.expect("user should be running on a compatible operating system")
|
||||
.join("dioxus/wasm-bindgen/");
|
||||
|
||||
fs::create_dir_all(&bindgen_dir).await?;
|
||||
Ok(bindgen_dir)
|
||||
}
|
||||
|
||||
fn installed_bin_name(&self) -> String {
|
||||
let mut name = format!("wasm-bindgen-{}", self.version);
|
||||
if cfg!(windows) {
|
||||
name = format!("{name}.exe");
|
||||
}
|
||||
name
|
||||
}
|
||||
|
||||
fn cargo_bin_name(&self) -> String {
|
||||
format!("wasm-bindgen-cli@{}", self.version)
|
||||
}
|
||||
|
||||
fn downloaded_bin_name(&self) -> &'static str {
|
||||
if cfg!(windows) {
|
||||
"wasm-bindgen.exe"
|
||||
} else {
|
||||
"wasm-bindgen"
|
||||
}
|
||||
}
|
||||
|
||||
fn git_install_url(&self) -> Option<String> {
|
||||
let platform = if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
|
||||
"x86_64-pc-windows-msvc"
|
||||
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
|
||||
"x86_64-unknown-linux-musl"
|
||||
} else if cfg!(all(target_os = "linux", target_arch = "aarch64")) {
|
||||
"aarch64-unknown-linux-gnu"
|
||||
} else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
|
||||
"x86_64-apple-darwin"
|
||||
} else if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
|
||||
"aarch64-apple-darwin"
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(format!(
|
||||
"https://github.com/rustwasm/wasm-bindgen/releases/download/{}/wasm-bindgen-{}-{}.tar.gz",
|
||||
self.version, self.version, platform
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -401,57 +440,56 @@ mod test {
|
||||
/// Test the github installer.
|
||||
#[tokio::test]
|
||||
async fn test_github_install() {
|
||||
let binary = WasmBindgen::new(VERSION);
|
||||
reset_test().await;
|
||||
WasmBindgen::install_github(VERSION).await.unwrap();
|
||||
binary.install_github().await.unwrap();
|
||||
test_verify_install().await;
|
||||
verify_installation().await;
|
||||
verify_installation(&binary).await;
|
||||
}
|
||||
|
||||
/// Test the cargo installer.
|
||||
#[tokio::test]
|
||||
async fn test_cargo_install() {
|
||||
let binary = WasmBindgen::new(VERSION);
|
||||
reset_test().await;
|
||||
WasmBindgen::install_cargo(VERSION).await.unwrap();
|
||||
binary.install_cargo().await.unwrap();
|
||||
test_verify_install().await;
|
||||
verify_installation().await;
|
||||
verify_installation(&binary).await;
|
||||
}
|
||||
|
||||
// CI doesn't have binstall.
|
||||
// Test the binstall installer
|
||||
// #[tokio::test]
|
||||
// async fn test_binstall_install() {
|
||||
// let binary = WasmBindgen::new(VERSION);
|
||||
// reset_test().await;
|
||||
// WasmBindgen::install_binstall(VERSION).await.unwrap();
|
||||
// binary.install_binstall().await.unwrap();
|
||||
// test_verify_install().await;
|
||||
// verify_installation().await;
|
||||
// verify_installation(&binary).await;
|
||||
// }
|
||||
|
||||
/// Helper to test `WasmBindgen::verify_install` after an installation.
|
||||
/// Helper to test `verify_install` after an installation.
|
||||
async fn test_verify_install() {
|
||||
// Test install verification
|
||||
let is_installed = WasmBindgen::verify_install(VERSION).await.unwrap();
|
||||
assert!(
|
||||
is_installed,
|
||||
"wasm-bingen install verification returned false after installation"
|
||||
);
|
||||
WasmBindgen::verify_install(VERSION).await.unwrap();
|
||||
}
|
||||
|
||||
/// Helper to test that the installed binary actually exists.
|
||||
async fn verify_installation() {
|
||||
let path = WasmBindgen::install_dir().await.unwrap();
|
||||
let name = WasmBindgen::installed_bin_name(VERSION);
|
||||
let binary = path.join(name);
|
||||
async fn verify_installation(binary: &WasmBindgen) {
|
||||
let path = binary.install_dir().await.unwrap();
|
||||
let name = binary.installed_bin_name();
|
||||
let binary_path = path.join(name);
|
||||
assert!(
|
||||
binary.exists(),
|
||||
binary_path.exists(),
|
||||
"wasm-bindgen binary doesn't exist after installation"
|
||||
);
|
||||
}
|
||||
|
||||
/// Delete the installed binary. The temp folder should be automatically deleted.
|
||||
async fn reset_test() {
|
||||
let path = WasmBindgen::install_dir().await.unwrap();
|
||||
let name = WasmBindgen::installed_bin_name(VERSION);
|
||||
let binary = path.join(name);
|
||||
let _ = fs::remove_file(binary).await;
|
||||
let binary = WasmBindgen::new(VERSION);
|
||||
let path = binary.install_dir().await.unwrap();
|
||||
let name = binary.installed_bin_name();
|
||||
let binary_path = path.join(name);
|
||||
let _ = tokio::fs::remove_file(binary_path).await;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user