From 4f29034fb67af1e7058b17cdd6e2ab4eb21e5d25 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 27 Mar 2023 03:13:11 +0000 Subject: [PATCH 01/85] Optimize get_process_steps --- src/command/build.rs | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 75374ad1..f1902042 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -274,39 +274,43 @@ impl Build { Ok(()) } - fn get_process_steps(mode: InstallMode) -> Vec<(&'static str, BuildStep)> { + fn get_process_steps(mode: InstallMode) -> impl Iterator { macro_rules! steps { ($($name:ident),+) => { { - let mut steps: Vec<(&'static str, BuildStep)> = Vec::new(); - $(steps.push((stringify!($name), Build::$name));)* - steps - } - }; + let steps: &'static [(_, BuildStep)] = &[ + $((stringify!($name), Build::$name),)* + ]; + steps + } + }; ($($name:ident,)*) => (steps![$($name),*]) } - let mut steps = Vec::new(); - match &mode { - InstallMode::Force => {} - _ => { - steps.extend(steps![ - step_check_rustc_version, - step_check_crate_config, - step_check_for_wasm_target, - ]); - } - } - steps.extend(steps![ - step_build_wasm, - step_create_dir, - step_copy_readme, - step_copy_license, - step_install_wasm_bindgen, - step_run_wasm_bindgen, - step_run_wasm_opt, - step_create_json, - ]); - steps + [ + match &mode { + InstallMode::Force => &[], + _ => { + steps![ + step_check_rustc_version, + step_check_crate_config, + step_check_for_wasm_target, + ] + } + }, + steps![ + step_build_wasm, + step_create_dir, + step_copy_readme, + step_copy_license, + step_install_wasm_bindgen, + step_run_wasm_bindgen, + step_run_wasm_opt, + step_create_json, + ], + ] + .into_iter() + .flatten() + .copied() } fn step_check_rustc_version(&mut self) -> Result<()> { From 8ac82f26c736055442cf454115a8047625f0e171 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 Mar 2023 01:34:39 +0000 Subject: [PATCH 02/85] Use Vec::with_capacity in check_wasm_pack_lastet_version --- src/manifest/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 54f77403..56c635f1 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -234,7 +234,7 @@ impl Crate { fn check_wasm_pack_latest_version() -> Result { let url = "https://crates.io/api/v1/crates/wasm-pack"; - let mut easy = easy::Easy2::new(Collector(Vec::new())); + let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); easy.useragent(&format!( "wasm-pack/{} ({})", From 08a66e68a4a5f47d9a1fddf78844e8fa0223d1d4 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 28 Mar 2023 04:11:31 +0000 Subject: [PATCH 03/85] Use &'static str for local version --- src/build/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 691ec490..78e89b60 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -16,7 +16,7 @@ pub mod wasm_target; /// wasm-pack version with the latest on crates.io. pub struct WasmPackVersion { /// The currently installed wasm-pack version. - pub local: String, + pub local: &'static str, /// The latest version of wasm-pack that's released at /// crates.io. pub latest: String, @@ -67,9 +67,9 @@ pub fn check_wasm_pack_versions() -> Result { } } -fn wasm_pack_local_version() -> Option { +fn wasm_pack_local_version() -> Option<&'static str> { let output = env!("CARGO_PKG_VERSION"); - Some(output.to_string()) + Some(output) } /// Run `cargo build` targetting `wasm32-unknown-unknown`. From 9d375922b18edc4b8832c1f6a7d590aada2147a2 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 1 Apr 2023 04:45:50 +0000 Subject: [PATCH 04/85] Optimize version check --- src/build/mod.rs | 6 +- src/main.rs | 4 +- src/manifest/mod.rs | 210 ++++++++++++++++++++---------------------- tests/all/manifest.rs | 5 + 4 files changed, 112 insertions(+), 113 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 78e89b60..5fb9e375 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -3,7 +3,7 @@ use crate::child; use crate::command::build::BuildProfile; use crate::emoji; -use crate::manifest::Crate; +use crate::manifest; use crate::PBAR; use anyhow::{bail, Context, Result}; use std::path::Path; @@ -19,7 +19,7 @@ pub struct WasmPackVersion { pub local: &'static str, /// The latest version of wasm-pack that's released at /// crates.io. - pub latest: String, + pub latest: Vec, } /// Ensure that `rustc` is present and that it is >= 1.30.0 @@ -62,7 +62,7 @@ fn rustc_minor_version() -> Option { /// Checks and returns local and latest versions of wasm-pack pub fn check_wasm_pack_versions() -> Result { match wasm_pack_local_version() { - Some(local) => Ok(WasmPackVersion {local, latest: Crate::return_wasm_pack_latest_version()?.unwrap_or_else(|| "".to_string())}), + Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or_else(|| Vec::new())}), None => bail!("We can't figure out what your wasm-pack version is, make sure the installation path is correct.") } } diff --git a/src/main.rs b/src/main.rs index c77f845d..72739809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ fn background_check_for_updates() -> mpsc::Receiver> { if let Ok(wasm_pack_version) = wasm_pack_version { if !wasm_pack_version.local.is_empty() && !wasm_pack_version.latest.is_empty() - && wasm_pack_version.local != wasm_pack_version.latest + && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest { let _ = sender.send(Ok(wasm_pack_version)); } @@ -93,7 +93,7 @@ fn run() -> Result<()> { match wasm_pack_version { Ok(wasm_pack_version) => PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ - To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", wasm_pack_version.latest, wasm_pack_version.local)), + To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), Err(err) => PBAR.warn(&format!("{}", err)) } } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 56c635f1..b0814eb6 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -129,140 +129,134 @@ impl easy::Handler for Collector { } } -/// Struct for storing information received from crates.io -#[derive(Deserialize, Debug)] -pub struct Crate { - #[serde(rename = "crate")] - crt: CrateInformation, -} - -#[derive(Deserialize, Debug)] -struct CrateInformation { - max_version: String, -} - -impl Crate { - /// Returns latest wasm-pack version - pub fn return_wasm_pack_latest_version() -> Result> { - let current_time = chrono::offset::Local::now(); - let old_metadata_file = Self::return_wasm_pack_file(); - - match old_metadata_file { - Some(ref file_contents) => { - let last_updated = Self::return_stamp_file_value(&file_contents, "created") - .and_then(|t| DateTime::parse_from_str(t.as_str(), "%+").ok()); - - last_updated - .map(|last_updated| { - if current_time.signed_duration_since(last_updated).num_hours() > 24 { - Self::return_api_call_result(current_time).map(Some) - } else { - Ok(Self::return_stamp_file_value(&file_contents, "version")) - } - }) - .unwrap_or_else(|| Ok(None)) - } - None => Self::return_api_call_result(current_time).map(Some), +/// Returns latest wasm-pack version +pub fn return_wasm_pack_latest_version() -> Result>> { + let current_time = chrono::offset::Local::now(); + let old_metadata_file = return_wasm_pack_file(); + + match old_metadata_file { + Some(ref file_contents) => { + let last_updated = return_stamp_file_value(&file_contents, b"created") + .and_then(|t| DateTime::parse_from_str(&String::from_utf8_lossy(t), "%+").ok()); + + last_updated + .map(|last_updated| { + if current_time.signed_duration_since(last_updated).num_hours() > 24 { + return_api_call_result(current_time).map(Some) + } else { + Ok(return_stamp_file_value(&file_contents, b"version") + .map(|f| f.to_owned())) + } + }) + .unwrap_or_else(|| Ok(None)) } + None => return_api_call_result(current_time).map(Some), } +} - fn return_api_call_result(current_time: DateTime) -> Result { - let version = Self::return_latest_wasm_pack_version(); +fn return_api_call_result(current_time: DateTime) -> Result> { + let version = return_latest_wasm_pack_version(); - // We always override the stamp file with the current time because we don't - // want to hit the API all the time if it fails. It should follow the same - // "policy" as the success. This means that the 24 hours rate limiting - // will be active regardless if the check succeeded or failed. - match version { - Ok(ref version) => Self::override_stamp_file(current_time, Some(&version)).ok(), - Err(_) => Self::override_stamp_file(current_time, None).ok(), - }; + // We always override the stamp file with the current time because we don't + // want to hit the API all the time if it fails. It should follow the same + // "policy" as the success. This means that the 24 hours rate limiting + // will be active regardless if the check succeeded or failed. + match version { + Ok(ref version) => override_stamp_file(current_time, Some(&version)).ok(), + Err(_) => override_stamp_file(current_time, None).ok(), + }; - version - } - - fn override_stamp_file( - current_time: DateTime, - version: Option<&str>, - ) -> Result<()> { - let path = env::current_exe()?; + version +} - let mut file = fs::OpenOptions::new() - .read(true) - .write(true) - .append(true) - .create(true) - .open(path.with_extension("stamp"))?; +fn override_stamp_file( + current_time: DateTime, + version: Option<&[u8]>, +) -> Result<()> { + let path = env::current_exe()?; - file.set_len(0)?; + let mut file = fs::OpenOptions::new() + .read(true) + .write(true) + .append(true) + .create(true) + .open(path.with_extension("stamp"))?; - write!(file, "created {:?}", current_time)?; + file.set_len(0)?; - if let Some(version) = version { - write!(file, "\nversion {}", version)?; - } + write!(file, "created {:?}", current_time)?; - Ok(()) + if let Some(version) = version { + write!(file, "\nversion ")?; + file.write(version)?; } - /// Return stamp file where metadata is stored. - fn return_wasm_pack_file() -> Option { - if let Ok(path) = env::current_exe() { - if let Ok(file) = fs::read_to_string(path.with_extension("stamp")) { - return Some(file); - } - } - None - } + Ok(()) +} - /// Returns wasm-pack latest version (if it's received) by executing check_wasm_pack_latest_version function. - fn return_latest_wasm_pack_version() -> Result { - Self::check_wasm_pack_latest_version().map(|crt| crt.crt.max_version) +/// Return stamp file where metadata is stored. +fn return_wasm_pack_file() -> Option> { + if let Ok(path) = env::current_exe() { + if let Ok(file) = fs::read(path.with_extension("stamp")) { + return Some(file); + } } + None +} - /// Read the stamp file and return value assigned to a certain key. - fn return_stamp_file_value(file: &str, word: &str) -> Option { - let created = file - .lines() - .find(|line| line.starts_with(word)) - .and_then(|l| l.split_whitespace().nth(1)); +/// Returns wasm-pack latest version (if it's received) by executing check_wasm_pack_latest_version function. +fn return_latest_wasm_pack_version() -> Result> { + check_wasm_pack_latest_version() +} - created.map(|s| s.to_string()) - } +/// Read the stamp file and return value assigned to a certain key. +fn return_stamp_file_value<'a>(file: &'a [u8], word: &[u8]) -> Option<&'a [u8]> { + file.split(|&byte| byte == b'\n') + .find_map(|line| line.strip_prefix(word)) + .and_then(|l| l.get(1..)) +} - /// Call to the crates.io api and return the latest version of `wasm-pack` - fn check_wasm_pack_latest_version() -> Result { - let url = "https://crates.io/api/v1/crates/wasm-pack"; +/// Call to the crates.io api and return the latest version of `wasm-pack` +fn check_wasm_pack_latest_version() -> Result> { + let url = "https://crates.io/api/v1/crates/wasm-pack"; - let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); + let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); - easy.useragent(&format!( - "wasm-pack/{} ({})", - WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), - WASM_PACK_REPO_URL - ))?; + easy.useragent(&format!( + "wasm-pack/{} ({})", + WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), + WASM_PACK_REPO_URL + ))?; - easy.url(url)?; - easy.get(true)?; - easy.perform()?; + easy.url(url)?; + easy.get(true)?; + easy.perform()?; - let status_code = easy.response_code()?; + let status_code = easy.response_code()?; - if 200 <= status_code && status_code < 300 { - let contents = easy.get_ref(); - let result = String::from_utf8_lossy(&contents.0); + if 200 <= status_code && status_code < 300 { + let contents = easy.get_ref(); + let version_bytes = get_max_version(&contents.0) + .context("max_version field not found when checking for newer wasm-pack version")?; - Ok(serde_json::from_str(result.into_owned().as_str())?) - } else { - bail!( - "Received a bad HTTP status code ({}) when checking for newer wasm-pack version at: {}", - status_code, - url - ) - } + Ok(version_bytes.to_owned()) + } else { + bail!( + "Received a bad HTTP status code ({}) when checking for newer wasm-pack version at: {}", + status_code, + url + ) } } +/// Returns the `max_version` field of given JSON from crates.io API +pub fn get_max_version(crate_info: &[u8]) -> Option<&[u8]> { + crate_info + .split(|&byte| byte == b',') + .find_map(|slice| slice.strip_prefix(b"\"max_version\":\"")) + .and_then(|slice| slice.split(|&byte| byte == b'"').next()) +} + #[derive(Clone, Deserialize)] #[serde(untagged)] enum CargoWasmPackProfileWasmOpt { diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index abf0e759..e46b02c9 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -641,3 +641,8 @@ fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { let crate_data = manifest::CrateData::new(&path, None); assert!(crate_data.is_err()); } + +#[test] +fn get_max_version_works() { + assert_eq!(Some(&b"0.11.0"[..]), manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)) +} From 85586ee861957631cc613c0357a85564a6e6bae3 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 2 Apr 2023 22:09:53 +0000 Subject: [PATCH 05/85] Reduce conversions from OsString to String --- src/bindgen.rs | 7 +++--- src/build/mod.rs | 3 ++- src/command/build.rs | 49 +++++++++++++++++++++----------------- src/command/generate.rs | 6 +++-- src/command/login.rs | 15 ++++++++---- src/command/mod.rs | 28 ++++++++++++++-------- src/command/publish/mod.rs | 13 +++++----- src/command/test.rs | 2 +- src/generate.rs | 5 ++-- src/install/mode.rs | 26 ++++++++++---------- src/npm.rs | 35 ++++++++++++++++----------- 11 files changed, 111 insertions(+), 78 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 58fab360..656521bc 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -6,6 +6,7 @@ use crate::install::{self, Tool}; use crate::manifest::CrateData; use anyhow::{bail, Context, Result}; use semver; +use std::ffi::{OsStr, OsString}; use std::path::Path; use std::process::Command; @@ -21,7 +22,7 @@ pub fn wasm_bindgen_build( reference_types: bool, target: Target, profile: BuildProfile, - extra_options: &Vec, + extra_options: &Vec, ) -> Result<()> { let release_or_debug = match profile { BuildProfile::Release | BuildProfile::Profiling => "release", @@ -29,10 +30,10 @@ pub fn wasm_bindgen_build( }; let out_dir = out_dir.to_str().unwrap(); - let has_target_dir_overwrite = extra_options.contains(&"--target-dir".to_string()); + let has_target_dir_overwrite = extra_options.iter().any(|i| i == "--target-dir"); let target_directory = if has_target_dir_overwrite { let i = extra_options - .binary_search(&"--target-dir".to_string()) + .binary_search_by(|i| i.as_os_str().cmp(OsStr::new("--target-dir"))) .unwrap(); extra_options .get(i + 1) diff --git a/src/build/mod.rs b/src/build/mod.rs index 5fb9e375..2d39bc64 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -6,6 +6,7 @@ use crate::emoji; use crate::manifest; use crate::PBAR; use anyhow::{bail, Context, Result}; +use std::ffi::OsString; use std::path::Path; use std::process::Command; use std::str; @@ -76,7 +77,7 @@ fn wasm_pack_local_version() -> Option<&'static str> { pub fn cargo_build_wasm( path: &Path, profile: BuildProfile, - extra_options: &[String], + extra_options: &[OsString], ) -> Result<()> { let msg = format!("{}Compiling to Wasm...", emoji::CYCLONE); PBAR.info(&msg); diff --git a/src/command/build.rs b/src/command/build.rs index f1902042..a8c9e9fa 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -12,12 +12,12 @@ use crate::manifest; use crate::readme; use crate::wasm_opt; use crate::PBAR; -use anyhow::{anyhow, bail, Error, Result}; +use anyhow::{anyhow, bail, Result}; use binary_install::Cache; use log::info; +use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::PathBuf; -use std::str::FromStr; use std::time::Instant; use structopt::clap::AppSettings; @@ -37,7 +37,7 @@ pub struct Build { pub out_name: Option, pub bindgen: Option, pub cache: Cache, - pub extra_options: Vec, + pub extra_options: Vec, } /// What sort of output we're going to be generating and flags we're invoking @@ -81,16 +81,23 @@ impl fmt::Display for Target { } } -impl FromStr for Target { - type Err = Error; - fn from_str(s: &str) -> Result { - match s { - "bundler" | "browser" => Ok(Target::Bundler), - "web" => Ok(Target::Web), - "nodejs" => Ok(Target::Nodejs), - "no-modules" => Ok(Target::NoModules), - "deno" => Ok(Target::Deno), - _ => bail!("Unknown target: {}", s), +impl Target { + /// Converts from `OsStr` + pub fn parse(s: &OsStr) -> Result { + if s == "bundler" || s == "browser" { + Ok(Target::Bundler) + } else if s == "web" { + Ok(Target::Web) + } else if s == "nodejs" { + Ok(Target::Nodejs) + } else if s == "no-modules" { + Ok(Target::NoModules) + } else if s == "deno" { + Ok(Target::Deno) + } else { + let mut err = OsString::from("Unknown target: "); + err.push(s); + Err(err) } } } @@ -125,7 +132,7 @@ pub struct BuildOptions { #[structopt(long = "scope", short = "s")] pub scope: Option, - #[structopt(long = "mode", short = "m", default_value = "normal")] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, @@ -142,7 +149,7 @@ pub struct BuildOptions { /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[structopt(long = "target", short = "t", default_value = "bundler")] + #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = Target::parse))] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, @@ -165,15 +172,15 @@ pub struct BuildOptions { #[structopt(long = "out-dir", short = "d", default_value = "pkg")] /// Sets the output directory with a relative path. - pub out_dir: String, + pub out_dir: OsString, #[structopt(long = "out-name")] /// Sets the output file names. Defaults to package name. pub out_name: Option, - #[structopt(allow_hyphen_values = true)] + #[structopt(allow_hyphen_values = true, parse(from_os_str))] /// List of extra options to pass to `cargo build` - pub extra_options: Vec, + pub extra_options: Vec, } impl Default for BuildOptions { @@ -190,7 +197,7 @@ impl Default for BuildOptions { dev: false, release: false, profiling: false, - out_dir: String::new(), + out_dir: OsString::new(), out_name: None, extra_options: Vec::new(), } @@ -205,9 +212,7 @@ impl Build { if let Some(path) = &build_opts.path { if path.to_string_lossy().starts_with("--") { let path = build_opts.path.take().unwrap(); - build_opts - .extra_options - .insert(0, path.to_string_lossy().into_owned()); + build_opts.extra_options.insert(0, path.into()); } } let crate_path = get_crate_path(build_opts.path)?; diff --git a/src/command/generate.rs b/src/command/generate.rs index 609a0b53..58cc73a7 100644 --- a/src/command/generate.rs +++ b/src/command/generate.rs @@ -1,3 +1,5 @@ +use std::ffi::OsString; + use crate::cache; use crate::generate; use crate::install::{self, Tool}; @@ -7,7 +9,7 @@ use log::info; /// Executes the 'cargo-generate' command in the current directory /// which generates a new rustwasm project from a template. -pub fn generate(template: String, name: String, install_permitted: bool) -> Result<()> { +pub fn generate(template: OsString, name: OsString, install_permitted: bool) -> Result<()> { info!("Generating a new rustwasm project..."); let download = install::download_prebuilt_or_cargo_install( Tool::CargoGenerate, @@ -17,7 +19,7 @@ pub fn generate(template: String, name: String, install_permitted: bool) -> Resu )?; generate::generate(&template, &name, &download)?; - let msg = format!("🐑 Generated new project at /{}", name); + let msg = format!("🐑 Generated new project at /{}", name.to_string_lossy()); PBAR.info(&msg); Ok(()) } diff --git a/src/command/login.rs b/src/command/login.rs index 817ae168..933007f2 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -1,20 +1,25 @@ +use std::ffi::OsString; + use crate::npm; use crate::PBAR; use anyhow::Result; use log::info; pub fn login( - registry: Option, - scope: &Option, + registry: Option, + scope: &Option, always_auth: bool, - auth_type: &Option, + auth_type: &Option, ) -> Result<()> { - let registry = registry.unwrap_or_else(|| npm::DEFAULT_NPM_REGISTRY.to_string()); + let registry = registry.unwrap_or_else(|| npm::DEFAULT_NPM_REGISTRY.to_string().into()); info!("Logging in to npm..."); info!( "Scope: {:?} Registry: {}, Always Auth: {}, Auth Type: {:?}.", - &scope, ®istry, always_auth, &auth_type + &scope, + ®istry.to_string_lossy(), + always_auth, + &auth_type ); info!("npm info located in the npm debug log"); npm::npm_login(®istry, &scope, always_auth, &auth_type)?; diff --git a/src/command/mod.rs b/src/command/mod.rs index 190e8738..ffa7e1ba 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -19,6 +19,7 @@ use self::test::{Test, TestOptions}; use crate::install::InstallMode; use anyhow::Result; use log::info; +use std::ffi::OsString; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. @@ -40,15 +41,17 @@ pub enum Command { /// 🐑 create a new project with a template Generate { /// The name of the project - name: String, + #[structopt(parse(from_os_str))] + name: OsString, /// The URL to the template #[structopt( long = "template", short = "temp", - default_value = "https://github.com/rustwasm/wasm-pack-template" + default_value = "https://github.com/rustwasm/wasm-pack-template", + parse(from_os_str) )] - template: String, - #[structopt(long = "mode", short = "m", default_value = "normal")] + template: OsString, + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, @@ -56,9 +59,14 @@ pub enum Command { #[structopt(name = "publish")] /// 🎆 pack up your npm package and publish! Publish { - #[structopt(long = "target", short = "t", default_value = "bundler")] + #[structopt( + long = "target", + short = "t", + default_value = "bundler", + parse(from_os_str) + )] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] - target: String, + target: OsString, /// The access level for the package to be published #[structopt(long = "access", short = "a")] @@ -67,7 +75,7 @@ pub enum Command { /// The distribution tag being used for publishing. /// See https://docs.npmjs.com/cli/dist-tag #[structopt(long = "tag")] - tag: Option, + tag: Option, /// The path to the Rust crate. If not set, searches up the path from the current directory. #[structopt(parse(from_os_str))] @@ -83,13 +91,13 @@ pub enum Command { /// specified, this registry will only be used for packages with that /// scope. scope defaults to the scope of the project directory you're /// currently in, if any. - registry: Option, + registry: Option, #[structopt(long = "scope", short = "s")] /// Default: none. /// If specified, the user and login credentials given will be /// associated with the specified scope. - scope: Option, + scope: Option, #[structopt(long = "always-auth", short = "a")] /// If specified, save configuration indicating that all requests to the @@ -103,7 +111,7 @@ pub enum Command { /// What authentication strategy to use with adduser/login. Some npm /// registries (for example, npmE) might support alternative auth /// strategies besides classic username/password entry in legacy npm. - auth_type: Option, + auth_type: Option, }, #[structopt(name = "test")] diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 92c6f3f7..70bce2c7 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -6,19 +6,19 @@ use crate::command::build::{Build, BuildOptions, Target}; use crate::command::utils::{find_pkg_directory, get_crate_path}; use crate::npm; use crate::PBAR; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Error, Result}; use dialoguer::{Confirm, Input, Select}; use log::info; +use std::ffi::{OsStr, OsString}; use std::path::PathBuf; -use std::str::FromStr; /// Creates a tarball from a 'pkg' directory /// and publishes it to the NPM registry pub fn publish( - _target: &str, + _target: &OsStr, path: Option, access: Option, - tag: Option, + tag: Option, ) -> Result<()> { let crate_path = get_crate_path(path)?; @@ -39,14 +39,15 @@ pub fn publish( .default(".".to_string()) .show_default(false) .interact()?; - let out_dir = format!("{}/pkg", out_dir); + let out_dir = OsString::from(format!("{}/pkg", out_dir)); let target = Select::new() .with_prompt("target[default: bundler]") .items(&["bundler", "nodejs", "web", "no-modules"]) .default(0) .interact()? .to_string(); - let target = Target::from_str(&target)?; + let target = Target::parse(OsStr::new(&target)) + .map_err(|err| Error::msg(err.to_string_lossy().into_owned()))?; let build_opts = BuildOptions { path: Some(crate_path.clone()), target, diff --git a/src/command/test.rs b/src/command/test.rs index d7b66424..616f99ad 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -71,7 +71,7 @@ pub struct TestOptions { /// UI or windows. pub headless: bool, - #[structopt(long = "mode", short = "m", default_value = "normal")] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, diff --git a/src/generate.rs b/src/generate.rs index 660f123b..5ea920bd 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -4,11 +4,12 @@ use crate::child; use crate::emoji; use crate::install::{self, Tool}; use anyhow::{Context, Result}; +use std::ffi::OsStr; use std::process::Command; /// Run `cargo generate` in the current directory to create a new /// project from a template -pub fn generate(template: &str, name: &str, install_status: &install::Status) -> Result<()> { +pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); @@ -19,7 +20,7 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) -> println!( "{} Generating a new rustwasm project with name '{}'...", emoji::SHEEP, - name + name.to_string_lossy() ); child::run(cmd, "cargo-generate").context("Running cargo-generate")?; Ok(()) diff --git a/src/install/mode.rs b/src/install/mode.rs index a55153de..b017d9a3 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -1,5 +1,4 @@ -use anyhow::{bail, Error, Result}; -use std::str::FromStr; +use std::ffi::{OsStr, OsString}; /// The `InstallMode` determines which mode of initialization we are running, and /// what install steps we perform. @@ -20,19 +19,22 @@ impl Default for InstallMode { } } -impl FromStr for InstallMode { - type Err = Error; - fn from_str(s: &str) -> Result { - match s { - "no-install" => Ok(InstallMode::Noinstall), - "normal" => Ok(InstallMode::Normal), - "force" => Ok(InstallMode::Force), - _ => bail!("Unknown build mode: {}", s), +impl InstallMode { + /// Converts from `OsStr` + pub fn parse(s: &OsStr) -> Result { + if s == "no-install" { + Ok(InstallMode::Noinstall) + } else if s == "normal" { + Ok(InstallMode::Normal) + } else if s == "force" { + Ok(InstallMode::Force) + } else { + let mut err = OsString::from("Unknown build mode: "); + err.push(s); + Err(err) } } -} -impl InstallMode { /// Determines if installation is permitted during a function call based on --mode flag pub fn install_permitted(self) -> bool { match self { diff --git a/src/npm.rs b/src/npm.rs index 7c4f08b0..11d2b5f3 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -1,5 +1,7 @@ //! Functionality related to publishing to npm. +use std::ffi::{OsStr, OsString}; + use crate::child; use crate::command::publish::access::Access; use anyhow::{bail, Context, Result}; @@ -17,7 +19,7 @@ pub fn npm_pack(path: &str) -> Result<()> { } /// Run the `npm publish` command. -pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { +pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); match access { Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), @@ -33,34 +35,39 @@ pub fn npm_publish(path: &str, access: Option, tag: Option) -> R /// Run the `npm login` command. pub fn npm_login( - registry: &str, - scope: &Option, + registry: &OsStr, + scope: &Option, always_auth: bool, - auth_type: &Option, + auth_type: &Option, ) -> Result<()> { - let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; + // Interactively ask user for npm login info. + // (child::run does not support interactive input) + let mut cmd = child::new_command("npm"); + + cmd.arg("login").arg(build_arg("--registry=", registry)); if let Some(scope) = scope { - args.push(format!("--scope={}", scope)); + cmd.arg(build_arg("--scope=", &scope)); } if always_auth { - args.push("--always_auth".to_string()); + cmd.arg("--always_auth"); } if let Some(auth_type) = auth_type { - args.push(format!("--auth_type={}", auth_type)); + cmd.arg(build_arg("--auth_type=", &auth_type)); } - // Interactively ask user for npm login info. - // (child::run does not support interactive input) - let mut cmd = child::new_command("npm"); - cmd.args(args); - info!("Running {:?}", cmd); if cmd.status()?.success() { Ok(()) } else { - bail!("Login to registry {} failed", registry) + bail!("Login to registry {} failed", registry.to_string_lossy()) } } + +fn build_arg(prefix: &'static str, value: &OsStr) -> OsString { + let mut s = OsString::from(prefix); + s.push(value); + s +} From 114d12b6482d8d89a6031ae929b68c84e6cee382 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 3 Apr 2023 01:20:10 +0000 Subject: [PATCH 06/85] Reduce heap allocations --- src/command/test.rs | 16 ++++++++-------- src/install/mod.rs | 6 +++--- src/license.rs | 41 ++++++++++++++++++++--------------------- src/manifest/mod.rs | 9 ++++----- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/command/test.rs b/src/command/test.rs index 616f99ad..3940b4af 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -194,17 +194,17 @@ impl Test { Ok(()) } - fn get_process_steps(&self) -> Vec<(&'static str, TestStep)> { + fn get_process_steps(&self) -> impl Iterator { + let identity = |i| i; macro_rules! steps { ($($name:ident $(if $e:expr)* ),+) => { { - let mut steps: Vec<(&'static str, TestStep)> = Vec::new(); - $( - $(if $e)* { - steps.push((stringify!($name), Test::$name)); - } - )* - steps + vec![$({ + let step: TestStep = Test::$name; + Some((stringify!($name), step))$(.filter(|_| $e))* + },)*] + .into_iter() + .filter_map(identity) } }; ($($name:ident $(if $e:expr)* ,)*) => (steps![$($name $(if $e)* ),*]) diff --git a/src/install/mod.rs b/src/install/mod.rs index 6debaccd..c4361407 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -270,9 +270,9 @@ pub fn cargo_install( // just want them in `$root/*` directly (which matches how the tarballs are // laid out, and where the rest of our code expects them to be). So we do a // little renaming here. - let binaries: Result> = match tool { - Tool::WasmBindgen => Ok(vec!["wasm-bindgen", "wasm-bindgen-test-runner"]), - Tool::CargoGenerate => Ok(vec!["cargo-generate"]), + let binaries: Result<&[&str]> = match tool { + Tool::WasmBindgen => Ok(&["wasm-bindgen", "wasm-bindgen-test-runner"]), + Tool::CargoGenerate => Ok(&["cargo-generate"]), Tool::WasmOpt => bail!("Cannot install wasm-opt with cargo."), }; diff --git a/src/license.rs b/src/license.rs index 5305e41e..483b3496 100644 --- a/src/license.rs +++ b/src/license.rs @@ -8,32 +8,29 @@ use crate::manifest::CrateData; use crate::PBAR; use glob::glob; -fn glob_license_files(path: &Path) -> Result> { - let mut license_files: Vec = Vec::new(); - let path_string = match path.join("LICENSE*").to_str() { - Some(path_string) => path_string.to_owned(), +fn glob_license_files<'a>(path: &'a Path) -> Result> + 'a> { + let joined_path = path.join("LICENSE*"); + let path_string = match joined_path.to_str() { + Some(path_string) => path_string, None => { return Err(anyhow!("Could not convert joined license path to String")); } }; - for entry in glob(&path_string)? { - match entry { - Ok(globed_path) => { - let file_name = match globed_path.file_name() { - Some(file_name) => file_name, - None => return Err(anyhow!("Could not get file name from path")), - }; - let file_name_string = match file_name.to_str() { - Some(file_name_string) => file_name_string.to_owned(), - None => return Err(anyhow!("Could not convert filename to String")), - }; - license_files.push(file_name_string); - } - Err(e) => println!("{:?}", e), + Ok(glob(path_string)?.map(|entry| match entry { + Ok(globed_path) => { + let file_name = match globed_path.file_name() { + Some(file_name) => file_name, + None => return Err(anyhow!("Could not get file name from path")), + }; + let file_name_string = match file_name.to_str() { + Some(file_name_string) => file_name_string.to_owned(), + None => return Err(anyhow!("Could not convert filename to String")), + }; + Ok(file_name_string) } - } - Ok(license_files) + Err(e) => Err(anyhow!("{:?}", e)), + })) } /// Copy the crate's license into the `pkg` directory. @@ -54,11 +51,13 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R match license_files { Ok(files) => { - if files.is_empty() { + let mut files = files.peekable(); + if files.peek().is_none() { PBAR.info("License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory"); return Ok(()); } for license_file in files { + let license_file = license_file?; let crate_license_path = path.join(&license_file); let new_license_path = out_dir.join(&license_file); if fs::copy(&crate_license_path, &new_license_path).is_err() { diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index b0814eb6..4ed8bdb0 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -604,7 +604,8 @@ impl CrateData { let name_prefix = self.name_prefix(); let wasm_file = format!("{}_bg.wasm", name_prefix); let js_file = format!("{}.js", name_prefix); - let mut files = vec![wasm_file]; + let mut files = Vec::with_capacity(6); + files.push(wasm_file); files.push(js_file.clone()); if add_js_bg_to_package_json { @@ -639,9 +640,7 @@ impl CrateData { .filter_map(|e| e.file_name().into_string().ok()) .filter(|f| f.starts_with("LICENSE")) .filter(|f| f != "LICENSE"); - for file_name in file_names { - files.push(file_name); - } + files.extend(file_names); } NpmData { @@ -790,7 +789,7 @@ impl CrateData { } fn check_optional_fields(&self) { - let mut messages = vec![]; + let mut messages = Vec::with_capacity(3); if self.pkg().description.is_none() { messages.push("description"); } From ade563a589a1f798c0917e3ec5228507dd1aaba7 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 4 Apr 2023 04:20:21 +0000 Subject: [PATCH 07/85] Add benchmark --- Cargo.lock | 228 ++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 5 ++ benches/bench.rs | 27 ++++++ 3 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 benches/bench.rs diff --git a/Cargo.lock b/Cargo.lock index 7c97c905..8c647be5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -277,6 +283,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.0.79" @@ -307,6 +319,33 @@ dependencies = [ "winapi", ] +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "cipher" version = "0.3.0" @@ -326,11 +365,32 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex", + "indexmap", + "textwrap 0.16.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -409,6 +469,76 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap 3.2.23", + "criterion-plot", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.15" @@ -831,6 +961,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.12.3" @@ -1160,6 +1296,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.16" @@ -1255,6 +1400,12 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -1327,6 +1478,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "os_str_bytes" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1397,6 +1554,34 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + [[package]] name = "predicates" version = "2.1.5" @@ -1487,6 +1672,28 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1818,7 +2025,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "structopt-derive", ] @@ -1912,6 +2119,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.40" @@ -1959,6 +2172,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2291,6 +2514,7 @@ dependencies = [ "cargo_metadata", "chrono", "console", + "criterion", "curl", "dialoguer", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index a4a38f5d..5c0d1808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,10 @@ readme = "README.md" categories = ["wasm"] documentation = "https://rustwasm.github.io/wasm-pack/" +[[bench]] +name = "bench" +harness = false + [dependencies] anyhow = "1.0.68" atty = "0.2.14" @@ -40,6 +44,7 @@ which = "4.4.0" [dev-dependencies] assert_cmd = "2.0.8" +criterion = "0.4.0" lazy_static = "1.4.0" predicates = "2.1.5" serial_test = "1.0.0" diff --git a/benches/bench.rs b/benches/bench.rs new file mode 100644 index 00000000..d4c4ac14 --- /dev/null +++ b/benches/bench.rs @@ -0,0 +1,27 @@ +#[path = "../tests/all/utils/fixture.rs"] +mod fixture; + +use criterion::{criterion_group, criterion_main, Criterion}; +use std::process::Stdio; + +pub fn criterion_benchmark(c: &mut Criterion) { + let fixture = fixture::dual_license(); + run(&fixture); + c.bench_function("re-run build without code changes", |b| { + b.iter(|| run(&fixture)) + }); +} + +fn run(fixture: &fixture::Fixture) { + assert!(fixture + .wasm_pack() + .arg("build") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .unwrap() + .success()) +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From dd71328c0f20da00e7f54460e95efdd3957a86ef Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 4 Apr 2023 04:36:07 +0000 Subject: [PATCH 08/85] increase warm up time --- benches/bench.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/benches/bench.rs b/benches/bench.rs index d4c4ac14..f5c6211a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -5,9 +5,11 @@ use criterion::{criterion_group, criterion_main, Criterion}; use std::process::Stdio; pub fn criterion_benchmark(c: &mut Criterion) { + let mut g = c.benchmark_group("wasm-pack"); + g.warm_up_time(std::time::Duration::from_secs(10)); let fixture = fixture::dual_license(); run(&fixture); - c.bench_function("re-run build without code changes", |b| { + g.bench_function("re-run build without code changes", |b| { b.iter(|| run(&fixture)) }); } From 87e0e26f89ea6837dc5ed4777cc7692a6bd87abe Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 4 Apr 2023 04:43:57 +0000 Subject: [PATCH 09/85] Allow unused --- benches/bench.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/benches/bench.rs b/benches/bench.rs index f5c6211a..7aabc1dc 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,4 +1,5 @@ #[path = "../tests/all/utils/fixture.rs"] +#[allow(unused)] mod fixture; use criterion::{criterion_group, criterion_main, Criterion}; From b5f7654dbd183c29a10f208a0ca5c653e2aca01d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 7 Apr 2023 05:34:16 +0000 Subject: [PATCH 10/85] More optimization --- src/build/wasm_target.rs | 26 ++++++++------------------ src/wasm_opt.rs | 2 +- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 8631086f..718beb69 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -58,8 +58,8 @@ pub fn check_for_wasm32_target() -> Result<()> { // Check if wasm32 target is present, otherwise bail. match check_wasm32_target() { - Ok(ref wasm32_check) if wasm32_check.found => Ok(()), - Ok(wasm32_check) => bail!("{}", wasm32_check), + Ok(None) => Ok(()), + Ok(Some(wasm32_check)) => bail!("{}", wasm32_check), Err(err) => Err(err), } } @@ -97,36 +97,26 @@ fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { } } -fn check_wasm32_target() -> Result { +fn check_wasm32_target() -> Result> { let sysroot = get_rustc_sysroot()?; - let rustc_path = which::which("rustc")?; // If wasm32-unknown-unknown already exists we're ok. if is_wasm32_target_in_sysroot(&sysroot) { - Ok(Wasm32Check { - rustc_path, - sysroot, - found: true, - is_rustup: false, - }) + Ok(None) // If it doesn't exist, then we need to check if we're using rustup. } else { + let rustc_path = which::which("rustc")?; // If sysroot contains "rustup", then we can assume we're using rustup // and use rustup to add the wasm32-unknown-unknown target. if sysroot.to_string_lossy().contains("rustup") { - rustup_add_wasm_target().map(|()| Wasm32Check { - rustc_path, - sysroot, - found: true, - is_rustup: true, - }) + rustup_add_wasm_target().map(|()| None) } else { - Ok(Wasm32Check { + Ok(Some(Wasm32Check { rustc_path, sysroot, found: false, is_rustup: false, - }) + })) } } } diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 6e2149ae..9df8102b 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -29,7 +29,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo for file in out_dir.read_dir()? { let file = file?; let path = file.path(); - if path.extension().and_then(|s| s.to_str()) != Some("wasm") { + if path.extension().filter(|&ext| ext == "wasm").is_none() { continue; } From 0dc955deebcbc6b317628ab0247f2606d231e8c4 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 14:00:28 +0000 Subject: [PATCH 11/85] Optimize rustc version check --- src/build/mod.rs | 52 +++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 2d39bc64..7d7c33f1 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -5,7 +5,7 @@ use crate::command::build::BuildProfile; use crate::emoji; use crate::manifest; use crate::PBAR; -use anyhow::{bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use std::ffi::OsString; use std::path::Path; use std::process::Command; @@ -25,39 +25,29 @@ pub struct WasmPackVersion { /// Ensure that `rustc` is present and that it is >= 1.30.0 pub fn check_rustc_version() -> Result { - let local_minor_version = rustc_minor_version(); - match local_minor_version { - Some(mv) => { - if mv < 30 { - bail!( - "Your version of Rust, '1.{}', is not supported. Please install Rust version 1.30.0 or higher.", - mv.to_string() - ) - } else { - Ok(mv.to_string()) - } - } - None => bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher."), - } + try_check_rustc_version().unwrap_or_else(|| bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher.")) } // from https://github.com/alexcrichton/proc-macro2/blob/79e40a113b51836f33214c6d00228934b41bd4ad/build.rs#L44-L61 -fn rustc_minor_version() -> Option { - macro_rules! otry { - ($e:expr) => { - match $e { - Some(e) => e, - None => return None, - } - }; - } - let output = otry!(Command::new("rustc").arg("--version").output().ok()); - let version = otry!(str::from_utf8(&output.stdout).ok()); - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - otry!(pieces.next()).parse().ok() +fn try_check_rustc_version() -> Option> { + let output = Command::new("rustc").arg("--version").output().ok()?.stdout; + let minor = str::from_utf8( + output + .strip_prefix(b"rustc 1.")? + .split(|&b| b == b'.') + .next()?, + ) + .ok()?; + let supported = match minor.len() { + 2 => minor >= "30", + 1 => false, + _ => true, + }; + Some(if supported { + Ok(minor.to_owned()) + } else { + Err(anyhow!("Your version of Rust, '1.{}', is not supported. Please install Rust version 1.30.0 or higher.", minor)) + }) } /// Checks and returns local and latest versions of wasm-pack From cca671c2a51ed825e1480faaa89cd42e874dae20 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 14:36:43 +0000 Subject: [PATCH 12/85] Clippy --- src/command/login.rs | 2 +- src/command/test.rs | 2 +- src/license.rs | 2 +- src/manifest/mod.rs | 6 +++--- src/npm.rs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command/login.rs b/src/command/login.rs index 933007f2..9794a6c4 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -25,6 +25,6 @@ pub fn login( npm::npm_login(®istry, &scope, always_auth, &auth_type)?; info!("Logged you in!"); - PBAR.info(&"👋 logged you in!".to_string()); + PBAR.info("👋 logged you in!"); Ok(()) } diff --git a/src/command/test.rs b/src/command/test.rs index 3940b4af..db009944 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -129,7 +129,7 @@ impl Test { let first_arg_is_path = path_and_extra_options .get(0) - .map(|first_arg| !first_arg.starts_with("-")) + .map(|first_arg| !first_arg.starts_with('-')) .unwrap_or(false); let (path, extra_options) = if first_arg_is_path { diff --git a/src/license.rs b/src/license.rs index 483b3496..a9394c88 100644 --- a/src/license.rs +++ b/src/license.rs @@ -8,7 +8,7 @@ use crate::manifest::CrateData; use crate::PBAR; use glob::glob; -fn glob_license_files<'a>(path: &'a Path) -> Result> + 'a> { +fn glob_license_files(path: &Path) -> Result> + '_> { let joined_path = path.join("LICENSE*"); let path_string = match joined_path.to_str() { Some(path_string) => path_string, diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 4ed8bdb0..4561689e 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -188,7 +188,7 @@ fn override_stamp_file( if let Some(version) = version { write!(file, "\nversion ")?; - file.write(version)?; + file.write_all(version)?; } Ok(()) @@ -522,8 +522,8 @@ impl CrateData { .iter() .find(|t| t.kind.iter().any(|k| k == "cdylib")) { - Some(lib) => lib.name.replace("-", "_"), - None => pkg.name.replace("-", "_"), + Some(lib) => lib.name.replace('-', "_"), + None => pkg.name.replace('-', "_"), } } diff --git a/src/npm.rs b/src/npm.rs index 11d2b5f3..76d3b931 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -47,7 +47,7 @@ pub fn npm_login( cmd.arg("login").arg(build_arg("--registry=", registry)); if let Some(scope) = scope { - cmd.arg(build_arg("--scope=", &scope)); + cmd.arg(build_arg("--scope=", scope)); } if always_auth { @@ -55,7 +55,7 @@ pub fn npm_login( } if let Some(auth_type) = auth_type { - cmd.arg(build_arg("--auth_type=", &auth_type)); + cmd.arg(build_arg("--auth_type=", auth_type)); } info!("Running {:?}", cmd); From 3f35b47f09b8ead779b0d95a2ea0fe3f5cfe8f7d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 16:50:49 +0000 Subject: [PATCH 13/85] More optimization --- src/bindgen.rs | 1 - src/license.rs | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 656521bc..1a27ad9a 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -29,7 +29,6 @@ pub fn wasm_bindgen_build( BuildProfile::Dev => "debug", }; - let out_dir = out_dir.to_str().unwrap(); let has_target_dir_overwrite = extra_options.iter().any(|i| i == "--target-dir"); let target_directory = if has_target_dir_overwrite { let i = extra_options diff --git a/src/license.rs b/src/license.rs index a9394c88..b1c4d44f 100644 --- a/src/license.rs +++ b/src/license.rs @@ -1,23 +1,31 @@ //! Copy `LICENSE` file(s) for the packaged wasm. -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; +use std::ffi::OsString; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use crate::manifest::CrateData; use crate::PBAR; use glob::glob; fn glob_license_files(path: &Path) -> Result> + '_> { - let joined_path = path.join("LICENSE*"); - let path_string = match joined_path.to_str() { - Some(path_string) => path_string, - None => { - return Err(anyhow!("Could not convert joined license path to String")); - } + let mut path_buf = { + let mut os_string = OsString::with_capacity(path.as_os_str().len() + 9); + os_string.push(path); + PathBuf::from(os_string) }; + // Add trailing slash + path_buf.push(""); + // Convert to String without validating the bytes in "LICENSE*" + let mut path_string = path_buf + .into_os_string() + .into_string() + .ok() + .context("Could not convert joined license path to String")?; + path_string.push_str("LICENSE*"); - Ok(glob(path_string)?.map(|entry| match entry { + Ok(glob(&path_string)?.map(|entry| match entry { Ok(globed_path) => { let file_name = match globed_path.file_name() { Some(file_name) => file_name, From 836fe7dc0d4bc0900434509d1605e1a79311f9e4 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 21:36:27 +0000 Subject: [PATCH 14/85] Add perf feature --- .gitignore | 1 + Cargo.lock | 49 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/command/build.rs | 4 ++-- src/command/test.rs | 4 ++-- src/command/utils.rs | 11 ++++++++++ src/main.rs | 7 +++++++ 7 files changed, 74 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4d857446..cd34a72c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tests/bin /build-installer docs/book docs/installer +dhat-heap.json diff --git a/Cargo.lock b/Cargo.lock index 8c647be5..9dac857b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,6 +645,22 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "dhat" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2aaf837aaf456f6706cb46386ba8dffd4013a757e36f4ea05c20dd46b209a3" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot", + "rustc-hash", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "dialoguer" version = "0.10.3" @@ -1320,6 +1336,16 @@ dependencies = [ "adler", ] +[[package]] +name = "mintex" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7c5ba1c3b5a23418d7bbf98c71c3d4946a0125002129231da8d6b723d559cb" +dependencies = [ + "once_cell", + "sys-info", +] + [[package]] name = "mio" version = "0.8.6" @@ -1780,6 +1806,12 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustix" version = "0.36.10" @@ -2071,6 +2103,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-info" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "tar" version = "0.4.38" @@ -2145,6 +2187,12 @@ dependencies = [ "syn 2.0.2", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "time" version = "0.1.45" @@ -2516,6 +2564,7 @@ dependencies = [ "console", "criterion", "curl", + "dhat", "dialoguer", "env_logger", "glob", diff --git a/Cargo.toml b/Cargo.toml index 5c0d1808..512e1b18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ cargo_metadata = "0.15.2" chrono = "0.4.23" console = "0.15.5" curl = "0.4.44" +dhat = { version = "0.3.2", optional = true } dialoguer = "0.10.3" env_logger = { version = "0.10.0", default-features = false } glob = "0.3.1" @@ -53,6 +54,7 @@ tempfile = "3.3.0" [features] # OpenSSL is vendored by default, can use system OpenSSL through feature flag. default = ['openssl/vendored'] +perf = ["dep:dhat"] # Treat compiler warnings as a build error. # This only runs in CI by default diff --git a/src/command/build.rs b/src/command/build.rs index a8c9e9fa..bdab0fef 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -258,8 +258,8 @@ impl Build { let started = Instant::now(); - for (_, process_step) in process_steps { - process_step(self)?; + for process_step in process_steps { + super::utils::run_step(process_step, self)?; } let duration = crate::command::utils::elapsed(started.elapsed()); diff --git a/src/command/test.rs b/src/command/test.rs index db009944..a80603ee 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -185,8 +185,8 @@ impl Test { let process_steps = self.get_process_steps(); let started = Instant::now(); - for (_, process_step) in process_steps { - process_step(&mut self)?; + for process_step in process_steps { + super::utils::run_step(process_step, &mut self)?; } let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); diff --git a/src/command/utils.rs b/src/command/utils.rs index 152dd99a..2a5da5a1 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -70,3 +70,14 @@ pub fn elapsed(duration: Duration) -> String { format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000) } } + +/// Runs a funcion and reports duration if `perf` feature is enabled +pub fn run_step((name, mut f): (&'static str, impl FnMut(T) -> U), arg: T) -> U { + let start = std::time::Instant::now(); + let result = f(arg); + #[cfg(feature = "perf")] + println!("{}: {} s", name, start.elapsed().as_secs_f64()); + #[cfg(not(feature = "perf"))] + let _ = name; + result +} diff --git a/src/main.rs b/src/main.rs index 72739809..67320eda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,10 @@ use wasm_pack::{ mod installer; +#[cfg(feature = "perf")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + fn background_check_for_updates() -> mpsc::Receiver> { let (sender, receiver) = mpsc::channel(); @@ -45,6 +49,9 @@ fn background_check_for_updates() -> mpsc::Receiver> { } fn main() { + #[cfg(feature = "perf")] + let _profiler = dhat::Profiler::new_heap(); + env_logger::init(); setup_panic_hooks(); From 130e237833e09cae1aef6e8bcebe838b81dc810b Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 21:43:01 +0000 Subject: [PATCH 15/85] Refactor run_step --- src/command/utils.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/command/utils.rs b/src/command/utils.rs index 2a5da5a1..70d76bf7 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -73,11 +73,16 @@ pub fn elapsed(duration: Duration) -> String { /// Runs a funcion and reports duration if `perf` feature is enabled pub fn run_step((name, mut f): (&'static str, impl FnMut(T) -> U), arg: T) -> U { - let start = std::time::Instant::now(); - let result = f(arg); #[cfg(feature = "perf")] - println!("{}: {} s", name, start.elapsed().as_secs_f64()); + { + let start = std::time::Instant::now(); + let result = f(arg); + println!("{}: {} s", name, start.elapsed().as_secs_f64()); + result + } #[cfg(not(feature = "perf"))] - let _ = name; - result + { + let _ = name; + f(arg) + } } From 4d90f54a4e9e7950906bdf0fcaf5408b9360060f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 22:45:03 +0000 Subject: [PATCH 16/85] Optimize lockfile --- src/lockfile.rs | 60 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/src/lockfile.rs b/src/lockfile.rs index f4a68eac..9db10e0a 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -13,14 +13,55 @@ use toml; /// This struct represents the contents of `Cargo.lock`. #[derive(Clone, Debug, Deserialize)] pub struct Lockfile { - package: Vec, + package: Packages, +} + +#[derive(Clone, Debug, Default)] +struct Packages { + wasm_bindgen_version: Option, + wasm_bindgen_test_version: Option, } /// This struct represents a single package entry in `Cargo.lock` #[derive(Clone, Debug, Deserialize)] -struct Package { - name: String, - version: String, +struct Package<'a> { + name: &'a str, + version: &'a str, +} + +impl<'de> serde::Deserialize<'de> for Packages { + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + deserializer.deserialize_seq(PackagesVisitor) + } +} + +struct PackagesVisitor; + +impl<'de> serde::de::Visitor<'de> for PackagesVisitor { + type Value = Packages; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("a sequence") + } + + fn visit_seq(self, mut seq: A) -> std::result::Result + where + A: serde::de::SeqAccess<'de>, + { + let mut result = Packages::default(); + while let Some(package) = seq.next_element::()? { + let field = match package.name { + "wasm-bindgen" => &mut result.wasm_bindgen_version, + "wasm-bindgen-test" => &mut result.wasm_bindgen_test_version, + _ => continue, + }; + *field = Some(package.version.to_owned()); + } + Ok(result) + } } impl Lockfile { @@ -36,7 +77,7 @@ impl Lockfile { /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. pub fn wasm_bindgen_version(&self) -> Option<&str> { - self.get_package_version("wasm-bindgen") + self.package.wasm_bindgen_version.as_deref() } /// Like `wasm_bindgen_version`, except it returns an error instead of @@ -54,14 +95,7 @@ impl Lockfile { /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. pub fn wasm_bindgen_test_version(&self) -> Option<&str> { - self.get_package_version("wasm-bindgen-test") - } - - fn get_package_version(&self, package: &str) -> Option<&str> { - self.package - .iter() - .find(|p| p.name == package) - .map(|p| &p.version[..]) + self.package.wasm_bindgen_test_version.as_deref() } } From 0725710ef75ebd62f2608af3dcbd25fe383b8566 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 8 Apr 2023 23:08:49 +0000 Subject: [PATCH 17/85] Use iai benchmark --- Cargo.lock | 235 ++--------------------------------------------- Cargo.toml | 2 +- benches/bench.rs | 21 ++--- 3 files changed, 18 insertions(+), 240 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9dac857b..efc5c675 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,12 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "ansi_term" version = "0.12.1" @@ -283,12 +277,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.79" @@ -319,33 +307,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ciborium" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" - -[[package]] -name = "ciborium-ll" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "cipher" version = "0.3.0" @@ -365,32 +326,11 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap 0.11.0", + "textwrap", "unicode-width", "vec_map", ] -[[package]] -name = "clap" -version = "3.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" -dependencies = [ - "bitflags", - "clap_lex", - "indexmap", - "textwrap 0.16.0", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -469,76 +409,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" -dependencies = [ - "anes", - "atty", - "cast", - "ciborium", - "clap 3.2.23", - "criterion-plot", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - [[package]] name = "crossbeam-utils" version = "0.8.15" @@ -977,12 +847,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - [[package]] name = "hashbrown" version = "0.12.3" @@ -1124,6 +988,12 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iai" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1312,15 +1182,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.16" @@ -1426,12 +1287,6 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "opaque-debug" version = "0.3.0" @@ -1504,12 +1359,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1580,34 +1429,6 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" -[[package]] -name = "plotters" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" - -[[package]] -name = "plotters-svg" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" -dependencies = [ - "plotters-backend", -] - [[package]] name = "predicates" version = "2.1.5" @@ -1698,28 +1519,6 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -[[package]] -name = "rayon" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -2057,7 +1856,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap 2.34.0", + "clap", "lazy_static", "structopt-derive", ] @@ -2161,12 +1960,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.40" @@ -2220,16 +2013,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -2562,13 +2345,13 @@ dependencies = [ "cargo_metadata", "chrono", "console", - "criterion", "curl", "dhat", "dialoguer", "env_logger", "glob", "human-panic", + "iai", "lazy_static", "log", "openssl", diff --git a/Cargo.toml b/Cargo.toml index 512e1b18..a3723378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ which = "4.4.0" [dev-dependencies] assert_cmd = "2.0.8" -criterion = "0.4.0" +iai = "0.1" lazy_static = "1.4.0" predicates = "2.1.5" serial_test = "1.0.0" diff --git a/benches/bench.rs b/benches/bench.rs index 7aabc1dc..0314c2aa 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -2,23 +2,15 @@ #[allow(unused)] mod fixture; -use criterion::{criterion_group, criterion_main, Criterion}; use std::process::Stdio; -pub fn criterion_benchmark(c: &mut Criterion) { - let mut g = c.benchmark_group("wasm-pack"); - g.warm_up_time(std::time::Duration::from_secs(10)); +fn run_wasm_pack() { let fixture = fixture::dual_license(); - run(&fixture); - g.bench_function("re-run build without code changes", |b| { - b.iter(|| run(&fixture)) - }); -} - -fn run(fixture: &fixture::Fixture) { assert!(fixture .wasm_pack() .arg("build") + .arg("--mode") + .arg("no-install") .stdout(Stdio::null()) .stderr(Stdio::null()) .status() @@ -26,5 +18,8 @@ fn run(fixture: &fixture::Fixture) { .success()) } -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); +fn parse_crates_io() { + assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); +} + +iai::main!(run_wasm_pack, parse_crates_io); From 204b138723a27e3b92ca054f3e67c87cfc3e8afe Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 9 Apr 2023 04:07:18 +0000 Subject: [PATCH 18/85] Fix bench --- benches/bench.rs | 21 ++++---- src/lib.rs | 109 ++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 122 +---------------------------------------------- 3 files changed, 120 insertions(+), 132 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 0314c2aa..eae93f01 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -2,20 +2,19 @@ #[allow(unused)] mod fixture; -use std::process::Stdio; +use std::ffi::OsString; fn run_wasm_pack() { let fixture = fixture::dual_license(); - assert!(fixture - .wasm_pack() - .arg("build") - .arg("--mode") - .arg("no-install") - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .unwrap() - .success()) + std::env::set_current_dir(&fixture.path).unwrap(); + std::env::set_var("WASM_PACK_CACHE", fixture.cache_dir()); + for _ in 0..8 { + wasm_pack::main( + ["wasm-pack", "build", "--mode", "force"] + .into_iter() + .map(|i| OsString::from(i)), + ); + } } fn parse_crates_io() { diff --git a/src/lib.rs b/src/lib.rs index 8410b484..c9e51054 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ pub mod command; pub mod emoji; pub mod generate; pub mod install; +mod installer; pub mod license; pub mod lockfile; pub mod manifest; @@ -45,6 +46,13 @@ pub mod test; pub mod wasm_opt; use crate::progressbar::{LogLevel, ProgressOutput}; +use crate::{build::WasmPackVersion, command::run_wasm_pack}; +use anyhow::Result; +use std::env; +use std::panic; +use std::sync::mpsc; +use std::thread; +use structopt::StructOpt; /// The global progress bar and user-facing message output. pub static PBAR: ProgressOutput = ProgressOutput::new(); @@ -68,3 +76,104 @@ pub struct Cli { /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } + +fn background_check_for_updates() -> mpsc::Receiver> { + let (sender, receiver) = mpsc::channel(); + + let _detached_thread = thread::spawn(move || { + let wasm_pack_version = build::check_wasm_pack_versions(); + + if let Ok(wasm_pack_version) = wasm_pack_version { + if !wasm_pack_version.local.is_empty() + && !wasm_pack_version.latest.is_empty() + && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest + { + let _ = sender.send(Ok(wasm_pack_version)); + } + } else { + let _ = sender.send(wasm_pack_version); + } + }); + + receiver +} + +/// Runs the CLI +pub fn main(args: impl Iterator) { + let _ = env_logger::try_init(); + + setup_panic_hooks(); + + if let Err(e) = run(args) { + eprintln!("Error: {}", e); + for cause in e.chain() { + eprintln!("Caused by: {}", cause); + } + ::std::process::exit(1); + } +} + +fn run(cmd_args: impl Iterator) -> Result<()> { + let wasm_pack_version = background_check_for_updates(); + + // Deprecate `init` + if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { + println!("wasm-pack init is deprecated, consider using wasm-pack build"); + } + + if let Ok(me) = env::current_exe() { + // If we're actually running as the installer then execute our + // self-installation, otherwise just continue as usual. + if me + .file_stem() + .and_then(|s| s.to_str()) + .expect("executable should have a filename") + .starts_with("wasm-pack-init") + { + installer::install(); + } + } + + let args = Cli::from_iter(cmd_args); + + PBAR.set_log_level(args.log_level); + + if args.quiet { + PBAR.set_quiet(true); + } + + run_wasm_pack(args.cmd)?; + + if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() { + match wasm_pack_version { + Ok(wasm_pack_version) => + PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ + To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), + Err(err) => PBAR.warn(&format!("{}", err)) + } + } + Ok(()) +} + +fn setup_panic_hooks() { + let meta = human_panic::Metadata { + version: env!("CARGO_PKG_VERSION").into(), + name: env!("CARGO_PKG_NAME").into(), + authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), + homepage: env!("CARGO_PKG_HOMEPAGE").into(), + }; + + let default_hook = panic::take_hook(); + + if let Err(_) = env::var("RUST_BACKTRACE") { + panic::set_hook(Box::new(move |info: &panic::PanicInfo| { + // First call the default hook that prints to standard error. + default_hook(info); + + // Then call human_panic. + let file_path = human_panic::handle_dump(&meta, info); + human_panic::print_msg(file_path, &meta) + .expect("human-panic: printing error message to console failed"); + })); + } +} diff --git a/src/main.rs b/src/main.rs index 67320eda..f88b3e33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,132 +1,12 @@ -#![allow(clippy::redundant_closure, clippy::redundant_pattern_matching)] - -extern crate anyhow; -extern crate atty; -extern crate env_logger; -extern crate human_panic; -extern crate log; -extern crate structopt; extern crate wasm_pack; -extern crate which; - -use anyhow::Result; -use std::env; -use std::panic; -use std::sync::mpsc; -use std::thread; -use structopt::StructOpt; -use wasm_pack::{ - build::{self, WasmPackVersion}, - command::run_wasm_pack, - Cli, PBAR, -}; - -mod installer; #[cfg(feature = "perf")] #[global_allocator] static ALLOC: dhat::Alloc = dhat::Alloc; -fn background_check_for_updates() -> mpsc::Receiver> { - let (sender, receiver) = mpsc::channel(); - - let _detached_thread = thread::spawn(move || { - let wasm_pack_version = build::check_wasm_pack_versions(); - - if let Ok(wasm_pack_version) = wasm_pack_version { - if !wasm_pack_version.local.is_empty() - && !wasm_pack_version.latest.is_empty() - && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest - { - let _ = sender.send(Ok(wasm_pack_version)); - } - } else { - let _ = sender.send(wasm_pack_version); - } - }); - - receiver -} - fn main() { #[cfg(feature = "perf")] let _profiler = dhat::Profiler::new_heap(); - env_logger::init(); - - setup_panic_hooks(); - - if let Err(e) = run() { - eprintln!("Error: {}", e); - for cause in e.chain() { - eprintln!("Caused by: {}", cause); - } - ::std::process::exit(1); - } -} - -fn run() -> Result<()> { - let wasm_pack_version = background_check_for_updates(); - - // Deprecate `init` - if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { - println!("wasm-pack init is deprecated, consider using wasm-pack build"); - } - - if let Ok(me) = env::current_exe() { - // If we're actually running as the installer then execute our - // self-installation, otherwise just continue as usual. - if me - .file_stem() - .and_then(|s| s.to_str()) - .expect("executable should have a filename") - .starts_with("wasm-pack-init") - { - installer::install(); - } - } - - let args = Cli::from_args(); - - PBAR.set_log_level(args.log_level); - - if args.quiet { - PBAR.set_quiet(true); - } - - run_wasm_pack(args.cmd)?; - - if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() { - match wasm_pack_version { - Ok(wasm_pack_version) => - PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ - To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), - Err(err) => PBAR.warn(&format!("{}", err)) - } - } - - Ok(()) -} - -fn setup_panic_hooks() { - let meta = human_panic::Metadata { - version: env!("CARGO_PKG_VERSION").into(), - name: env!("CARGO_PKG_NAME").into(), - authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), - homepage: env!("CARGO_PKG_HOMEPAGE").into(), - }; - - let default_hook = panic::take_hook(); - - if let Err(_) = env::var("RUST_BACKTRACE") { - panic::set_hook(Box::new(move |info: &panic::PanicInfo| { - // First call the default hook that prints to standard error. - default_hook(info); - - // Then call human_panic. - let file_path = human_panic::handle_dump(&meta, info); - human_panic::print_msg(file_path, &meta) - .expect("human-panic: printing error message to console failed"); - })); - } + wasm_pack::main(std::env::args_os()) } From 2db60b3a4726c9d143805727e2853ec589b1234b Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 9 Apr 2023 04:19:03 +0000 Subject: [PATCH 19/85] Add more benchmarks --- benches/bench.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/benches/bench.rs b/benches/bench.rs index eae93f01..88cd6570 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -3,6 +3,7 @@ mod fixture; use std::ffi::OsString; +use wasm_pack::build::{check_rustc_version, wasm_target::check_for_wasm32_target}; fn run_wasm_pack() { let fixture = fixture::dual_license(); @@ -21,4 +22,9 @@ fn parse_crates_io() { assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); } -iai::main!(run_wasm_pack, parse_crates_io); +iai::main!( + run_wasm_pack, + parse_crates_io, + check_rustc_version, + check_for_wasm32_target +); From c6f1b56e0b62c961a4b1c4d10edf7843f86dad75 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 9 Apr 2023 17:10:45 +0000 Subject: [PATCH 20/85] Stuff --- .gitignore | 2 +- benches/bench.rs | 23 +- benches/lockfile.txt | 1446 ++++++++++++++++++++++++++++++++++++++ src/bindgen.rs | 9 +- src/build/wasm_target.rs | 14 +- 5 files changed, 1472 insertions(+), 22 deletions(-) create mode 100644 benches/lockfile.txt diff --git a/.gitignore b/.gitignore index cd34a72c..b7eb8db9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ tests/bin /build-installer docs/book docs/installer -dhat-heap.json +dhat-*.json diff --git a/benches/bench.rs b/benches/bench.rs index 88cd6570..d42e76b0 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -9,22 +9,27 @@ fn run_wasm_pack() { let fixture = fixture::dual_license(); std::env::set_current_dir(&fixture.path).unwrap(); std::env::set_var("WASM_PACK_CACHE", fixture.cache_dir()); - for _ in 0..8 { - wasm_pack::main( - ["wasm-pack", "build", "--mode", "force"] - .into_iter() - .map(|i| OsString::from(i)), - ); - } + + wasm_pack::main( + ["wasm-pack", "build", "--mode", "force"] + .into_iter() + .map(|i| OsString::from(i)), + ); } fn parse_crates_io() { - assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); + assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(iai::black_box(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#))); +} + +fn parse_lockfile() -> wasm_pack::lockfile::Lockfile { + let bytes = iai::black_box(include_bytes!("lockfile.txt")); + toml::from_slice(bytes).unwrap() } iai::main!( run_wasm_pack, parse_crates_io, check_rustc_version, - check_for_wasm32_target + check_for_wasm32_target, + parse_lockfile ); diff --git a/benches/lockfile.txt b/benches/lockfile.txt new file mode 100644 index 00000000..f67749be --- /dev/null +++ b/benches/lockfile.txt @@ -0,0 +1,1446 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "async-trait" +version = "0.1.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.0", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "axgeom" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db217c826c3f4cb10bb278b0fe0c6e17483bb1e9213709d229d2f18fa90cdca5" +dependencies = [ + "num-traits", + "partial-min-max", + "serde", +] + +[[package]] +name = "axum" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d8068b6ccb8b34db9de397c7043f91db8b4c66414952c6db944f238c4d3db3" +dependencies = [ + "async-trait", + "axum-core", + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2f958c80c248b34b9a877a643811be8dbca03ca5ba827f2b63baf3a81e5fc4e" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "broccoli" +version = "6.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83629ad677c5ae614adc2536be0345f4ccece257bd08152a6589481cbc4b3ec5" +dependencies = [ + "axgeom", + "compt", + "revec", + "slice-group-by", + "twounordered", +] + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "compt" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e76b03e56db9abaa17c0df498682806499690473fc2b4b035a018d9b75053e3e" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "deku" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819b87cc7a05b3abe3fc38e59b3980a5fd3162f25a247116441a9171d3e84481" +dependencies = [ + "bitvec", + "deku_derive", +] + +[[package]] +name = "deku_derive" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e2ca12572239215a352a74ad7c776d7e8a914f8a23511c6cbedddd887e5009e" +dependencies = [ + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "enclose" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1056f553da426e9c025a662efa48b52e62e0a3a7648aa2d15aeaaf7f0d329357" + +[[package]] +name = "euclid" +version = "0.22.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52c2ef4a78da0ba68fbe1fd920627411096d2ac478f7f4c9f3a54ba6705bade" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" + +[[package]] +name = "futures-executor" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" + +[[package]] +name = "futures-macro" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "futures-sink" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" + +[[package]] +name = "futures-task" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" + +[[package]] +name = "futures-util" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "gloo-events" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b107f8abed8105e4182de63845afcc7b69c098b7852a813ea7462a320992fc" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-file" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7" +dependencies = [ + "futures-channel", + "gloo-events", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "gloo-utils" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "h2" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" + +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "lyon_geom" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74df1ff0a0147282eb10699537a03baa7d31972b58984a1d44ce0624043fe8ad" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "matchit" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "owned_ttf_parser" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25e9fb15717794fae58ab55c26e044103aad13186fbb625893f9a3bbcc24228" +dependencies = [ + "ttf-parser", +] + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "partial-min-max" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6448add382c60bbbc64f9dab41309a12ec530c05191601042f911356ac09758c" + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "revec" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64dfec684e04cbb4a5f03ed70ac988c8d9d96db894c8e7d2ac42bbf3f91ea5b" + +[[package]] +name = "rustversion" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "seed" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c0e296ea0569d20467e9a1df3cb6ed66ce3b791a7eaf1e1110ae231f75e2b46" +dependencies = [ + "enclose", + "futures", + "getrandom", + "gloo-file", + "gloo-timers", + "gloo-utils", + "indexmap", + "js-sys", + "rand", + "uuid", + "version_check", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "serde" +version = "1.0.157" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.157" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.0", +] + +[[package]] +name = "serde_json" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "sled" +version = "0.34.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" +dependencies = [ + "crc32fast", + "crossbeam-epoch", + "crossbeam-utils", + "fs2", + "fxhash", + "libc", + "log", + "parking_lot", +] + +[[package]] +name = "slice-group-by" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cff13bb1732bccfe3b246f3fdb09edfd51c01d6f5299b7ccd9457c2e4e37774" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tokio" +version = "1.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "windows-sys", +] + +[[package]] +name = "tokio-util" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml_datetime" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" + +[[package]] +name = "toml_edit" +version = "0.19.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc18466501acd8ac6a3f615dd29a3438f8ca6bb3b19537138b3106e575621274" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "ttf-parser" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0609f771ad9c6155384897e1df4d948e692667cc0588548b68eb44d052b27633" + +[[package]] +name = "twounordered" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f40128da4fef8c4bf9cc1ab73d8126cb1148660d37a93d4a5110002a80657ba" + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "uuid" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +dependencies = [ + "getrandom", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 1.0.109", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "web-log" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57583eade6ead63af3267790de55b6e5dbe9fe2257ccc213feb62ab67f5c2dd3" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "winnow" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d020b441f92996c80d94ae9166e8501e59c7bb56121189dc9eab3bd8216966" +dependencies = [ + "memchr", +] + +[[package]] +name = "workspace-backend" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "deku", + "fastrand", + "tokio", + "workspace-database", + "workspace-glyph", +] + +[[package]] +name = "workspace-database" +version = "0.1.0" +dependencies = [ + "anyhow", + "deku", + "sled", + "workspace-shared", +] + +[[package]] +name = "workspace-font-editor" +version = "0.1.0" +dependencies = [ + "broccoli", + "deku", + "js-sys", + "lyon_geom", + "owned_ttf_parser", + "seed", + "wasm-bindgen", + "web-log", + "web-sys", + "workspace-glyph", + "workspace-glyph-builder", + "workspace-glyph-svg", +] + +[[package]] +name = "workspace-frontend" +version = "0.1.0" +dependencies = [ + "console_error_panic_hook", + "seed", + "wasm-bindgen", + "workspace-font-editor", +] + +[[package]] +name = "workspace-frontend-cdylib" +version = "0.1.0" +dependencies = [ + "wasm-bindgen", + "workspace-frontend", + "workspace-glyph-svg", +] + +[[package]] +name = "workspace-glyph" +version = "0.1.0" +dependencies = [ + "broccoli", + "deku", + "fastrand", +] + +[[package]] +name = "workspace-glyph-builder" +version = "0.1.0" +dependencies = [ + "fastrand", + "workspace-glyph", +] + +[[package]] +name = "workspace-glyph-svg" +version = "0.1.0" +dependencies = [ + "broccoli", + "seed", + "wasm-bindgen", + "workspace-glyph", +] + +[[package]] +name = "workspace-shared" +version = "0.1.0" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] diff --git a/src/bindgen.rs b/src/bindgen.rs index 1a27ad9a..9c2cc599 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -42,11 +42,10 @@ pub fn wasm_bindgen_build( data.target_directory() }; - let wasm_path = target_directory - .join("wasm32-unknown-unknown") - .join(release_or_debug) - .join(data.crate_name()) - .with_extension("wasm"); + let mut wasm_path = target_directory.join("wasm32-unknown-unknown"); + wasm_path.push(release_or_debug); + wasm_path.push(data.crate_name()); + wasm_path.set_extension("wasm"); let dts_arg = if disable_dts { "--no-typescript" diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 718beb69..7f4da59b 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -84,15 +84,16 @@ fn get_rustc_sysroot() -> Result { fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { let wasm32_target = "wasm32-unknown-unknown"; - let rustlib_path = sysroot.join("lib/rustlib"); + let mut path = sysroot.join("lib/rustlib"); - info!("Looking for {} in {:?}", wasm32_target, rustlib_path); + info!("Looking for {} in {:?}", wasm32_target, path); + path.push(wasm32_target); - if rustlib_path.join(wasm32_target).exists() { - info!("Found {} in {:?}", wasm32_target, rustlib_path); + if path.exists() { + info!("Found {} in {:?}", wasm32_target, path.parent()); true } else { - info!("Failed to find {} in {:?}", wasm32_target, rustlib_path); + info!("Failed to find {} in {:?}", wasm32_target, path.parent()); false } } @@ -105,14 +106,13 @@ fn check_wasm32_target() -> Result> { Ok(None) // If it doesn't exist, then we need to check if we're using rustup. } else { - let rustc_path = which::which("rustc")?; // If sysroot contains "rustup", then we can assume we're using rustup // and use rustup to add the wasm32-unknown-unknown target. if sysroot.to_string_lossy().contains("rustup") { rustup_add_wasm_target().map(|()| None) } else { Ok(Some(Wasm32Check { - rustc_path, + rustc_path: which::which("rustc")?, sysroot, found: false, is_rustup: false, From 1b6f23fc645df8df9161cde4bf564484722ad889 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 9 Apr 2023 18:10:12 +0000 Subject: [PATCH 21/85] Clippy --- src/bindgen.rs | 2 +- src/build/mod.rs | 2 +- src/build/wasm_target.rs | 2 +- src/command/build.rs | 9 ++------- src/command/login.rs | 2 +- src/command/test.rs | 2 +- src/command/utils.rs | 4 ++-- src/generate.rs | 6 +++--- src/install/krate.rs | 2 +- src/install/mod.rs | 2 +- src/install/mode.rs | 9 ++------- src/installer.rs | 4 +--- src/lib.rs | 6 +++--- src/license.rs | 4 ++-- src/manifest/mod.rs | 32 +++++++++++++++++--------------- src/manifest/npm/mod.rs | 6 +++--- src/readme.rs | 4 ++-- src/wasm_opt.rs | 9 ++++----- 18 files changed, 48 insertions(+), 59 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 9c2cc599..3a7dad49 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -22,7 +22,7 @@ pub fn wasm_bindgen_build( reference_types: bool, target: Target, profile: BuildProfile, - extra_options: &Vec, + extra_options: &[OsString], ) -> Result<()> { let release_or_debug = match profile { BuildProfile::Release | BuildProfile::Profiling => "release", diff --git a/src/build/mod.rs b/src/build/mod.rs index 7d7c33f1..ea82bc8c 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -53,7 +53,7 @@ fn try_check_rustc_version() -> Option> { /// Checks and returns local and latest versions of wasm-pack pub fn check_wasm_pack_versions() -> Result { match wasm_pack_local_version() { - Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or_else(|| Vec::new())}), + Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or(vec![])}), None => bail!("We can't figure out what your wasm-pack version is, make sure the installation path is correct.") } } diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 7f4da59b..dccb3c87 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -67,7 +67,7 @@ pub fn check_for_wasm32_target() -> Result<()> { /// Get rustc's sysroot as a PathBuf fn get_rustc_sysroot() -> Result { let command = Command::new("rustc") - .args(&["--print", "sysroot"]) + .args(["--print", "sysroot"]) .output()?; if command.status.success() { diff --git a/src/command/build.rs b/src/command/build.rs index bdab0fef..4acc88b7 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -42,10 +42,11 @@ pub struct Build { /// What sort of output we're going to be generating and flags we're invoking /// `wasm-bindgen` with. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] pub enum Target { /// Default output mode or `--target bundler`, indicates output will be /// used with a bundle in a later step. + #[default] Bundler, /// Correspond to `--target web` where the output is natively usable as an /// ES module in a browser and the wasm is manually instantiated. @@ -62,12 +63,6 @@ pub enum Target { Deno, } -impl Default for Target { - fn default() -> Target { - Target::Bundler - } -} - impl fmt::Display for Target { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = match self { diff --git a/src/command/login.rs b/src/command/login.rs index 9794a6c4..63f67841 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -22,7 +22,7 @@ pub fn login( &auth_type ); info!("npm info located in the npm debug log"); - npm::npm_login(®istry, &scope, always_auth, &auth_type)?; + npm::npm_login(®istry, scope, always_auth, auth_type)?; info!("Logged you in!"); PBAR.info("👋 logged you in!"); diff --git a/src/command/test.rs b/src/command/test.rs index a80603ee..efe2cf07 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -302,7 +302,7 @@ impl Test { let status = install::download_prebuilt_or_cargo_install( Tool::WasmBindgen, &self.cache, - &bindgen_version, + bindgen_version, self.mode.install_permitted(), )?; diff --git a/src/command/utils.rs b/src/command/utils.rs index 70d76bf7..a1ea0eb8 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -38,7 +38,7 @@ fn find_manifest_from_cwd() -> Result { /// Construct our `pkg` directory in the crate. pub fn create_pkg_dir(out_dir: &Path) -> Result<()> { let _ = fs::remove_file(out_dir.join("package.json")); // Clean up package.json from previous runs - fs::create_dir_all(&out_dir)?; + fs::create_dir_all(out_dir)?; fs::write(out_dir.join(".gitignore"), "*")?; Ok(()) } @@ -53,7 +53,7 @@ pub fn find_pkg_directory(path: &Path) -> Option { WalkDir::new(path) .into_iter() .filter_map(|x| x.ok().map(|e| e.into_path())) - .find(|x| is_pkg_directory(&x)) + .find(|x| is_pkg_directory(x)) } fn is_pkg_directory(path: &Path) -> bool { diff --git a/src/generate.rs b/src/generate.rs index 5ea920bd..c58993e3 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,10 +12,10 @@ use std::process::Command; pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; - let mut cmd = Command::new(&bin_path); + let mut cmd = Command::new(bin_path); cmd.arg("generate"); - cmd.arg("--git").arg(&template); - cmd.arg("--name").arg(&name); + cmd.arg("--git").arg(template); + cmd.arg("--name").arg(name); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/krate.rs b/src/install/krate.rs index 4ac2facf..d8ec163b 100644 --- a/src/install/krate.rs +++ b/src/install/krate.rs @@ -17,7 +17,7 @@ impl Krate { pub fn new(name: &Tool) -> Result { let krate_address = format!("https://crates.io/api/v1/crates/{}", name); let client = reqwest::blocking::Client::new(); - let res = client.get(&krate_address).send()?; + let res = client.get(krate_address).send()?; let kr: KrateResponse = serde_json::from_str(&res.text()?)?; Ok(kr.krate) diff --git a/src/install/mod.rs b/src/install/mod.rs index c4361407..571bec3d 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -110,7 +110,7 @@ pub fn get_cli_version(tool: &Tool, path: &Path) -> Result { let mut cmd = Command::new(path); cmd.arg("--version"); let stdout = child::run_capture_stdout(cmd, tool)?; - let version = stdout.trim().split_whitespace().nth(1); + let version = stdout.split_whitespace().nth(1); match version { Some(v) => Ok(v.to_string()), None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.") diff --git a/src/install/mode.rs b/src/install/mode.rs index b017d9a3..bfcb57a2 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -2,9 +2,10 @@ use std::ffi::{OsStr, OsString}; /// The `InstallMode` determines which mode of initialization we are running, and /// what install steps we perform. -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] pub enum InstallMode { /// Perform all the install steps. + #[default] Normal, /// Don't install tools like `wasm-bindgen`, just use the global /// environment's existing versions to do builds. @@ -13,12 +14,6 @@ pub enum InstallMode { Force, } -impl Default for InstallMode { - fn default() -> InstallMode { - InstallMode::Normal - } -} - impl InstallMode { /// Converts from `OsStr` pub fn parse(s: &OsStr) -> Result { diff --git a/src/installer.rs b/src/installer.rs index 67f2b6b0..1c97fb15 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -23,8 +23,6 @@ use std::path::Path; use std::process; use anyhow::{anyhow, bail, Context, Result}; -use atty; -use which; pub fn install() -> ! { if let Err(e) = do_install() { @@ -73,7 +71,7 @@ fn do_install() -> Result<()> { // Our relatively simple install step! let me = env::current_exe()?; - fs::copy(&me, &destination) + fs::copy(me, &destination) .with_context(|| anyhow!("failed to copy executable to `{}`", destination.display()))?; println!( "info: successfully installed wasm-pack to `{}`", diff --git a/src/lib.rs b/src/lib.rs index c9e51054..f0cfac14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,7 @@ fn run(cmd_args: impl Iterator) -> Result<()> { let wasm_pack_version = background_check_for_updates(); // Deprecate `init` - if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { + if let Some("init") = env::args().nth(1).as_deref() { println!("wasm-pack init is deprecated, consider using wasm-pack build"); } @@ -159,13 +159,13 @@ fn setup_panic_hooks() { let meta = human_panic::Metadata { version: env!("CARGO_PKG_VERSION").into(), name: env!("CARGO_PKG_NAME").into(), - authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), + authors: env!("CARGO_PKG_AUTHORS").replace(':', ", ").into(), homepage: env!("CARGO_PKG_HOMEPAGE").into(), }; let default_hook = panic::take_hook(); - if let Err(_) = env::var("RUST_BACKTRACE") { + if env::var("RUST_BACKTRACE").is_err() { panic::set_hook(Box::new(move |info: &panic::PanicInfo| { // First call the default hook that prints to standard error. default_hook(info); diff --git a/src/license.rs b/src/license.rs index b1c4d44f..a6636457 100644 --- a/src/license.rs +++ b/src/license.rs @@ -49,7 +49,7 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R ); assert!( - fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()), + fs::metadata(out_dir).ok().map_or(false, |m| m.is_dir()), "crate's pkg directory should exist" ); @@ -79,7 +79,7 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R (None, Some(license_file)) => { let crate_license_path = path.join(&license_file); let new_license_path = out_dir.join(&license_file); - if fs::copy(&crate_license_path, &new_license_path).is_err() { + if fs::copy(crate_license_path, new_license_path).is_err() { PBAR.info("origin crate has no LICENSE"); } } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 4561689e..887defce 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -136,7 +136,7 @@ pub fn return_wasm_pack_latest_version() -> Result>> { match old_metadata_file { Some(ref file_contents) => { - let last_updated = return_stamp_file_value(&file_contents, b"created") + let last_updated = return_stamp_file_value(file_contents, b"created") .and_then(|t| DateTime::parse_from_str(&String::from_utf8_lossy(t), "%+").ok()); last_updated @@ -144,8 +144,10 @@ pub fn return_wasm_pack_latest_version() -> Result>> { if current_time.signed_duration_since(last_updated).num_hours() > 24 { return_api_call_result(current_time).map(Some) } else { - Ok(return_stamp_file_value(&file_contents, b"version") - .map(|f| f.to_owned())) + Ok( + return_stamp_file_value(file_contents, b"version") + .map(|f| f.to_owned()), + ) } }) .unwrap_or_else(|| Ok(None)) @@ -162,7 +164,7 @@ fn return_api_call_result(current_time: DateTime) -> Result override_stamp_file(current_time, Some(&version)).ok(), + Ok(ref version) => override_stamp_file(current_time, Some(version)).ok(), Err(_) => override_stamp_file(current_time, None).ok(), }; @@ -224,7 +226,7 @@ fn check_wasm_pack_latest_version() -> Result> { easy.useragent(&format!( "wasm-pack/{} ({})", - WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), + WASM_PACK_VERSION.unwrap_or("unknown"), WASM_PACK_REPO_URL ))?; @@ -234,7 +236,7 @@ fn check_wasm_pack_latest_version() -> Result> { let status_code = easy.response_code()?; - if 200 <= status_code && status_code < 300 { + if (200..300).contains(&status_code) { let contents = easy.get_ref(); let version_bytes = get_max_version(&contents.0) .context("max_version field not found when checking for newer wasm-pack version")?; @@ -425,8 +427,8 @@ impl CrateData { } fn is_same_path(path1: &Path, path2: &Path) -> bool { - if let Ok(path1) = fs::canonicalize(&path1) { - if let Ok(path2) = fs::canonicalize(&path2) { + if let Ok(path1) = fs::canonicalize(path1) { + if let Ok(path2) = fs::canonicalize(path2) { return path1 == path2; } } @@ -441,7 +443,7 @@ impl CrateData { /// Will return Err if the file (manifest_path) couldn't be read or /// if deserialize to `CargoManifest` fails. pub fn parse_crate_data(manifest_path: &Path) -> Result { - let manifest = fs::read_to_string(&manifest_path) + let manifest = fs::read_to_string(manifest_path) .with_context(|| anyhow!("failed to read: {}", manifest_path.display()))?; let manifest = &mut toml::Deserializer::new(&manifest); @@ -627,7 +629,7 @@ impl CrateData { None }; - let keywords = if pkg.keywords.len() > 0 { + let keywords = if !pkg.keywords.is_empty() { Some(pkg.keywords.clone()) } else { None @@ -655,7 +657,7 @@ impl CrateData { fn license(&self) -> Option { self.crate_license().clone().or_else(|| { - self.crate_license_file().clone().map(|file| { + self.crate_license_file().map(|file| { // When license is written in file: https://docs.npmjs.com/files/package.json#license format!("SEE LICENSE IN {}", file) }) @@ -674,7 +676,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::CommonJSPackage(CommonJSPackage { + NpmPackage::CommonJS(CommonJSPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -705,7 +707,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::ESModulesPackage(ESModulesPackage { + NpmPackage::ESModules(ESModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -737,7 +739,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::ESModulesPackage(ESModulesPackage { + NpmPackage::ESModules(ESModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -769,7 +771,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::NoModulesPackage(NoModulesPackage { + NpmPackage::NoModules(NoModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), diff --git a/src/manifest/npm/mod.rs b/src/manifest/npm/mod.rs index c8d65821..68dfe577 100644 --- a/src/manifest/npm/mod.rs +++ b/src/manifest/npm/mod.rs @@ -10,7 +10,7 @@ pub use self::nomodules::NoModulesPackage; #[derive(Serialize)] #[serde(untagged)] pub enum NpmPackage { - CommonJSPackage(CommonJSPackage), - ESModulesPackage(ESModulesPackage), - NoModulesPackage(NoModulesPackage), + CommonJS(CommonJSPackage), + ESModules(ESModulesPackage), + NoModules(NoModulesPackage), } diff --git a/src/readme.rs b/src/readme.rs index c98cdc0c..48665e81 100644 --- a/src/readme.rs +++ b/src/readme.rs @@ -13,14 +13,14 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path) -> Result<()> { "crate directory should exist" ); assert!( - fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()), + fs::metadata(out_dir).ok().map_or(false, |m| m.is_dir()), "crate's pkg directory should exist" ); let crate_readme_path = path.join("README.md"); let new_readme_path = out_dir.join("README.md"); if crate_readme_path.exists() { - fs::copy(&crate_readme_path, &new_readme_path).context("failed to copy README")?; + fs::copy(&crate_readme_path, new_readme_path).context("failed to copy README")?; } else { PBAR.warn("origin crate has no README"); } diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 9df8102b..35f26f86 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -55,16 +55,15 @@ pub fn find_wasm_opt(cache: &Cache, install_permitted: bool) -> Result return Ok(install::Status::Found(Download::at(path))), - None => {} + if let Some(path) = path.as_path().parent() { + return Ok(install::Status::Found(Download::at(path))); } } - Ok(install::download_prebuilt( + install::download_prebuilt( &install::Tool::WasmOpt, cache, "latest", install_permitted, - )?) + ) } From f74de4538c351bd2b2a15919f9abb209fc7ca8e4 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 9 Apr 2023 19:20:05 +0000 Subject: [PATCH 22/85] Optimize initialization --- src/installer.rs | 1 + src/lib.rs | 4 ++-- src/wasm_opt.rs | 7 +------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/installer.rs b/src/installer.rs index 1c97fb15..e12d114d 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -24,6 +24,7 @@ use std::process; use anyhow::{anyhow, bail, Context, Result}; +#[cold] pub fn install() -> ! { if let Err(e) = do_install() { eprintln!("{}", e); diff --git a/src/lib.rs b/src/lib.rs index f0cfac14..82203a1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,7 @@ fn run(cmd_args: impl Iterator) -> Result<()> { let wasm_pack_version = background_check_for_updates(); // Deprecate `init` - if let Some("init") = env::args().nth(1).as_deref() { + if Some(std::ffi::OsStr::new("init")) == env::args_os().nth(1).as_deref() { println!("wasm-pack init is deprecated, consider using wasm-pack build"); } @@ -165,7 +165,7 @@ fn setup_panic_hooks() { let default_hook = panic::take_hook(); - if env::var("RUST_BACKTRACE").is_err() { + if env::var_os("RUST_BACKTRACE").is_none() { panic::set_hook(Box::new(move |info: &panic::PanicInfo| { // First call the default hook that prints to standard error. default_hook(info); diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 35f26f86..848745b9 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -60,10 +60,5 @@ pub fn find_wasm_opt(cache: &Cache, install_permitted: bool) -> Result Date: Sun, 9 Apr 2023 19:49:29 +0000 Subject: [PATCH 23/85] Add Tool::name --- src/bindgen.rs | 2 +- src/generate.rs | 2 +- src/install/mod.rs | 8 ++++---- src/install/tool.rs | 16 +++++++++++----- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 3a7dad49..94a29ad2 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -53,7 +53,7 @@ pub fn wasm_bindgen_build( "--typescript" }; let bindgen_path = install::get_tool_path(install_status, Tool::WasmBindgen)? - .binary(&Tool::WasmBindgen.to_string())?; + .binary(Tool::WasmBindgen.name())?; let mut cmd = Command::new(&bindgen_path); cmd.arg(&wasm_path) diff --git a/src/generate.rs b/src/generate.rs index c58993e3..cabcb363 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -11,7 +11,7 @@ use std::process::Command; /// project from a template pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? - .binary(&Tool::CargoGenerate.to_string())?; + .binary(Tool::CargoGenerate.name())?; let mut cmd = Command::new(bin_path); cmd.arg("generate"); cmd.arg("--git").arg(template); diff --git a/src/install/mod.rs b/src/install/mod.rs index 571bec3d..9fc5a2cd 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -63,7 +63,7 @@ pub fn download_prebuilt_or_cargo_install( // // This situation can arise if the tool is already installed via // `cargo install`, for example. - if let Ok(path) = which(tool.to_string()) { + if let Ok(path) = which(tool.name()) { debug!("found global {} binary at: {}", tool, path.display()); if check_version(&tool, &path, version)? { let download = Download::at(path.parent().unwrap()); @@ -71,7 +71,7 @@ pub fn download_prebuilt_or_cargo_install( } } - let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool); + let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool.name()); PBAR.info(&msg); let dl = download_prebuilt(&tool, cache, version, install_permitted); @@ -248,8 +248,8 @@ pub fn cargo_install( fs::create_dir_all(&tmp).context(context)?; let crate_name = match tool { - Tool::WasmBindgen => "wasm-bindgen-cli".to_string(), - _ => tool.to_string(), + Tool::WasmBindgen => "wasm-bindgen-cli", + _ => tool.name(), }; let mut cmd = Command::new("cargo"); diff --git a/src/install/tool.rs b/src/install/tool.rs index 4a174ea3..21d2a5de 100644 --- a/src/install/tool.rs +++ b/src/install/tool.rs @@ -10,13 +10,19 @@ pub enum Tool { WasmOpt, } -impl fmt::Display for Tool { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = match self { +impl Tool { + /// Returns the binary's name + pub fn name(&self) -> &'static str { + match self { Tool::CargoGenerate => "cargo-generate", Tool::WasmBindgen => "wasm-bindgen", Tool::WasmOpt => "wasm-opt", - }; - write!(f, "{}", s) + } + } +} + +impl fmt::Display for Tool { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name()) } } From d3282409772a35e942ddee40b5e44a17b3d0ccb6 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 10 Apr 2023 03:47:46 +0000 Subject: [PATCH 24/85] Use Command::args --- src/bindgen.rs | 69 ++++++++++++++++++---------------- src/build/mod.rs | 71 ++++++++++++++++------------------- src/build/wasm_target.rs | 2 +- src/child.rs | 2 +- src/command/publish/access.rs | 24 +++++++----- src/generate.rs | 10 +++-- src/install/mod.rs | 26 ++++++++----- src/npm.rs | 53 +++++++++++++++----------- src/test/mod.rs | 21 ++++------- src/wasm_opt.rs | 7 +++- 10 files changed, 155 insertions(+), 130 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 94a29ad2..7808c762 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -55,41 +55,44 @@ pub fn wasm_bindgen_build( let bindgen_path = install::get_tool_path(install_status, Tool::WasmBindgen)? .binary(Tool::WasmBindgen.name())?; - let mut cmd = Command::new(&bindgen_path); - cmd.arg(&wasm_path) - .arg("--out-dir") - .arg(out_dir) - .arg(dts_arg); - - if weak_refs { - cmd.arg("--weak-refs"); - } - - if reference_types { - cmd.arg("--reference-types"); - } - let target_arg = build_target_arg(target, &bindgen_path)?; - if supports_dash_dash_target(&bindgen_path)? { - cmd.arg("--target").arg(target_arg); - } else { - cmd.arg(target_arg); - } - - if let Some(value) = out_name { - cmd.arg("--out-name").arg(value); - } - + //let out_name_args = out_name.map(|value| [OsStr::new("--out-name"), value.as_ref()]).into_iter().flatten(); let profile = data.configured_profile(profile); - if profile.wasm_bindgen_debug_js_glue() { - cmd.arg("--debug"); - } - if !profile.wasm_bindgen_demangle_name_section() { - cmd.arg("--no-demangle"); - } - if profile.wasm_bindgen_dwarf_debug_info() { - cmd.arg("--keep-debug"); - } + + let mut cmd = Command::new(&bindgen_path); + cmd.args( + std::iter::empty::<&OsStr>() + .chain([ + wasm_path.as_os_str(), + "--out-dir".as_ref(), + out_dir.as_os_str(), + dts_arg.as_ref(), + ]) + .chain(weak_refs.then_some("--weak-refs".as_ref())) + .chain(reference_types.then_some("--reference-types".as_ref())) + .chain(supports_dash_dash_target(&bindgen_path)?.then_some("--target".as_ref())) + .chain([target_arg.as_ref()]) + .chain( + out_name + .as_ref() + .map(|value| ["--out-name".as_ref(), value.as_ref()]) + .into_iter() + .flatten(), + ) + .chain( + profile + .wasm_bindgen_debug_js_glue() + .then_some("--debug".as_ref()), + ) + .chain( + (!profile.wasm_bindgen_demangle_name_section()).then_some("--no-demangle".as_ref()), + ) + .chain( + profile + .wasm_bindgen_dwarf_debug_info() + .then_some("--keep-debug".as_ref()), + ), + ); child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?; Ok(()) diff --git a/src/build/mod.rs b/src/build/mod.rs index ea82bc8c..ac91e0f8 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -6,6 +6,7 @@ use crate::emoji; use crate::manifest; use crate::PBAR; use anyhow::{anyhow, bail, Context, Result}; +use std::ffi::OsStr; use std::ffi::OsString; use std::path::Path; use std::process::Command; @@ -73,32 +74,29 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--lib"); - - if PBAR.quiet() { - cmd.arg("--quiet"); - } - - match profile { - BuildProfile::Profiling => { - // Once there are DWARF debug info consumers, force enable debug - // info, because builds that use the release cargo profile disables - // debug info. - // - // cmd.env("RUSTFLAGS", "-g"); - cmd.arg("--release"); - } - BuildProfile::Release => { - cmd.arg("--release"); - } - BuildProfile::Dev => { - // Plain cargo builds use the dev cargo profile, which includes - // debug info by default. - } - } - - cmd.arg("--target").arg("wasm32-unknown-unknown"); - cmd.args(extra_options); + cmd.current_dir(path).args( + std::iter::empty::<&OsStr>() + .chain(["build".as_ref(), "--lib".as_ref()]) + .chain(PBAR.quiet().then_some("--quiet".as_ref())) + .chain(match profile { + BuildProfile::Profiling => { + // Once there are DWARF debug info consumers, force enable debug + // info, because builds that use the release cargo profile disables + // debug info. + // + // cmd.env("RUSTFLAGS", "-g"); + Some("--release".as_ref()) + } + BuildProfile::Release => Some("--release".as_ref()), + BuildProfile::Dev => { + // Plain cargo builds use the dev cargo profile, which includes + // debug info by default. + None + } + }) + .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) + .chain(extra_options.iter().map(|s| s.as_ref())), + ); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } @@ -119,19 +117,14 @@ pub fn cargo_build_wasm( pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]) -> Result<()> { let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--tests"); - - if PBAR.quiet() { - cmd.arg("--quiet"); - } - - if !debug { - cmd.arg("--release"); - } - - cmd.arg("--target").arg("wasm32-unknown-unknown"); - - cmd.args(extra_options); + cmd.current_dir(path).args( + std::iter::empty::<&OsStr>() + .chain(["build".as_ref(), "--tests".as_ref()]) + .chain(PBAR.quiet().then_some("--quiet".as_ref())) + .chain((!debug).then_some("--release".as_ref())) + .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) + .chain(extra_options.iter().map(|s| s.as_ref())), + ); child::run(cmd, "cargo build").context("Compilation of your program failed")?; Ok(()) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index dccb3c87..652eec30 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -124,7 +124,7 @@ fn check_wasm32_target() -> Result> { /// Add wasm32-unknown-unknown using `rustup`. fn rustup_add_wasm_target() -> Result<()> { let mut cmd = Command::new("rustup"); - cmd.arg("target").arg("add").arg("wasm32-unknown-unknown"); + cmd.args(["target", "add", "wasm32-unknown-unknown"]); child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?; Ok(()) diff --git a/src/child.rs b/src/child.rs index 52249ac3..e5888d2a 100644 --- a/src/child.rs +++ b/src/child.rs @@ -17,7 +17,7 @@ pub fn new_command(program: &str) -> Command { if cfg!(windows) { let mut cmd = Command::new("cmd"); - cmd.arg("/c").arg(program); + cmd.args(["/c", program]); cmd } else { Command::new(program) diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index 6b374b4c..02c94a8d 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -11,25 +11,31 @@ pub enum Access { Restricted, } +impl Access { + /// Returns the mode's name + pub fn name(&self) -> &'static str { + match self { + Access::Public => "--access=public", + Access::Restricted => "--access=restricted", + } + } +} + impl FromStr for Access { type Err = Error; fn from_str(s: &str) -> Result { match s { - "public" => Ok(Access::Public), - "restricted" => Ok(Access::Restricted), - "private" => Ok(Access::Restricted), - _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), + "public" => Ok(Access::Public), + "restricted" => Ok(Access::Restricted), + "private" => Ok(Access::Restricted), + _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), } } } impl fmt::Display for Access { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let printable = match *self { - Access::Public => "--access=public", - Access::Restricted => "--access=restricted", - }; - write!(f, "{}", printable) + write!(f, "{}", self.name()) } } diff --git a/src/generate.rs b/src/generate.rs index cabcb363..0be06af2 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -13,9 +13,13 @@ pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(Tool::CargoGenerate.name())?; let mut cmd = Command::new(bin_path); - cmd.arg("generate"); - cmd.arg("--git").arg(template); - cmd.arg("--name").arg(name); + cmd.args([ + "generate".as_ref(), + "--git".as_ref(), + template, + "--name".as_ref(), + name, + ]); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/mod.rs b/src/install/mod.rs index 9fc5a2cd..2d24e639 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -10,6 +10,7 @@ use binary_install::{Cache, Download}; use log::debug; use log::{info, warn}; use std::env; +use std::ffi::OsStr; use std::fs; use std::path::Path; use std::process::Command; @@ -253,15 +254,22 @@ pub fn cargo_install( }; let mut cmd = Command::new("cargo"); - cmd.arg("install") - .arg("--force") - .arg(crate_name) - .arg("--root") - .arg(&tmp); - - if version != "latest" { - cmd.arg("--version").arg(version); - } + cmd.args( + std::iter::empty::<&OsStr>() + .chain([ + "install".as_ref(), + "--force".as_ref(), + crate_name.as_ref(), + "--root".as_ref(), + tmp.as_ref(), + ]) + .chain( + (version != "latest") + .then_some(["--version".as_ref(), version.as_ref()]) + .into_iter() + .flatten(), + ), + ); let context = format!("Installing {} with cargo", tool); child::run(cmd, "cargo install").context(context)?; diff --git a/src/npm.rs b/src/npm.rs index 76d3b931..d5578669 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -21,13 +21,18 @@ pub fn npm_pack(path: &str) -> Result<()> { /// Run the `npm publish` command. pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); - match access { - Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), - None => cmd.current_dir(path).arg("publish"), - }; - if let Some(tag) = tag { - cmd.arg("--tag").arg(tag); - }; + cmd.current_dir(path); + cmd.args( + std::iter::empty::<&OsStr>() + .chain(["publish".as_ref()]) + .chain(access.map(|a| a.name().as_ref())) + .chain( + tag.as_ref() + .map(|t| ["--tag".as_ref(), t.as_os_str()]) + .into_iter() + .flatten(), + ), + ); child::run(cmd, "npm publish").context("Publishing to npm failed")?; Ok(()) @@ -43,20 +48,26 @@ pub fn npm_login( // Interactively ask user for npm login info. // (child::run does not support interactive input) let mut cmd = child::new_command("npm"); - - cmd.arg("login").arg(build_arg("--registry=", registry)); - - if let Some(scope) = scope { - cmd.arg(build_arg("--scope=", scope)); - } - - if always_auth { - cmd.arg("--always_auth"); - } - - if let Some(auth_type) = auth_type { - cmd.arg(build_arg("--auth_type=", auth_type)); - } + cmd.args( + std::iter::empty::<&OsStr>() + .chain([ + "login".as_ref(), + build_arg("--registry=", registry).as_os_str(), + ]) + .chain( + scope + .as_deref() + .map(|scope| build_arg("--scope=", scope)) + .as_deref(), + ) + .chain(always_auth.then_some("--always-auth".as_ref())) + .chain( + auth_type + .as_deref() + .map(|auth_type| build_arg("--auth_type", auth_type)) + .as_deref(), + ), + ); info!("Running {:?}", cmd); if cmd.status()?.success() { diff --git a/src/test/mod.rs b/src/test/mod.rs index 1fbe920d..252148fc 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -25,19 +25,14 @@ where let mut cmd = Command::new("cargo"); cmd.envs(envs); - cmd.current_dir(path).arg("test"); - - if PBAR.quiet() { - cmd.arg("--quiet"); - } - - if release { - cmd.arg("--release"); - } - - cmd.arg("--target").arg("wasm32-unknown-unknown"); - - cmd.args(extra_options); + cmd.current_dir(path).args( + std::iter::empty::<&OsStr>() + .chain(["test".as_ref()]) + .chain(PBAR.quiet().then_some("--quiet".as_ref())) + .chain(release.then_some("--release".as_ref())) + .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) + .chain(extra_options.iter().map(|s| s.as_ref())), + ); child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?; diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 848745b9..e26651c2 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -5,6 +5,7 @@ use crate::install; use crate::PBAR; use anyhow::Result; use binary_install::{Cache, Download}; +use std::ffi::OsStr; use std::path::Path; use std::process::Command; @@ -35,7 +36,11 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo let tmp = path.with_extension("wasm-opt.wasm"); let mut cmd = Command::new(&wasm_opt_path); - cmd.arg(&path).arg("-o").arg(&tmp).args(args); + cmd.args( + std::iter::empty::<&OsStr>() + .chain([path.as_os_str(), "-o".as_ref(), tmp.as_os_str()]) + .chain(args.iter().map(|s| s.as_ref())), + ); child::run(cmd, "wasm-opt")?; std::fs::rename(&tmp, &path)?; } From 3a960121ea70389f6360c645a338ab57b4b746d8 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 10 Apr 2023 04:33:41 +0000 Subject: [PATCH 25/85] Make installation check 47% faster with multithreading --- src/command/build.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 4acc88b7..bba50d23 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -290,11 +290,7 @@ impl Build { match &mode { InstallMode::Force => &[], _ => { - steps![ - step_check_rustc_version, - step_check_crate_config, - step_check_for_wasm_target, - ] + steps![step_check_installation,] } }, steps![ @@ -313,7 +309,20 @@ impl Build { .copied() } - fn step_check_rustc_version(&mut self) -> Result<()> { + fn step_check_installation(&mut self) -> Result<()> { + std::thread::scope(|s| { + for handle in [ + s.spawn(|| self.step_check_rustc_version()), + s.spawn(|| self.step_check_crate_config()), + s.spawn(|| self.step_check_for_wasm_target()), + ] { + handle.join().unwrap()?; + } + Ok(()) + }) + } + + fn step_check_rustc_version(&self) -> Result<()> { info!("Checking rustc version..."); let version = build::check_rustc_version()?; let msg = format!("rustc version is {}.", version); @@ -321,14 +330,14 @@ impl Build { Ok(()) } - fn step_check_crate_config(&mut self) -> Result<()> { + fn step_check_crate_config(&self) -> Result<()> { info!("Checking crate configuration..."); self.crate_data.check_crate_config()?; info!("Crate is correctly configured."); Ok(()) } - fn step_check_for_wasm_target(&mut self) -> Result<()> { + fn step_check_for_wasm_target(&self) -> Result<()> { info!("Checking for wasm-target..."); build::wasm_target::check_for_wasm32_target()?; info!("Checking for wasm-target was successful."); From 1c7700a272588acf0c45c7c5f69c490d32d9185f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 10 Apr 2023 16:34:27 +0000 Subject: [PATCH 26/85] Optimize string conversion --- src/bindgen.rs | 11 +++++------ src/child.rs | 2 +- src/command/build.rs | 22 +++++++++++----------- src/command/mod.rs | 6 +++--- src/command/publish/access.rs | 34 ++++++++++++++++------------------ src/command/publish/mod.rs | 2 +- src/command/test.rs | 3 ++- src/install/arch.rs | 11 ++++------- src/install/krate.rs | 2 +- src/install/mod.rs | 35 +++++++++++++++++++++++------------ src/install/mode.rs | 9 ++++++--- src/install/os.rs | 11 ++++------- src/install/tool.rs | 8 -------- src/lib.rs | 3 ++- src/progressbar.rs | 25 ++++++++++++++++--------- tests/all/download.rs | 4 ++-- 16 files changed, 97 insertions(+), 91 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 7808c762..f609cd14 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -118,17 +118,17 @@ fn supports_dash_dash_target(cli_path: &Path) -> Result { Ok(cli_version >= expected_version) } -fn build_target_arg(target: Target, cli_path: &Path) -> Result { +fn build_target_arg(target: Target, cli_path: &Path) -> Result<&'static str> { if !supports_dash_dash_target(cli_path)? { Ok(build_target_arg_legacy(target, cli_path)?) } else { - Ok(target.to_string()) + Ok(target.name()) } } -fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result { +fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result<&'static str> { log::info!("Your version of wasm-bindgen is out of date. You should consider updating your Cargo.toml to a version >= 0.2.40."); - let target_arg = match target { + Ok(match target { Target::Nodejs => "--nodejs", Target::NoModules => "--no-modules", Target::Web => { @@ -140,6 +140,5 @@ fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result { } Target::Bundler => "--browser", Target::Deno => "--deno", - }; - Ok(target_arg.to_string()) + }) } diff --git a/src/child.rs b/src/child.rs index e5888d2a..78ecc6db 100644 --- a/src/child.rs +++ b/src/child.rs @@ -56,7 +56,7 @@ pub fn run_capture_stdout(mut command: Command, command_name: &Tool) -> Result fmt::Result { - let s = match self { +impl Target { + /// Returns the target's name + pub fn name(&self) -> &'static str { + match self { Target::Bundler => "bundler", Target::Web => "web", Target::Nodejs => "nodejs", Target::NoModules => "no-modules", Target::Deno => "deno", - }; - write!(f, "{}", s) + } } } -impl Target { - /// Converts from `OsStr` - pub fn parse(s: &OsStr) -> Result { +impl TryFrom<&OsStr> for Target { + type Error = OsString; + + fn try_from(s: &OsStr) -> Result { if s == "bundler" || s == "browser" { Ok(Target::Bundler) } else if s == "web" { @@ -127,7 +127,7 @@ pub struct BuildOptions { #[structopt(long = "scope", short = "s")] pub scope: Option, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, @@ -144,7 +144,7 @@ pub struct BuildOptions { /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = Target::parse))] + #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, diff --git a/src/command/mod.rs b/src/command/mod.rs index ffa7e1ba..dfce6792 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -19,7 +19,7 @@ use self::test::{Test, TestOptions}; use crate::install::InstallMode; use anyhow::Result; use log::info; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. @@ -51,7 +51,7 @@ pub enum Command { parse(from_os_str) )] template: OsString, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, @@ -69,7 +69,7 @@ pub enum Command { target: OsString, /// The access level for the package to be published - #[structopt(long = "access", short = "a")] + #[structopt(long = "access", short = "a", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] access: Option, /// The distribution tag being used for publishing. diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index 02c94a8d..e7d9465a 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -1,6 +1,5 @@ -use anyhow::{bail, Error, Result}; -use std::fmt; -use std::str::FromStr; +use anyhow::Result; +use std::ffi::{OsStr, OsString}; /// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`. #[derive(Debug)] @@ -21,21 +20,20 @@ impl Access { } } -impl FromStr for Access { - type Err = Error; +impl TryFrom<&OsStr> for Access { + type Error = OsString; - fn from_str(s: &str) -> Result { - match s { - "public" => Ok(Access::Public), - "restricted" => Ok(Access::Restricted), - "private" => Ok(Access::Restricted), - _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), - } - } -} - -impl fmt::Display for Access { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name()) + fn try_from(s: &OsStr) -> Result { + if s == "public" { + Ok(Access::Public) + } else if s == "restricted" { + Ok(Access::Restricted) + } else if s == "private" { + Ok(Access::Restricted) + } else { + let mut err = OsString::from(s); + err.push(" is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels."); + Err(err) + } } } diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 70bce2c7..026bef8f 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -46,7 +46,7 @@ pub fn publish( .default(0) .interact()? .to_string(); - let target = Target::parse(OsStr::new(&target)) + let target = Target::try_from(OsStr::new(&target)) .map_err(|err| Error::msg(err.to_string_lossy().into_owned()))?; let build_opts = BuildOptions { path: Some(crate_path.clone()), diff --git a/src/command/test.rs b/src/command/test.rs index efe2cf07..8863ab6b 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -11,6 +11,7 @@ use anyhow::{bail, Result}; use binary_install::Cache; use console::style; use log::info; +use std::ffi::OsStr; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; @@ -71,7 +72,7 @@ pub struct TestOptions { /// UI or windows. pub headless: bool, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, diff --git a/src/install/arch.rs b/src/install/arch.rs index b8c1f687..c66855bc 100644 --- a/src/install/arch.rs +++ b/src/install/arch.rs @@ -1,5 +1,4 @@ use anyhow::{bail, Result}; -use std::fmt; use crate::target; @@ -27,15 +26,13 @@ impl Arch { bail!("Unrecognized target!") } } -} -impl fmt::Display for Arch { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = match self { + /// Returns the architecture's name + pub fn name(&self) -> &'static str { + match self { Arch::X86_64 => "x86-64", Arch::X86 => "x86", Arch::AArch64 => "aarch64", - }; - write!(f, "{}", s) + } } } diff --git a/src/install/krate.rs b/src/install/krate.rs index d8ec163b..f72c0502 100644 --- a/src/install/krate.rs +++ b/src/install/krate.rs @@ -15,7 +15,7 @@ pub struct KrateResponse { impl Krate { pub fn new(name: &Tool) -> Result { - let krate_address = format!("https://crates.io/api/v1/crates/{}", name); + let krate_address = format!("https://crates.io/api/v1/crates/{}", name.name()); let client = reqwest::blocking::Client::new(); let res = client.get(krate_address).send()?; diff --git a/src/install/mod.rs b/src/install/mod.rs index 2d24e639..ccc2de5f 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -40,9 +40,9 @@ pub enum Status { pub fn get_tool_path(status: &Status, tool: Tool) -> Result<&Download> { match status { Status::Found(download) => Ok(download), - Status::CannotInstall => bail!("Not able to find or install a local {}.", tool), + Status::CannotInstall => bail!("Not able to find or install a local {}.", tool.name()), install::Status::PlatformNotSupported => { - bail!("{} does not currently support your platform.", tool) + bail!("{} does not currently support your platform.", tool.name()) } } } @@ -65,7 +65,7 @@ pub fn download_prebuilt_or_cargo_install( // This situation can arise if the tool is already installed via // `cargo install`, for example. if let Ok(path) = which(tool.name()) { - debug!("found global {} binary at: {}", tool, path.display()); + debug!("found global {} binary at: {}", tool.name(), path.display()); if check_version(&tool, &path, version)? { let download = Download::at(path.parent().unwrap()); return Ok(Status::Found(download)); @@ -81,7 +81,8 @@ pub fn download_prebuilt_or_cargo_install( Err(e) => { warn!( "could not download pre-built `{}`: {}. Falling back to `cargo install`.", - tool, e + tool.name(), + e ); } } @@ -101,7 +102,9 @@ pub fn check_version(tool: &Tool, path: &Path, expected_version: &str) -> Result let v = get_cli_version(tool, path)?; info!( "Checking installed `{}` version == expected version: {} == {}", - tool, v, &expected_version + tool.name(), + v, + &expected_version ); Ok(v == expected_version) } @@ -129,7 +132,7 @@ pub fn download_prebuilt( Ok(url) => url, Err(e) => bail!( "no prebuilt {} binaries are available for this platform: {}", - tool, + tool.name(), e, ), }; @@ -219,15 +222,16 @@ pub fn cargo_install( ) -> Result { debug!( "Attempting to use a `cargo install`ed version of `{}={}`", - tool, version, + tool.name(), + version, ); - let dirname = format!("{}-cargo-install-{}", tool, version); + let dirname = format!("{}-cargo-install-{}", tool.name(), version); let destination = cache.join(dirname.as_ref()); if destination.exists() { debug!( "`cargo install`ed `{}={}` already exists at {}", - tool, + tool.name(), version, destination.display() ); @@ -243,9 +247,16 @@ pub fn cargo_install( // and ensure we don't accidentally use stale files in the future let tmp = cache.join(format!(".{}", dirname).as_ref()); drop(fs::remove_dir_all(&tmp)); - debug!("cargo installing {} to tempdir: {}", tool, tmp.display(),); + debug!( + "cargo installing {} to tempdir: {}", + tool.name(), + tmp.display(), + ); - let context = format!("failed to create temp dir for `cargo install {}`", tool); + let context = format!( + "failed to create temp dir for `cargo install {}`", + tool.name() + ); fs::create_dir_all(&tmp).context(context)?; let crate_name = match tool { @@ -271,7 +282,7 @@ pub fn cargo_install( ), ); - let context = format!("Installing {} with cargo", tool); + let context = format!("Installing {} with cargo", tool.name()); child::run(cmd, "cargo install").context(context)?; // `cargo install` will put the installed binaries in `$root/bin/*`, but we diff --git a/src/install/mode.rs b/src/install/mode.rs index bfcb57a2..a5e59e80 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -14,9 +14,10 @@ pub enum InstallMode { Force, } -impl InstallMode { - /// Converts from `OsStr` - pub fn parse(s: &OsStr) -> Result { +impl TryFrom<&OsStr> for InstallMode { + type Error = OsString; + + fn try_from(s: &OsStr) -> Result { if s == "no-install" { Ok(InstallMode::Noinstall) } else if s == "normal" { @@ -29,7 +30,9 @@ impl InstallMode { Err(err) } } +} +impl InstallMode { /// Determines if installation is permitted during a function call based on --mode flag pub fn install_permitted(self) -> bool { match self { diff --git a/src/install/os.rs b/src/install/os.rs index b5ef6401..ad53f518 100644 --- a/src/install/os.rs +++ b/src/install/os.rs @@ -1,5 +1,4 @@ use anyhow::{bail, Result}; -use std::fmt; use crate::target; @@ -27,15 +26,13 @@ impl Os { bail!("Unrecognized target!") } } -} -impl fmt::Display for Os { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = match self { + /// Returns the OS name + pub fn name(&self) -> &'static str { + match self { Os::Linux => "linux", Os::MacOS => "macOS", Os::Windows => "windows", - }; - write!(f, "{}", s) + } } } diff --git a/src/install/tool.rs b/src/install/tool.rs index 21d2a5de..39a39bb0 100644 --- a/src/install/tool.rs +++ b/src/install/tool.rs @@ -1,5 +1,3 @@ -use std::fmt; - /// Represents the set of CLI tools wasm-pack uses pub enum Tool { /// cargo-generate CLI tool @@ -20,9 +18,3 @@ impl Tool { } } } - -impl fmt::Display for Tool { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name()) - } -} diff --git a/src/lib.rs b/src/lib.rs index 82203a1b..62cc2de3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,7 @@ use crate::progressbar::{LogLevel, ProgressOutput}; use crate::{build::WasmPackVersion, command::run_wasm_pack}; use anyhow::Result; use std::env; +use std::ffi::OsStr; use std::panic; use std::sync::mpsc; use std::thread; @@ -72,7 +73,7 @@ pub struct Cli { /// No output printed to stdout pub quiet: bool, - #[structopt(long = "log-level", default_value = "info")] + #[structopt(long = "log-level", default_value = "info", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } diff --git a/src/progressbar.rs b/src/progressbar.rs index 330b7f91..709d06ef 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -1,8 +1,9 @@ //! Fancy progress bar functionality. use crate::emoji; -use anyhow::{bail, Error, Result}; +use anyhow::Result; use console::style; +use std::ffi::{OsStr, OsString}; use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; #[repr(u8)] @@ -19,14 +20,20 @@ pub enum LogLevel { Info, } -impl std::str::FromStr for LogLevel { - type Err = Error; - fn from_str(s: &str) -> Result { - match s { - "error" => Ok(LogLevel::Error), - "warn" => Ok(LogLevel::Warn), - "info" => Ok(LogLevel::Info), - _ => bail!("Unknown log-level: {}", s), +impl TryFrom<&OsStr> for LogLevel { + type Error = OsString; + + fn try_from(s: &OsStr) -> Result>::Error> { + if s == "error" { + Ok(LogLevel::Error) + } else if s == "warn" { + Ok(LogLevel::Warn) + } else if s == "info" { + Ok(LogLevel::Info) + } else { + let mut err = OsString::from("Unknown log-level: "); + err.push(s); + Err(err) } } } diff --git a/tests/all/download.rs b/tests/all/download.rs index 62a79da5..b25b394d 100644 --- a/tests/all/download.rs +++ b/tests/all/download.rs @@ -91,8 +91,8 @@ fn all_latest_tool_download_urls_valid() { errors.push(format!( "Can't download URL {} for {} on {}: {}", url, - arch, - os, + arch.name(), + os.name(), res.status() )); } From 8fe50176e19ded1a95497af1286c2217cd827dc6 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 16 Apr 2023 17:30:57 +0000 Subject: [PATCH 27/85] Optimize handling of unused cargo.toml fields --- src/main.rs | 2 +- src/manifest/mod.rs | 101 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index f88b3e33..35634300 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ static ALLOC: dhat::Alloc = dhat::Alloc; fn main() { #[cfg(feature = "perf")] - let _profiler = dhat::Profiler::new_heap(); + let _profiler = dhat::Profiler::builder().trim_backtraces(None).build(); wasm_pack::main(std::env::args_os()) } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 887defce..c4042243 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -26,7 +26,6 @@ use serde_json; use std::collections::BTreeSet; use std::env; use std::io::Write; -use strsim::levenshtein; use toml; const WASM_PACK_METADATA_KEY: &str = "package.metadata.wasm-pack"; @@ -45,6 +44,9 @@ pub struct CrateData { #[derive(Deserialize)] pub struct CargoManifest { package: CargoPackage, + #[allow(dead_code)] + #[serde(flatten)] + unused_keys: UnusedKeys, } #[derive(Deserialize)] @@ -53,12 +55,61 @@ struct CargoPackage { #[serde(default)] metadata: CargoMetadata, + #[allow(dead_code)] + #[serde(flatten)] + unused_keys: UnusedKeys, } #[derive(Default, Deserialize)] struct CargoMetadata { #[serde(default, rename = "wasm-pack")] wasm_pack: CargoWasmPack, + /// Keys that are similar to "wasm-pack" + #[serde(flatten, deserialize_with = "deserialize_typos")] + typos: BTreeSet, +} + +fn deserialize_typos<'de, D: serde::Deserializer<'de>>( + deserializer: D, +) -> Result, D::Error> { + struct Visitor; + + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = BTreeSet; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("struct") + } + + fn visit_map(self, mut map: A) -> Result + where + A: serde::de::MapAccess<'de>, + { + let mut result = BTreeSet::new(); + while let Some(key) = map.next_key::<&str>()? { + if typo([key, "wasm-pack"]) { + result.insert(key.to_owned()); + } + } + Ok(result) + } + } + + deserializer.deserialize_map(Visitor) +} + +/// Like `IgnoredAny`, but doesn't trigger the callback given to `serde_ignored::deserialize` because it doesn't call `Deserializer::deserialize_ignored_any`. +struct UnusedKeys; + +impl<'de> Deserialize<'de> for UnusedKeys { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + deserializer + .deserialize_map(serde::de::IgnoredAny) + .map(|_| UnusedKeys) + } } #[derive(Default, Deserialize)] @@ -448,20 +499,16 @@ impl CrateData { let manifest = &mut toml::Deserializer::new(&manifest); let mut unused_keys = BTreeSet::new(); - let levenshtein_threshold = 1; - let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { + let mut manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { let path_string = path.to_string(); - - if path_string.starts_with("package.metadata") - && (path_string.contains("wasm-pack") - || levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold) - { - unused_keys.insert(path_string); - } + debug_assert!(path_string.starts_with(WASM_PACK_METADATA_KEY)); + unused_keys.insert(path_string); }) .with_context(|| anyhow!("failed to parse manifest: {}", manifest_path.display()))?; + unused_keys.append(&mut manifest.package.metadata.typos); + Ok(ManifestAndUnsedKeys { manifest, unused_keys, @@ -810,3 +857,37 @@ impl CrateData { }; } } + +/// Returns `true` if the levenshtein distance between both strings is 1 +fn typo(strs: [&str; 2]) -> bool { + let [iter0, iter1] = strs.map(|s| s.chars()); + let [len0, len1] = strs.map(|s| s.chars().count()); + let (different_len, mut long, mut short) = if len0 == len1 { + (false, iter0, iter1) + } else if len0 == len1 + 1 { + (true, iter0, iter1) + } else if len1 == len0 + 1 { + (true, iter1, iter0) + } else { + return false; + }; + while let (Some(a), b) = (long.next(), short.next()) { + if Some(a) != b { + if different_len { + let _ = long.next(); + } + // If remaining characters don't match, then distance is more than 1 + return long.eq(short); + } + } + // Distance is 0 + false +} + +#[test] +fn test_typo() { + for s in [".ab", "a.b", "ab.", "a", "b", ".b", "a."] { + assert!(typo(["ab", dbg!(s)])); + } + assert!(!typo(["ab", "ab"])) +} From 45497712aefe6065c6b85e236f731551bdc3a600 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 16 Apr 2023 17:36:46 +0000 Subject: [PATCH 28/85] Clippy --- src/command/publish/access.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index e7d9465a..d3b93d76 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -26,9 +26,7 @@ impl TryFrom<&OsStr> for Access { fn try_from(s: &OsStr) -> Result { if s == "public" { Ok(Access::Public) - } else if s == "restricted" { - Ok(Access::Restricted) - } else if s == "private" { + } else if s == "restricted" || s == "private" { Ok(Access::Restricted) } else { let mut err = OsString::from(s); From c9bce177f29253106e540abc518eb93a2bd418cf Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 16 Apr 2023 18:03:08 +0000 Subject: [PATCH 29/85] Return Cow from find_pkg_directory --- src/command/publish/mod.rs | 3 ++- src/command/utils.rs | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 026bef8f..5372ce51 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -9,6 +9,7 @@ use crate::PBAR; use anyhow::{anyhow, bail, Error, Result}; use dialoguer::{Confirm, Input, Select}; use log::info; +use std::borrow::Cow; use std::ffi::{OsStr, OsString}; use std::path::PathBuf; @@ -56,7 +57,7 @@ pub fn publish( }; Build::try_from_opts(build_opts) .and_then(|mut build| build.run()) - .map(|()| crate_path.join(out_dir)) + .map(|()| Cow::Owned(crate_path.join(out_dir))) .map_err(|_| { anyhow!( "Unable to find the pkg directory at path '{:#?}',\ diff --git a/src/command/utils.rs b/src/command/utils.rs index a1ea0eb8..ec25069b 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -2,6 +2,7 @@ #![allow(clippy::redundant_closure)] use anyhow::Result; +use std::borrow::Cow; use std::fs; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -45,14 +46,14 @@ pub fn create_pkg_dir(out_dir: &Path) -> Result<()> { /// Locates the pkg directory from a specific path /// Returns None if unable to find the 'pkg' directory -pub fn find_pkg_directory(path: &Path) -> Option { +pub fn find_pkg_directory(path: &Path) -> Option> { if is_pkg_directory(path) { - return Some(path.to_owned()); + return Some(Cow::Borrowed(path)); } WalkDir::new(path) .into_iter() - .filter_map(|x| x.ok().map(|e| e.into_path())) + .filter_map(|x| x.ok().map(|e| Cow::Owned(e.into_path()))) .find(|x| is_pkg_directory(x)) } From 1fe302cbd74c629ab5576c9ec6207a4752998aa5 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:52:44 +0000 Subject: [PATCH 30/85] Revert "Return Cow from find_pkg_directory" This reverts commit c9bce177f29253106e540abc518eb93a2bd418cf. --- src/command/publish/mod.rs | 3 +-- src/command/utils.rs | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 5372ce51..026bef8f 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -9,7 +9,6 @@ use crate::PBAR; use anyhow::{anyhow, bail, Error, Result}; use dialoguer::{Confirm, Input, Select}; use log::info; -use std::borrow::Cow; use std::ffi::{OsStr, OsString}; use std::path::PathBuf; @@ -57,7 +56,7 @@ pub fn publish( }; Build::try_from_opts(build_opts) .and_then(|mut build| build.run()) - .map(|()| Cow::Owned(crate_path.join(out_dir))) + .map(|()| crate_path.join(out_dir)) .map_err(|_| { anyhow!( "Unable to find the pkg directory at path '{:#?}',\ diff --git a/src/command/utils.rs b/src/command/utils.rs index ec25069b..a1ea0eb8 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -2,7 +2,6 @@ #![allow(clippy::redundant_closure)] use anyhow::Result; -use std::borrow::Cow; use std::fs; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -46,14 +45,14 @@ pub fn create_pkg_dir(out_dir: &Path) -> Result<()> { /// Locates the pkg directory from a specific path /// Returns None if unable to find the 'pkg' directory -pub fn find_pkg_directory(path: &Path) -> Option> { +pub fn find_pkg_directory(path: &Path) -> Option { if is_pkg_directory(path) { - return Some(Cow::Borrowed(path)); + return Some(path.to_owned()); } WalkDir::new(path) .into_iter() - .filter_map(|x| x.ok().map(|e| Cow::Owned(e.into_path()))) + .filter_map(|x| x.ok().map(|e| e.into_path())) .find(|x| is_pkg_directory(x)) } From 31cb1f0417d3776283d7b8ddbffc59b0ee5c1004 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:06 +0000 Subject: [PATCH 31/85] Revert "Clippy" This reverts commit 45497712aefe6065c6b85e236f731551bdc3a600. --- src/command/publish/access.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index d3b93d76..e7d9465a 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -26,7 +26,9 @@ impl TryFrom<&OsStr> for Access { fn try_from(s: &OsStr) -> Result { if s == "public" { Ok(Access::Public) - } else if s == "restricted" || s == "private" { + } else if s == "restricted" { + Ok(Access::Restricted) + } else if s == "private" { Ok(Access::Restricted) } else { let mut err = OsString::from(s); From d7d3840fad3dcba8b39f03ef46390300e4e72139 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:11 +0000 Subject: [PATCH 32/85] Revert "Optimize handling of unused cargo.toml fields" This reverts commit 8fe50176e19ded1a95497af1286c2217cd827dc6. --- src/main.rs | 2 +- src/manifest/mod.rs | 101 +++++--------------------------------------- 2 files changed, 11 insertions(+), 92 deletions(-) diff --git a/src/main.rs b/src/main.rs index 35634300..f88b3e33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ static ALLOC: dhat::Alloc = dhat::Alloc; fn main() { #[cfg(feature = "perf")] - let _profiler = dhat::Profiler::builder().trim_backtraces(None).build(); + let _profiler = dhat::Profiler::new_heap(); wasm_pack::main(std::env::args_os()) } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index c4042243..887defce 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -26,6 +26,7 @@ use serde_json; use std::collections::BTreeSet; use std::env; use std::io::Write; +use strsim::levenshtein; use toml; const WASM_PACK_METADATA_KEY: &str = "package.metadata.wasm-pack"; @@ -44,9 +45,6 @@ pub struct CrateData { #[derive(Deserialize)] pub struct CargoManifest { package: CargoPackage, - #[allow(dead_code)] - #[serde(flatten)] - unused_keys: UnusedKeys, } #[derive(Deserialize)] @@ -55,61 +53,12 @@ struct CargoPackage { #[serde(default)] metadata: CargoMetadata, - #[allow(dead_code)] - #[serde(flatten)] - unused_keys: UnusedKeys, } #[derive(Default, Deserialize)] struct CargoMetadata { #[serde(default, rename = "wasm-pack")] wasm_pack: CargoWasmPack, - /// Keys that are similar to "wasm-pack" - #[serde(flatten, deserialize_with = "deserialize_typos")] - typos: BTreeSet, -} - -fn deserialize_typos<'de, D: serde::Deserializer<'de>>( - deserializer: D, -) -> Result, D::Error> { - struct Visitor; - - impl<'de> serde::de::Visitor<'de> for Visitor { - type Value = BTreeSet; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("struct") - } - - fn visit_map(self, mut map: A) -> Result - where - A: serde::de::MapAccess<'de>, - { - let mut result = BTreeSet::new(); - while let Some(key) = map.next_key::<&str>()? { - if typo([key, "wasm-pack"]) { - result.insert(key.to_owned()); - } - } - Ok(result) - } - } - - deserializer.deserialize_map(Visitor) -} - -/// Like `IgnoredAny`, but doesn't trigger the callback given to `serde_ignored::deserialize` because it doesn't call `Deserializer::deserialize_ignored_any`. -struct UnusedKeys; - -impl<'de> Deserialize<'de> for UnusedKeys { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - deserializer - .deserialize_map(serde::de::IgnoredAny) - .map(|_| UnusedKeys) - } } #[derive(Default, Deserialize)] @@ -499,16 +448,20 @@ impl CrateData { let manifest = &mut toml::Deserializer::new(&manifest); let mut unused_keys = BTreeSet::new(); + let levenshtein_threshold = 1; - let mut manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { + let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { let path_string = path.to_string(); - debug_assert!(path_string.starts_with(WASM_PACK_METADATA_KEY)); - unused_keys.insert(path_string); + + if path_string.starts_with("package.metadata") + && (path_string.contains("wasm-pack") + || levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold) + { + unused_keys.insert(path_string); + } }) .with_context(|| anyhow!("failed to parse manifest: {}", manifest_path.display()))?; - unused_keys.append(&mut manifest.package.metadata.typos); - Ok(ManifestAndUnsedKeys { manifest, unused_keys, @@ -857,37 +810,3 @@ impl CrateData { }; } } - -/// Returns `true` if the levenshtein distance between both strings is 1 -fn typo(strs: [&str; 2]) -> bool { - let [iter0, iter1] = strs.map(|s| s.chars()); - let [len0, len1] = strs.map(|s| s.chars().count()); - let (different_len, mut long, mut short) = if len0 == len1 { - (false, iter0, iter1) - } else if len0 == len1 + 1 { - (true, iter0, iter1) - } else if len1 == len0 + 1 { - (true, iter1, iter0) - } else { - return false; - }; - while let (Some(a), b) = (long.next(), short.next()) { - if Some(a) != b { - if different_len { - let _ = long.next(); - } - // If remaining characters don't match, then distance is more than 1 - return long.eq(short); - } - } - // Distance is 0 - false -} - -#[test] -fn test_typo() { - for s in [".ab", "a.b", "ab.", "a", "b", ".b", "a."] { - assert!(typo(["ab", dbg!(s)])); - } - assert!(!typo(["ab", "ab"])) -} From 34eebb2bd4ad68221ee67fcad900f1493b77c536 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:13 +0000 Subject: [PATCH 33/85] Revert "Optimize string conversion" This reverts commit 1c7700a272588acf0c45c7c5f69c490d32d9185f. --- src/bindgen.rs | 11 ++++++----- src/child.rs | 2 +- src/command/build.rs | 22 +++++++++++----------- src/command/mod.rs | 6 +++--- src/command/publish/access.rs | 34 ++++++++++++++++++---------------- src/command/publish/mod.rs | 2 +- src/command/test.rs | 3 +-- src/install/arch.rs | 11 +++++++---- src/install/krate.rs | 2 +- src/install/mod.rs | 35 ++++++++++++----------------------- src/install/mode.rs | 9 +++------ src/install/os.rs | 11 +++++++---- src/install/tool.rs | 8 ++++++++ src/lib.rs | 3 +-- src/progressbar.rs | 25 +++++++++---------------- tests/all/download.rs | 4 ++-- 16 files changed, 91 insertions(+), 97 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index f609cd14..7808c762 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -118,17 +118,17 @@ fn supports_dash_dash_target(cli_path: &Path) -> Result { Ok(cli_version >= expected_version) } -fn build_target_arg(target: Target, cli_path: &Path) -> Result<&'static str> { +fn build_target_arg(target: Target, cli_path: &Path) -> Result { if !supports_dash_dash_target(cli_path)? { Ok(build_target_arg_legacy(target, cli_path)?) } else { - Ok(target.name()) + Ok(target.to_string()) } } -fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result<&'static str> { +fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result { log::info!("Your version of wasm-bindgen is out of date. You should consider updating your Cargo.toml to a version >= 0.2.40."); - Ok(match target { + let target_arg = match target { Target::Nodejs => "--nodejs", Target::NoModules => "--no-modules", Target::Web => { @@ -140,5 +140,6 @@ fn build_target_arg_legacy(target: Target, cli_path: &Path) -> Result<&'static s } Target::Bundler => "--browser", Target::Deno => "--deno", - }) + }; + Ok(target_arg.to_string()) } diff --git a/src/child.rs b/src/child.rs index 78ecc6db..e5888d2a 100644 --- a/src/child.rs +++ b/src/child.rs @@ -56,7 +56,7 @@ pub fn run_capture_stdout(mut command: Command, command_name: &Tool) -> Result &'static str { - match self { +impl fmt::Display for Target { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match self { Target::Bundler => "bundler", Target::Web => "web", Target::Nodejs => "nodejs", Target::NoModules => "no-modules", Target::Deno => "deno", - } + }; + write!(f, "{}", s) } } -impl TryFrom<&OsStr> for Target { - type Error = OsString; - - fn try_from(s: &OsStr) -> Result { +impl Target { + /// Converts from `OsStr` + pub fn parse(s: &OsStr) -> Result { if s == "bundler" || s == "browser" { Ok(Target::Bundler) } else if s == "web" { @@ -127,7 +127,7 @@ pub struct BuildOptions { #[structopt(long = "scope", short = "s")] pub scope: Option, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, @@ -144,7 +144,7 @@ pub struct BuildOptions { /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = Target::parse))] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, diff --git a/src/command/mod.rs b/src/command/mod.rs index dfce6792..ffa7e1ba 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -19,7 +19,7 @@ use self::test::{Test, TestOptions}; use crate::install::InstallMode; use anyhow::Result; use log::info; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsString; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. @@ -51,7 +51,7 @@ pub enum Command { parse(from_os_str) )] template: OsString, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, @@ -69,7 +69,7 @@ pub enum Command { target: OsString, /// The access level for the package to be published - #[structopt(long = "access", short = "a", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "access", short = "a")] access: Option, /// The distribution tag being used for publishing. diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index e7d9465a..02c94a8d 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -1,5 +1,6 @@ -use anyhow::Result; -use std::ffi::{OsStr, OsString}; +use anyhow::{bail, Error, Result}; +use std::fmt; +use std::str::FromStr; /// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`. #[derive(Debug)] @@ -20,20 +21,21 @@ impl Access { } } -impl TryFrom<&OsStr> for Access { - type Error = OsString; +impl FromStr for Access { + type Err = Error; - fn try_from(s: &OsStr) -> Result { - if s == "public" { - Ok(Access::Public) - } else if s == "restricted" { - Ok(Access::Restricted) - } else if s == "private" { - Ok(Access::Restricted) - } else { - let mut err = OsString::from(s); - err.push(" is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels."); - Err(err) - } + fn from_str(s: &str) -> Result { + match s { + "public" => Ok(Access::Public), + "restricted" => Ok(Access::Restricted), + "private" => Ok(Access::Restricted), + _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), + } + } +} + +impl fmt::Display for Access { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name()) } } diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 026bef8f..70bce2c7 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -46,7 +46,7 @@ pub fn publish( .default(0) .interact()? .to_string(); - let target = Target::try_from(OsStr::new(&target)) + let target = Target::parse(OsStr::new(&target)) .map_err(|err| Error::msg(err.to_string_lossy().into_owned()))?; let build_opts = BuildOptions { path: Some(crate_path.clone()), diff --git a/src/command/test.rs b/src/command/test.rs index 8863ab6b..efe2cf07 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -11,7 +11,6 @@ use anyhow::{bail, Result}; use binary_install::Cache; use console::style; use log::info; -use std::ffi::OsStr; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; @@ -72,7 +71,7 @@ pub struct TestOptions { /// UI or windows. pub headless: bool, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, diff --git a/src/install/arch.rs b/src/install/arch.rs index c66855bc..b8c1f687 100644 --- a/src/install/arch.rs +++ b/src/install/arch.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Result}; +use std::fmt; use crate::target; @@ -26,13 +27,15 @@ impl Arch { bail!("Unrecognized target!") } } +} - /// Returns the architecture's name - pub fn name(&self) -> &'static str { - match self { +impl fmt::Display for Arch { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match self { Arch::X86_64 => "x86-64", Arch::X86 => "x86", Arch::AArch64 => "aarch64", - } + }; + write!(f, "{}", s) } } diff --git a/src/install/krate.rs b/src/install/krate.rs index f72c0502..d8ec163b 100644 --- a/src/install/krate.rs +++ b/src/install/krate.rs @@ -15,7 +15,7 @@ pub struct KrateResponse { impl Krate { pub fn new(name: &Tool) -> Result { - let krate_address = format!("https://crates.io/api/v1/crates/{}", name.name()); + let krate_address = format!("https://crates.io/api/v1/crates/{}", name); let client = reqwest::blocking::Client::new(); let res = client.get(krate_address).send()?; diff --git a/src/install/mod.rs b/src/install/mod.rs index ccc2de5f..2d24e639 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -40,9 +40,9 @@ pub enum Status { pub fn get_tool_path(status: &Status, tool: Tool) -> Result<&Download> { match status { Status::Found(download) => Ok(download), - Status::CannotInstall => bail!("Not able to find or install a local {}.", tool.name()), + Status::CannotInstall => bail!("Not able to find or install a local {}.", tool), install::Status::PlatformNotSupported => { - bail!("{} does not currently support your platform.", tool.name()) + bail!("{} does not currently support your platform.", tool) } } } @@ -65,7 +65,7 @@ pub fn download_prebuilt_or_cargo_install( // This situation can arise if the tool is already installed via // `cargo install`, for example. if let Ok(path) = which(tool.name()) { - debug!("found global {} binary at: {}", tool.name(), path.display()); + debug!("found global {} binary at: {}", tool, path.display()); if check_version(&tool, &path, version)? { let download = Download::at(path.parent().unwrap()); return Ok(Status::Found(download)); @@ -81,8 +81,7 @@ pub fn download_prebuilt_or_cargo_install( Err(e) => { warn!( "could not download pre-built `{}`: {}. Falling back to `cargo install`.", - tool.name(), - e + tool, e ); } } @@ -102,9 +101,7 @@ pub fn check_version(tool: &Tool, path: &Path, expected_version: &str) -> Result let v = get_cli_version(tool, path)?; info!( "Checking installed `{}` version == expected version: {} == {}", - tool.name(), - v, - &expected_version + tool, v, &expected_version ); Ok(v == expected_version) } @@ -132,7 +129,7 @@ pub fn download_prebuilt( Ok(url) => url, Err(e) => bail!( "no prebuilt {} binaries are available for this platform: {}", - tool.name(), + tool, e, ), }; @@ -222,16 +219,15 @@ pub fn cargo_install( ) -> Result { debug!( "Attempting to use a `cargo install`ed version of `{}={}`", - tool.name(), - version, + tool, version, ); - let dirname = format!("{}-cargo-install-{}", tool.name(), version); + let dirname = format!("{}-cargo-install-{}", tool, version); let destination = cache.join(dirname.as_ref()); if destination.exists() { debug!( "`cargo install`ed `{}={}` already exists at {}", - tool.name(), + tool, version, destination.display() ); @@ -247,16 +243,9 @@ pub fn cargo_install( // and ensure we don't accidentally use stale files in the future let tmp = cache.join(format!(".{}", dirname).as_ref()); drop(fs::remove_dir_all(&tmp)); - debug!( - "cargo installing {} to tempdir: {}", - tool.name(), - tmp.display(), - ); + debug!("cargo installing {} to tempdir: {}", tool, tmp.display(),); - let context = format!( - "failed to create temp dir for `cargo install {}`", - tool.name() - ); + let context = format!("failed to create temp dir for `cargo install {}`", tool); fs::create_dir_all(&tmp).context(context)?; let crate_name = match tool { @@ -282,7 +271,7 @@ pub fn cargo_install( ), ); - let context = format!("Installing {} with cargo", tool.name()); + let context = format!("Installing {} with cargo", tool); child::run(cmd, "cargo install").context(context)?; // `cargo install` will put the installed binaries in `$root/bin/*`, but we diff --git a/src/install/mode.rs b/src/install/mode.rs index a5e59e80..bfcb57a2 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -14,10 +14,9 @@ pub enum InstallMode { Force, } -impl TryFrom<&OsStr> for InstallMode { - type Error = OsString; - - fn try_from(s: &OsStr) -> Result { +impl InstallMode { + /// Converts from `OsStr` + pub fn parse(s: &OsStr) -> Result { if s == "no-install" { Ok(InstallMode::Noinstall) } else if s == "normal" { @@ -30,9 +29,7 @@ impl TryFrom<&OsStr> for InstallMode { Err(err) } } -} -impl InstallMode { /// Determines if installation is permitted during a function call based on --mode flag pub fn install_permitted(self) -> bool { match self { diff --git a/src/install/os.rs b/src/install/os.rs index ad53f518..b5ef6401 100644 --- a/src/install/os.rs +++ b/src/install/os.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Result}; +use std::fmt; use crate::target; @@ -26,13 +27,15 @@ impl Os { bail!("Unrecognized target!") } } +} - /// Returns the OS name - pub fn name(&self) -> &'static str { - match self { +impl fmt::Display for Os { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match self { Os::Linux => "linux", Os::MacOS => "macOS", Os::Windows => "windows", - } + }; + write!(f, "{}", s) } } diff --git a/src/install/tool.rs b/src/install/tool.rs index 39a39bb0..21d2a5de 100644 --- a/src/install/tool.rs +++ b/src/install/tool.rs @@ -1,3 +1,5 @@ +use std::fmt; + /// Represents the set of CLI tools wasm-pack uses pub enum Tool { /// cargo-generate CLI tool @@ -18,3 +20,9 @@ impl Tool { } } } + +impl fmt::Display for Tool { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name()) + } +} diff --git a/src/lib.rs b/src/lib.rs index 62cc2de3..82203a1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,6 @@ use crate::progressbar::{LogLevel, ProgressOutput}; use crate::{build::WasmPackVersion, command::run_wasm_pack}; use anyhow::Result; use std::env; -use std::ffi::OsStr; use std::panic; use std::sync::mpsc; use std::thread; @@ -73,7 +72,7 @@ pub struct Cli { /// No output printed to stdout pub quiet: bool, - #[structopt(long = "log-level", default_value = "info", parse(try_from_os_str = TryFrom::<&OsStr>::try_from))] + #[structopt(long = "log-level", default_value = "info")] /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } diff --git a/src/progressbar.rs b/src/progressbar.rs index 709d06ef..330b7f91 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -1,9 +1,8 @@ //! Fancy progress bar functionality. use crate::emoji; -use anyhow::Result; +use anyhow::{bail, Error, Result}; use console::style; -use std::ffi::{OsStr, OsString}; use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; #[repr(u8)] @@ -20,20 +19,14 @@ pub enum LogLevel { Info, } -impl TryFrom<&OsStr> for LogLevel { - type Error = OsString; - - fn try_from(s: &OsStr) -> Result>::Error> { - if s == "error" { - Ok(LogLevel::Error) - } else if s == "warn" { - Ok(LogLevel::Warn) - } else if s == "info" { - Ok(LogLevel::Info) - } else { - let mut err = OsString::from("Unknown log-level: "); - err.push(s); - Err(err) +impl std::str::FromStr for LogLevel { + type Err = Error; + fn from_str(s: &str) -> Result { + match s { + "error" => Ok(LogLevel::Error), + "warn" => Ok(LogLevel::Warn), + "info" => Ok(LogLevel::Info), + _ => bail!("Unknown log-level: {}", s), } } } diff --git a/tests/all/download.rs b/tests/all/download.rs index b25b394d..62a79da5 100644 --- a/tests/all/download.rs +++ b/tests/all/download.rs @@ -91,8 +91,8 @@ fn all_latest_tool_download_urls_valid() { errors.push(format!( "Can't download URL {} for {} on {}: {}", url, - arch.name(), - os.name(), + arch, + os, res.status() )); } From 220f20a15f388df519a039143a2db2521f198e3a Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:17 +0000 Subject: [PATCH 34/85] Revert "Make installation check 47% faster with multithreading" This reverts commit 3a960121ea70389f6360c645a338ab57b4b746d8. --- src/command/build.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index bba50d23..4acc88b7 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -290,7 +290,11 @@ impl Build { match &mode { InstallMode::Force => &[], _ => { - steps![step_check_installation,] + steps![ + step_check_rustc_version, + step_check_crate_config, + step_check_for_wasm_target, + ] } }, steps![ @@ -309,20 +313,7 @@ impl Build { .copied() } - fn step_check_installation(&mut self) -> Result<()> { - std::thread::scope(|s| { - for handle in [ - s.spawn(|| self.step_check_rustc_version()), - s.spawn(|| self.step_check_crate_config()), - s.spawn(|| self.step_check_for_wasm_target()), - ] { - handle.join().unwrap()?; - } - Ok(()) - }) - } - - fn step_check_rustc_version(&self) -> Result<()> { + fn step_check_rustc_version(&mut self) -> Result<()> { info!("Checking rustc version..."); let version = build::check_rustc_version()?; let msg = format!("rustc version is {}.", version); @@ -330,14 +321,14 @@ impl Build { Ok(()) } - fn step_check_crate_config(&self) -> Result<()> { + fn step_check_crate_config(&mut self) -> Result<()> { info!("Checking crate configuration..."); self.crate_data.check_crate_config()?; info!("Crate is correctly configured."); Ok(()) } - fn step_check_for_wasm_target(&self) -> Result<()> { + fn step_check_for_wasm_target(&mut self) -> Result<()> { info!("Checking for wasm-target..."); build::wasm_target::check_for_wasm32_target()?; info!("Checking for wasm-target was successful."); From dbefd7cb6c69ddc6518c885c8a58899184e2c44b Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:19 +0000 Subject: [PATCH 35/85] Revert "Use Command::args" This reverts commit d3282409772a35e942ddee40b5e44a17b3d0ccb6. --- src/bindgen.rs | 69 ++++++++++++++++------------------ src/build/mod.rs | 71 +++++++++++++++++++---------------- src/build/wasm_target.rs | 2 +- src/child.rs | 2 +- src/command/publish/access.rs | 24 +++++------- src/generate.rs | 10 ++--- src/install/mod.rs | 26 +++++-------- src/npm.rs | 53 +++++++++++--------------- src/test/mod.rs | 21 +++++++---- src/wasm_opt.rs | 7 +--- 10 files changed, 130 insertions(+), 155 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 7808c762..94a29ad2 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -55,44 +55,41 @@ pub fn wasm_bindgen_build( let bindgen_path = install::get_tool_path(install_status, Tool::WasmBindgen)? .binary(Tool::WasmBindgen.name())?; + let mut cmd = Command::new(&bindgen_path); + cmd.arg(&wasm_path) + .arg("--out-dir") + .arg(out_dir) + .arg(dts_arg); + + if weak_refs { + cmd.arg("--weak-refs"); + } + + if reference_types { + cmd.arg("--reference-types"); + } + let target_arg = build_target_arg(target, &bindgen_path)?; - //let out_name_args = out_name.map(|value| [OsStr::new("--out-name"), value.as_ref()]).into_iter().flatten(); - let profile = data.configured_profile(profile); + if supports_dash_dash_target(&bindgen_path)? { + cmd.arg("--target").arg(target_arg); + } else { + cmd.arg(target_arg); + } - let mut cmd = Command::new(&bindgen_path); - cmd.args( - std::iter::empty::<&OsStr>() - .chain([ - wasm_path.as_os_str(), - "--out-dir".as_ref(), - out_dir.as_os_str(), - dts_arg.as_ref(), - ]) - .chain(weak_refs.then_some("--weak-refs".as_ref())) - .chain(reference_types.then_some("--reference-types".as_ref())) - .chain(supports_dash_dash_target(&bindgen_path)?.then_some("--target".as_ref())) - .chain([target_arg.as_ref()]) - .chain( - out_name - .as_ref() - .map(|value| ["--out-name".as_ref(), value.as_ref()]) - .into_iter() - .flatten(), - ) - .chain( - profile - .wasm_bindgen_debug_js_glue() - .then_some("--debug".as_ref()), - ) - .chain( - (!profile.wasm_bindgen_demangle_name_section()).then_some("--no-demangle".as_ref()), - ) - .chain( - profile - .wasm_bindgen_dwarf_debug_info() - .then_some("--keep-debug".as_ref()), - ), - ); + if let Some(value) = out_name { + cmd.arg("--out-name").arg(value); + } + + let profile = data.configured_profile(profile); + if profile.wasm_bindgen_debug_js_glue() { + cmd.arg("--debug"); + } + if !profile.wasm_bindgen_demangle_name_section() { + cmd.arg("--no-demangle"); + } + if profile.wasm_bindgen_dwarf_debug_info() { + cmd.arg("--keep-debug"); + } child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?; Ok(()) diff --git a/src/build/mod.rs b/src/build/mod.rs index ac91e0f8..ea82bc8c 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -6,7 +6,6 @@ use crate::emoji; use crate::manifest; use crate::PBAR; use anyhow::{anyhow, bail, Context, Result}; -use std::ffi::OsStr; use std::ffi::OsString; use std::path::Path; use std::process::Command; @@ -74,29 +73,32 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path).args( - std::iter::empty::<&OsStr>() - .chain(["build".as_ref(), "--lib".as_ref()]) - .chain(PBAR.quiet().then_some("--quiet".as_ref())) - .chain(match profile { - BuildProfile::Profiling => { - // Once there are DWARF debug info consumers, force enable debug - // info, because builds that use the release cargo profile disables - // debug info. - // - // cmd.env("RUSTFLAGS", "-g"); - Some("--release".as_ref()) - } - BuildProfile::Release => Some("--release".as_ref()), - BuildProfile::Dev => { - // Plain cargo builds use the dev cargo profile, which includes - // debug info by default. - None - } - }) - .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) - .chain(extra_options.iter().map(|s| s.as_ref())), - ); + cmd.current_dir(path).arg("build").arg("--lib"); + + if PBAR.quiet() { + cmd.arg("--quiet"); + } + + match profile { + BuildProfile::Profiling => { + // Once there are DWARF debug info consumers, force enable debug + // info, because builds that use the release cargo profile disables + // debug info. + // + // cmd.env("RUSTFLAGS", "-g"); + cmd.arg("--release"); + } + BuildProfile::Release => { + cmd.arg("--release"); + } + BuildProfile::Dev => { + // Plain cargo builds use the dev cargo profile, which includes + // debug info by default. + } + } + + cmd.arg("--target").arg("wasm32-unknown-unknown"); + cmd.args(extra_options); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } @@ -117,14 +119,19 @@ pub fn cargo_build_wasm( pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]) -> Result<()> { let mut cmd = Command::new("cargo"); - cmd.current_dir(path).args( - std::iter::empty::<&OsStr>() - .chain(["build".as_ref(), "--tests".as_ref()]) - .chain(PBAR.quiet().then_some("--quiet".as_ref())) - .chain((!debug).then_some("--release".as_ref())) - .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) - .chain(extra_options.iter().map(|s| s.as_ref())), - ); + cmd.current_dir(path).arg("build").arg("--tests"); + + if PBAR.quiet() { + cmd.arg("--quiet"); + } + + if !debug { + cmd.arg("--release"); + } + + cmd.arg("--target").arg("wasm32-unknown-unknown"); + + cmd.args(extra_options); child::run(cmd, "cargo build").context("Compilation of your program failed")?; Ok(()) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 652eec30..dccb3c87 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -124,7 +124,7 @@ fn check_wasm32_target() -> Result> { /// Add wasm32-unknown-unknown using `rustup`. fn rustup_add_wasm_target() -> Result<()> { let mut cmd = Command::new("rustup"); - cmd.args(["target", "add", "wasm32-unknown-unknown"]); + cmd.arg("target").arg("add").arg("wasm32-unknown-unknown"); child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?; Ok(()) diff --git a/src/child.rs b/src/child.rs index e5888d2a..52249ac3 100644 --- a/src/child.rs +++ b/src/child.rs @@ -17,7 +17,7 @@ pub fn new_command(program: &str) -> Command { if cfg!(windows) { let mut cmd = Command::new("cmd"); - cmd.args(["/c", program]); + cmd.arg("/c").arg(program); cmd } else { Command::new(program) diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index 02c94a8d..6b374b4c 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -11,31 +11,25 @@ pub enum Access { Restricted, } -impl Access { - /// Returns the mode's name - pub fn name(&self) -> &'static str { - match self { - Access::Public => "--access=public", - Access::Restricted => "--access=restricted", - } - } -} - impl FromStr for Access { type Err = Error; fn from_str(s: &str) -> Result { match s { - "public" => Ok(Access::Public), - "restricted" => Ok(Access::Restricted), - "private" => Ok(Access::Restricted), - _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), + "public" => Ok(Access::Public), + "restricted" => Ok(Access::Restricted), + "private" => Ok(Access::Restricted), + _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s), } } } impl fmt::Display for Access { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name()) + let printable = match *self { + Access::Public => "--access=public", + Access::Restricted => "--access=restricted", + }; + write!(f, "{}", printable) } } diff --git a/src/generate.rs b/src/generate.rs index 0be06af2..cabcb363 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -13,13 +13,9 @@ pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(Tool::CargoGenerate.name())?; let mut cmd = Command::new(bin_path); - cmd.args([ - "generate".as_ref(), - "--git".as_ref(), - template, - "--name".as_ref(), - name, - ]); + cmd.arg("generate"); + cmd.arg("--git").arg(template); + cmd.arg("--name").arg(name); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/mod.rs b/src/install/mod.rs index 2d24e639..9fc5a2cd 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -10,7 +10,6 @@ use binary_install::{Cache, Download}; use log::debug; use log::{info, warn}; use std::env; -use std::ffi::OsStr; use std::fs; use std::path::Path; use std::process::Command; @@ -254,22 +253,15 @@ pub fn cargo_install( }; let mut cmd = Command::new("cargo"); - cmd.args( - std::iter::empty::<&OsStr>() - .chain([ - "install".as_ref(), - "--force".as_ref(), - crate_name.as_ref(), - "--root".as_ref(), - tmp.as_ref(), - ]) - .chain( - (version != "latest") - .then_some(["--version".as_ref(), version.as_ref()]) - .into_iter() - .flatten(), - ), - ); + cmd.arg("install") + .arg("--force") + .arg(crate_name) + .arg("--root") + .arg(&tmp); + + if version != "latest" { + cmd.arg("--version").arg(version); + } let context = format!("Installing {} with cargo", tool); child::run(cmd, "cargo install").context(context)?; diff --git a/src/npm.rs b/src/npm.rs index d5578669..76d3b931 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -21,18 +21,13 @@ pub fn npm_pack(path: &str) -> Result<()> { /// Run the `npm publish` command. pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); - cmd.current_dir(path); - cmd.args( - std::iter::empty::<&OsStr>() - .chain(["publish".as_ref()]) - .chain(access.map(|a| a.name().as_ref())) - .chain( - tag.as_ref() - .map(|t| ["--tag".as_ref(), t.as_os_str()]) - .into_iter() - .flatten(), - ), - ); + match access { + Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), + None => cmd.current_dir(path).arg("publish"), + }; + if let Some(tag) = tag { + cmd.arg("--tag").arg(tag); + }; child::run(cmd, "npm publish").context("Publishing to npm failed")?; Ok(()) @@ -48,26 +43,20 @@ pub fn npm_login( // Interactively ask user for npm login info. // (child::run does not support interactive input) let mut cmd = child::new_command("npm"); - cmd.args( - std::iter::empty::<&OsStr>() - .chain([ - "login".as_ref(), - build_arg("--registry=", registry).as_os_str(), - ]) - .chain( - scope - .as_deref() - .map(|scope| build_arg("--scope=", scope)) - .as_deref(), - ) - .chain(always_auth.then_some("--always-auth".as_ref())) - .chain( - auth_type - .as_deref() - .map(|auth_type| build_arg("--auth_type", auth_type)) - .as_deref(), - ), - ); + + cmd.arg("login").arg(build_arg("--registry=", registry)); + + if let Some(scope) = scope { + cmd.arg(build_arg("--scope=", scope)); + } + + if always_auth { + cmd.arg("--always_auth"); + } + + if let Some(auth_type) = auth_type { + cmd.arg(build_arg("--auth_type=", auth_type)); + } info!("Running {:?}", cmd); if cmd.status()?.success() { diff --git a/src/test/mod.rs b/src/test/mod.rs index 252148fc..1fbe920d 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -25,14 +25,19 @@ where let mut cmd = Command::new("cargo"); cmd.envs(envs); - cmd.current_dir(path).args( - std::iter::empty::<&OsStr>() - .chain(["test".as_ref()]) - .chain(PBAR.quiet().then_some("--quiet".as_ref())) - .chain(release.then_some("--release".as_ref())) - .chain(["--target".as_ref(), "wasm32-unknown-unknown".as_ref()]) - .chain(extra_options.iter().map(|s| s.as_ref())), - ); + cmd.current_dir(path).arg("test"); + + if PBAR.quiet() { + cmd.arg("--quiet"); + } + + if release { + cmd.arg("--release"); + } + + cmd.arg("--target").arg("wasm32-unknown-unknown"); + + cmd.args(extra_options); child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?; diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index e26651c2..848745b9 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -5,7 +5,6 @@ use crate::install; use crate::PBAR; use anyhow::Result; use binary_install::{Cache, Download}; -use std::ffi::OsStr; use std::path::Path; use std::process::Command; @@ -36,11 +35,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo let tmp = path.with_extension("wasm-opt.wasm"); let mut cmd = Command::new(&wasm_opt_path); - cmd.args( - std::iter::empty::<&OsStr>() - .chain([path.as_os_str(), "-o".as_ref(), tmp.as_os_str()]) - .chain(args.iter().map(|s| s.as_ref())), - ); + cmd.arg(&path).arg("-o").arg(&tmp).args(args); child::run(cmd, "wasm-opt")?; std::fs::rename(&tmp, &path)?; } From 7b568daf36641890a467445ae6d4ce588cd1c3a1 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:21 +0000 Subject: [PATCH 36/85] Revert "Add Tool::name" This reverts commit afc9ed21e4e075bb9ee1301a8d87b3ea83286153. --- src/bindgen.rs | 2 +- src/generate.rs | 2 +- src/install/mod.rs | 8 ++++---- src/install/tool.rs | 16 +++++----------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 94a29ad2..3a7dad49 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -53,7 +53,7 @@ pub fn wasm_bindgen_build( "--typescript" }; let bindgen_path = install::get_tool_path(install_status, Tool::WasmBindgen)? - .binary(Tool::WasmBindgen.name())?; + .binary(&Tool::WasmBindgen.to_string())?; let mut cmd = Command::new(&bindgen_path); cmd.arg(&wasm_path) diff --git a/src/generate.rs b/src/generate.rs index cabcb363..c58993e3 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -11,7 +11,7 @@ use std::process::Command; /// project from a template pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? - .binary(Tool::CargoGenerate.name())?; + .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(bin_path); cmd.arg("generate"); cmd.arg("--git").arg(template); diff --git a/src/install/mod.rs b/src/install/mod.rs index 9fc5a2cd..571bec3d 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -63,7 +63,7 @@ pub fn download_prebuilt_or_cargo_install( // // This situation can arise if the tool is already installed via // `cargo install`, for example. - if let Ok(path) = which(tool.name()) { + if let Ok(path) = which(tool.to_string()) { debug!("found global {} binary at: {}", tool, path.display()); if check_version(&tool, &path, version)? { let download = Download::at(path.parent().unwrap()); @@ -71,7 +71,7 @@ pub fn download_prebuilt_or_cargo_install( } } - let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool.name()); + let msg = format!("{}Installing {}...", emoji::DOWN_ARROW, tool); PBAR.info(&msg); let dl = download_prebuilt(&tool, cache, version, install_permitted); @@ -248,8 +248,8 @@ pub fn cargo_install( fs::create_dir_all(&tmp).context(context)?; let crate_name = match tool { - Tool::WasmBindgen => "wasm-bindgen-cli", - _ => tool.name(), + Tool::WasmBindgen => "wasm-bindgen-cli".to_string(), + _ => tool.to_string(), }; let mut cmd = Command::new("cargo"); diff --git a/src/install/tool.rs b/src/install/tool.rs index 21d2a5de..4a174ea3 100644 --- a/src/install/tool.rs +++ b/src/install/tool.rs @@ -10,19 +10,13 @@ pub enum Tool { WasmOpt, } -impl Tool { - /// Returns the binary's name - pub fn name(&self) -> &'static str { - match self { +impl fmt::Display for Tool { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = match self { Tool::CargoGenerate => "cargo-generate", Tool::WasmBindgen => "wasm-bindgen", Tool::WasmOpt => "wasm-opt", - } - } -} - -impl fmt::Display for Tool { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.name()) + }; + write!(f, "{}", s) } } From a89c6e8e7569c4e996df40a9892bc108f9ae7cdc Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:24 +0000 Subject: [PATCH 37/85] Revert "Optimize initialization" This reverts commit f74de4538c351bd2b2a15919f9abb209fc7ca8e4. --- src/installer.rs | 1 - src/lib.rs | 4 ++-- src/wasm_opt.rs | 7 ++++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/installer.rs b/src/installer.rs index e12d114d..1c97fb15 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -24,7 +24,6 @@ use std::process; use anyhow::{anyhow, bail, Context, Result}; -#[cold] pub fn install() -> ! { if let Err(e) = do_install() { eprintln!("{}", e); diff --git a/src/lib.rs b/src/lib.rs index 82203a1b..f0cfac14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,7 @@ fn run(cmd_args: impl Iterator) -> Result<()> { let wasm_pack_version = background_check_for_updates(); // Deprecate `init` - if Some(std::ffi::OsStr::new("init")) == env::args_os().nth(1).as_deref() { + if let Some("init") = env::args().nth(1).as_deref() { println!("wasm-pack init is deprecated, consider using wasm-pack build"); } @@ -165,7 +165,7 @@ fn setup_panic_hooks() { let default_hook = panic::take_hook(); - if env::var_os("RUST_BACKTRACE").is_none() { + if env::var("RUST_BACKTRACE").is_err() { panic::set_hook(Box::new(move |info: &panic::PanicInfo| { // First call the default hook that prints to standard error. default_hook(info); diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 848745b9..35f26f86 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -60,5 +60,10 @@ pub fn find_wasm_opt(cache: &Cache, install_permitted: bool) -> Result Date: Fri, 2 Jun 2023 13:53:26 +0000 Subject: [PATCH 38/85] Revert "Clippy" This reverts commit 1b6f23fc645df8df9161cde4bf564484722ad889. --- src/bindgen.rs | 2 +- src/build/mod.rs | 2 +- src/build/wasm_target.rs | 2 +- src/command/build.rs | 9 +++++++-- src/command/login.rs | 2 +- src/command/test.rs | 2 +- src/command/utils.rs | 4 ++-- src/generate.rs | 6 +++--- src/install/krate.rs | 2 +- src/install/mod.rs | 2 +- src/install/mode.rs | 9 +++++++-- src/installer.rs | 4 +++- src/lib.rs | 6 +++--- src/license.rs | 4 ++-- src/manifest/mod.rs | 32 +++++++++++++++----------------- src/manifest/npm/mod.rs | 6 +++--- src/readme.rs | 4 ++-- src/wasm_opt.rs | 9 +++++---- 18 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 3a7dad49..9c2cc599 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -22,7 +22,7 @@ pub fn wasm_bindgen_build( reference_types: bool, target: Target, profile: BuildProfile, - extra_options: &[OsString], + extra_options: &Vec, ) -> Result<()> { let release_or_debug = match profile { BuildProfile::Release | BuildProfile::Profiling => "release", diff --git a/src/build/mod.rs b/src/build/mod.rs index ea82bc8c..7d7c33f1 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -53,7 +53,7 @@ fn try_check_rustc_version() -> Option> { /// Checks and returns local and latest versions of wasm-pack pub fn check_wasm_pack_versions() -> Result { match wasm_pack_local_version() { - Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or(vec![])}), + Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or_else(|| Vec::new())}), None => bail!("We can't figure out what your wasm-pack version is, make sure the installation path is correct.") } } diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index dccb3c87..7f4da59b 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -67,7 +67,7 @@ pub fn check_for_wasm32_target() -> Result<()> { /// Get rustc's sysroot as a PathBuf fn get_rustc_sysroot() -> Result { let command = Command::new("rustc") - .args(["--print", "sysroot"]) + .args(&["--print", "sysroot"]) .output()?; if command.status.success() { diff --git a/src/command/build.rs b/src/command/build.rs index 4acc88b7..bdab0fef 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -42,11 +42,10 @@ pub struct Build { /// What sort of output we're going to be generating and flags we're invoking /// `wasm-bindgen` with. -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] pub enum Target { /// Default output mode or `--target bundler`, indicates output will be /// used with a bundle in a later step. - #[default] Bundler, /// Correspond to `--target web` where the output is natively usable as an /// ES module in a browser and the wasm is manually instantiated. @@ -63,6 +62,12 @@ pub enum Target { Deno, } +impl Default for Target { + fn default() -> Target { + Target::Bundler + } +} + impl fmt::Display for Target { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = match self { diff --git a/src/command/login.rs b/src/command/login.rs index 63f67841..9794a6c4 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -22,7 +22,7 @@ pub fn login( &auth_type ); info!("npm info located in the npm debug log"); - npm::npm_login(®istry, scope, always_auth, auth_type)?; + npm::npm_login(®istry, &scope, always_auth, &auth_type)?; info!("Logged you in!"); PBAR.info("👋 logged you in!"); diff --git a/src/command/test.rs b/src/command/test.rs index efe2cf07..a80603ee 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -302,7 +302,7 @@ impl Test { let status = install::download_prebuilt_or_cargo_install( Tool::WasmBindgen, &self.cache, - bindgen_version, + &bindgen_version, self.mode.install_permitted(), )?; diff --git a/src/command/utils.rs b/src/command/utils.rs index a1ea0eb8..70d76bf7 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -38,7 +38,7 @@ fn find_manifest_from_cwd() -> Result { /// Construct our `pkg` directory in the crate. pub fn create_pkg_dir(out_dir: &Path) -> Result<()> { let _ = fs::remove_file(out_dir.join("package.json")); // Clean up package.json from previous runs - fs::create_dir_all(out_dir)?; + fs::create_dir_all(&out_dir)?; fs::write(out_dir.join(".gitignore"), "*")?; Ok(()) } @@ -53,7 +53,7 @@ pub fn find_pkg_directory(path: &Path) -> Option { WalkDir::new(path) .into_iter() .filter_map(|x| x.ok().map(|e| e.into_path())) - .find(|x| is_pkg_directory(x)) + .find(|x| is_pkg_directory(&x)) } fn is_pkg_directory(path: &Path) -> bool { diff --git a/src/generate.rs b/src/generate.rs index c58993e3..5ea920bd 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,10 +12,10 @@ use std::process::Command; pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; - let mut cmd = Command::new(bin_path); + let mut cmd = Command::new(&bin_path); cmd.arg("generate"); - cmd.arg("--git").arg(template); - cmd.arg("--name").arg(name); + cmd.arg("--git").arg(&template); + cmd.arg("--name").arg(&name); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/krate.rs b/src/install/krate.rs index d8ec163b..4ac2facf 100644 --- a/src/install/krate.rs +++ b/src/install/krate.rs @@ -17,7 +17,7 @@ impl Krate { pub fn new(name: &Tool) -> Result { let krate_address = format!("https://crates.io/api/v1/crates/{}", name); let client = reqwest::blocking::Client::new(); - let res = client.get(krate_address).send()?; + let res = client.get(&krate_address).send()?; let kr: KrateResponse = serde_json::from_str(&res.text()?)?; Ok(kr.krate) diff --git a/src/install/mod.rs b/src/install/mod.rs index 571bec3d..c4361407 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -110,7 +110,7 @@ pub fn get_cli_version(tool: &Tool, path: &Path) -> Result { let mut cmd = Command::new(path); cmd.arg("--version"); let stdout = child::run_capture_stdout(cmd, tool)?; - let version = stdout.split_whitespace().nth(1); + let version = stdout.trim().split_whitespace().nth(1); match version { Some(v) => Ok(v.to_string()), None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.") diff --git a/src/install/mode.rs b/src/install/mode.rs index bfcb57a2..b017d9a3 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -2,10 +2,9 @@ use std::ffi::{OsStr, OsString}; /// The `InstallMode` determines which mode of initialization we are running, and /// what install steps we perform. -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] pub enum InstallMode { /// Perform all the install steps. - #[default] Normal, /// Don't install tools like `wasm-bindgen`, just use the global /// environment's existing versions to do builds. @@ -14,6 +13,12 @@ pub enum InstallMode { Force, } +impl Default for InstallMode { + fn default() -> InstallMode { + InstallMode::Normal + } +} + impl InstallMode { /// Converts from `OsStr` pub fn parse(s: &OsStr) -> Result { diff --git a/src/installer.rs b/src/installer.rs index 1c97fb15..67f2b6b0 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -23,6 +23,8 @@ use std::path::Path; use std::process; use anyhow::{anyhow, bail, Context, Result}; +use atty; +use which; pub fn install() -> ! { if let Err(e) = do_install() { @@ -71,7 +73,7 @@ fn do_install() -> Result<()> { // Our relatively simple install step! let me = env::current_exe()?; - fs::copy(me, &destination) + fs::copy(&me, &destination) .with_context(|| anyhow!("failed to copy executable to `{}`", destination.display()))?; println!( "info: successfully installed wasm-pack to `{}`", diff --git a/src/lib.rs b/src/lib.rs index f0cfac14..c9e51054 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,7 @@ fn run(cmd_args: impl Iterator) -> Result<()> { let wasm_pack_version = background_check_for_updates(); // Deprecate `init` - if let Some("init") = env::args().nth(1).as_deref() { + if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { println!("wasm-pack init is deprecated, consider using wasm-pack build"); } @@ -159,13 +159,13 @@ fn setup_panic_hooks() { let meta = human_panic::Metadata { version: env!("CARGO_PKG_VERSION").into(), name: env!("CARGO_PKG_NAME").into(), - authors: env!("CARGO_PKG_AUTHORS").replace(':', ", ").into(), + authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), homepage: env!("CARGO_PKG_HOMEPAGE").into(), }; let default_hook = panic::take_hook(); - if env::var("RUST_BACKTRACE").is_err() { + if let Err(_) = env::var("RUST_BACKTRACE") { panic::set_hook(Box::new(move |info: &panic::PanicInfo| { // First call the default hook that prints to standard error. default_hook(info); diff --git a/src/license.rs b/src/license.rs index a6636457..b1c4d44f 100644 --- a/src/license.rs +++ b/src/license.rs @@ -49,7 +49,7 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R ); assert!( - fs::metadata(out_dir).ok().map_or(false, |m| m.is_dir()), + fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()), "crate's pkg directory should exist" ); @@ -79,7 +79,7 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R (None, Some(license_file)) => { let crate_license_path = path.join(&license_file); let new_license_path = out_dir.join(&license_file); - if fs::copy(crate_license_path, new_license_path).is_err() { + if fs::copy(&crate_license_path, &new_license_path).is_err() { PBAR.info("origin crate has no LICENSE"); } } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 887defce..4561689e 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -136,7 +136,7 @@ pub fn return_wasm_pack_latest_version() -> Result>> { match old_metadata_file { Some(ref file_contents) => { - let last_updated = return_stamp_file_value(file_contents, b"created") + let last_updated = return_stamp_file_value(&file_contents, b"created") .and_then(|t| DateTime::parse_from_str(&String::from_utf8_lossy(t), "%+").ok()); last_updated @@ -144,10 +144,8 @@ pub fn return_wasm_pack_latest_version() -> Result>> { if current_time.signed_duration_since(last_updated).num_hours() > 24 { return_api_call_result(current_time).map(Some) } else { - Ok( - return_stamp_file_value(file_contents, b"version") - .map(|f| f.to_owned()), - ) + Ok(return_stamp_file_value(&file_contents, b"version") + .map(|f| f.to_owned())) } }) .unwrap_or_else(|| Ok(None)) @@ -164,7 +162,7 @@ fn return_api_call_result(current_time: DateTime) -> Result override_stamp_file(current_time, Some(version)).ok(), + Ok(ref version) => override_stamp_file(current_time, Some(&version)).ok(), Err(_) => override_stamp_file(current_time, None).ok(), }; @@ -226,7 +224,7 @@ fn check_wasm_pack_latest_version() -> Result> { easy.useragent(&format!( "wasm-pack/{} ({})", - WASM_PACK_VERSION.unwrap_or("unknown"), + WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), WASM_PACK_REPO_URL ))?; @@ -236,7 +234,7 @@ fn check_wasm_pack_latest_version() -> Result> { let status_code = easy.response_code()?; - if (200..300).contains(&status_code) { + if 200 <= status_code && status_code < 300 { let contents = easy.get_ref(); let version_bytes = get_max_version(&contents.0) .context("max_version field not found when checking for newer wasm-pack version")?; @@ -427,8 +425,8 @@ impl CrateData { } fn is_same_path(path1: &Path, path2: &Path) -> bool { - if let Ok(path1) = fs::canonicalize(path1) { - if let Ok(path2) = fs::canonicalize(path2) { + if let Ok(path1) = fs::canonicalize(&path1) { + if let Ok(path2) = fs::canonicalize(&path2) { return path1 == path2; } } @@ -443,7 +441,7 @@ impl CrateData { /// Will return Err if the file (manifest_path) couldn't be read or /// if deserialize to `CargoManifest` fails. pub fn parse_crate_data(manifest_path: &Path) -> Result { - let manifest = fs::read_to_string(manifest_path) + let manifest = fs::read_to_string(&manifest_path) .with_context(|| anyhow!("failed to read: {}", manifest_path.display()))?; let manifest = &mut toml::Deserializer::new(&manifest); @@ -629,7 +627,7 @@ impl CrateData { None }; - let keywords = if !pkg.keywords.is_empty() { + let keywords = if pkg.keywords.len() > 0 { Some(pkg.keywords.clone()) } else { None @@ -657,7 +655,7 @@ impl CrateData { fn license(&self) -> Option { self.crate_license().clone().or_else(|| { - self.crate_license_file().map(|file| { + self.crate_license_file().clone().map(|file| { // When license is written in file: https://docs.npmjs.com/files/package.json#license format!("SEE LICENSE IN {}", file) }) @@ -676,7 +674,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::CommonJS(CommonJSPackage { + NpmPackage::CommonJSPackage(CommonJSPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -707,7 +705,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::ESModules(ESModulesPackage { + NpmPackage::ESModulesPackage(ESModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -739,7 +737,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::ESModules(ESModulesPackage { + NpmPackage::ESModulesPackage(ESModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), @@ -771,7 +769,7 @@ impl CrateData { self.check_optional_fields(); - NpmPackage::NoModules(NoModulesPackage { + NpmPackage::NoModulesPackage(NoModulesPackage { name: data.name, collaborators: pkg.authors.clone(), description: self.pkg().description.clone(), diff --git a/src/manifest/npm/mod.rs b/src/manifest/npm/mod.rs index 68dfe577..c8d65821 100644 --- a/src/manifest/npm/mod.rs +++ b/src/manifest/npm/mod.rs @@ -10,7 +10,7 @@ pub use self::nomodules::NoModulesPackage; #[derive(Serialize)] #[serde(untagged)] pub enum NpmPackage { - CommonJS(CommonJSPackage), - ESModules(ESModulesPackage), - NoModules(NoModulesPackage), + CommonJSPackage(CommonJSPackage), + ESModulesPackage(ESModulesPackage), + NoModulesPackage(NoModulesPackage), } diff --git a/src/readme.rs b/src/readme.rs index 48665e81..c98cdc0c 100644 --- a/src/readme.rs +++ b/src/readme.rs @@ -13,14 +13,14 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path) -> Result<()> { "crate directory should exist" ); assert!( - fs::metadata(out_dir).ok().map_or(false, |m| m.is_dir()), + fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()), "crate's pkg directory should exist" ); let crate_readme_path = path.join("README.md"); let new_readme_path = out_dir.join("README.md"); if crate_readme_path.exists() { - fs::copy(&crate_readme_path, new_readme_path).context("failed to copy README")?; + fs::copy(&crate_readme_path, &new_readme_path).context("failed to copy README")?; } else { PBAR.warn("origin crate has no README"); } diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 35f26f86..9df8102b 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -55,15 +55,16 @@ pub fn find_wasm_opt(cache: &Cache, install_permitted: bool) -> Result return Ok(install::Status::Found(Download::at(path))), + None => {} } } - install::download_prebuilt( + Ok(install::download_prebuilt( &install::Tool::WasmOpt, cache, "latest", install_permitted, - ) + )?) } From a58356affe38ac6127bb3cf9ada8c541919f650f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:28 +0000 Subject: [PATCH 39/85] Revert "Stuff" This reverts commit c6f1b56e0b62c961a4b1c4d10edf7843f86dad75. --- .gitignore | 2 +- benches/bench.rs | 23 +- benches/lockfile.txt | 1446 -------------------------------------- src/bindgen.rs | 9 +- src/build/wasm_target.rs | 14 +- 5 files changed, 22 insertions(+), 1472 deletions(-) delete mode 100644 benches/lockfile.txt diff --git a/.gitignore b/.gitignore index b7eb8db9..cd34a72c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ tests/bin /build-installer docs/book docs/installer -dhat-*.json +dhat-heap.json diff --git a/benches/bench.rs b/benches/bench.rs index d42e76b0..88cd6570 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -9,27 +9,22 @@ fn run_wasm_pack() { let fixture = fixture::dual_license(); std::env::set_current_dir(&fixture.path).unwrap(); std::env::set_var("WASM_PACK_CACHE", fixture.cache_dir()); - - wasm_pack::main( - ["wasm-pack", "build", "--mode", "force"] - .into_iter() - .map(|i| OsString::from(i)), - ); + for _ in 0..8 { + wasm_pack::main( + ["wasm-pack", "build", "--mode", "force"] + .into_iter() + .map(|i| OsString::from(i)), + ); + } } fn parse_crates_io() { - assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(iai::black_box(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#))); -} - -fn parse_lockfile() -> wasm_pack::lockfile::Lockfile { - let bytes = iai::black_box(include_bytes!("lockfile.txt")); - toml::from_slice(bytes).unwrap() + assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); } iai::main!( run_wasm_pack, parse_crates_io, check_rustc_version, - check_for_wasm32_target, - parse_lockfile + check_for_wasm32_target ); diff --git a/benches/lockfile.txt b/benches/lockfile.txt deleted file mode 100644 index f67749be..00000000 --- a/benches/lockfile.txt +++ /dev/null @@ -1,1446 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anyhow" -version = "1.0.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "async-trait" -version = "0.1.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.0", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "axgeom" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db217c826c3f4cb10bb278b0fe0c6e17483bb1e9213709d229d2f18fa90cdca5" -dependencies = [ - "num-traits", - "partial-min-max", - "serde", -] - -[[package]] -name = "axum" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d8068b6ccb8b34db9de397c7043f91db8b4c66414952c6db944f238c4d3db3" -dependencies = [ - "async-trait", - "axum-core", - "bitflags", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tokio", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2f958c80c248b34b9a877a643811be8dbca03ca5ba827f2b63baf3a81e5fc4e" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "broccoli" -version = "6.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83629ad677c5ae614adc2536be0345f4ccece257bd08152a6589481cbc4b3ec5" -dependencies = [ - "axgeom", - "compt", - "revec", - "slice-group-by", - "twounordered", -] - -[[package]] -name = "bumpalo" -version = "3.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "compt" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e76b03e56db9abaa17c0df498682806499690473fc2b4b035a018d9b75053e3e" - -[[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", -] - -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "darling" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "deku" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819b87cc7a05b3abe3fc38e59b3980a5fd3162f25a247116441a9171d3e84481" -dependencies = [ - "bitvec", - "deku_derive", -] - -[[package]] -name = "deku_derive" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2ca12572239215a352a74ad7c776d7e8a914f8a23511c6cbedddd887e5009e" -dependencies = [ - "darling", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "enclose" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1056f553da426e9c025a662efa48b52e62e0a3a7648aa2d15aeaaf7f0d329357" - -[[package]] -name = "euclid" -version = "0.22.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b52c2ef4a78da0ba68fbe1fd920627411096d2ac478f7f4c9f3a54ba6705bade" -dependencies = [ - "num-traits", -] - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "futures" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" - -[[package]] -name = "futures-executor" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" - -[[package]] -name = "futures-macro" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "futures-sink" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" - -[[package]] -name = "futures-task" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" - -[[package]] -name = "futures-util" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if", - "js-sys", - "libc", - "wasi", - "wasm-bindgen", -] - -[[package]] -name = "gloo-events" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b107f8abed8105e4182de63845afcc7b69c098b7852a813ea7462a320992fc" -dependencies = [ - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "gloo-file" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d5564e570a38b43d78bdc063374a0c3098c4f0d64005b12f9bbe87e869b6d7" -dependencies = [ - "futures-channel", - "gloo-events", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "gloo-utils" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5" -dependencies = [ - "js-sys", - "serde", - "serde_json", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "h2" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - -[[package]] -name = "js-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "libc" -version = "0.2.140" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" - -[[package]] -name = "libm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "lyon_geom" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74df1ff0a0147282eb10699537a03baa7d31972b58984a1d44ce0624043fe8ad" -dependencies = [ - "arrayvec", - "euclid", - "num-traits", -] - -[[package]] -name = "matchit" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mio" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", - "libm", -] - -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "owned_ttf_parser" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25e9fb15717794fae58ab55c26e044103aad13186fbb625893f9a3bbcc24228" -dependencies = [ - "ttf-parser", -] - -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - -[[package]] -name = "partial-min-max" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6448add382c60bbbc64f9dab41309a12ec530c05191601042f911356ac09758c" - -[[package]] -name = "percent-encoding" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" - -[[package]] -name = "pin-project" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - -[[package]] -name = "proc-macro2" -version = "1.0.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "revec" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64dfec684e04cbb4a5f03ed70ac988c8d9d96db894c8e7d2ac42bbf3f91ea5b" - -[[package]] -name = "rustversion" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" - -[[package]] -name = "ryu" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "seed" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c0e296ea0569d20467e9a1df3cb6ed66ce3b791a7eaf1e1110ae231f75e2b46" -dependencies = [ - "enclose", - "futures", - "getrandom", - "gloo-file", - "gloo-timers", - "gloo-utils", - "indexmap", - "js-sys", - "rand", - "uuid", - "version_check", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "serde" -version = "1.0.157" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.157" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.0", -] - -[[package]] -name = "serde_json" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - -[[package]] -name = "sled" -version = "0.34.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" -dependencies = [ - "crc32fast", - "crossbeam-epoch", - "crossbeam-utils", - "fs2", - "fxhash", - "libc", - "log", - "parking_lot", -] - -[[package]] -name = "slice-group-by" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec" - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cff13bb1732bccfe3b246f3fdb09edfd51c01d6f5299b7ccd9457c2e4e37774" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "tokio" -version = "1.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "pin-project-lite", - "socket2", - "windows-sys", -] - -[[package]] -name = "tokio-util" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "toml_datetime" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" - -[[package]] -name = "toml_edit" -version = "0.19.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc18466501acd8ac6a3f615dd29a3438f8ca6bb3b19537138b3106e575621274" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "ttf-parser" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0609f771ad9c6155384897e1df4d948e692667cc0588548b68eb44d052b27633" - -[[package]] -name = "twounordered" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f40128da4fef8c4bf9cc1ab73d8126cb1148660d37a93d4a5110002a80657ba" - -[[package]] -name = "unicode-ident" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" - -[[package]] -name = "uuid" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" -dependencies = [ - "getrandom", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 1.0.109", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.84" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" - -[[package]] -name = "web-log" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57583eade6ead63af3267790de55b6e5dbe9fe2257ccc213feb62ab67f5c2dd3" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "web-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "winnow" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d020b441f92996c80d94ae9166e8501e59c7bb56121189dc9eab3bd8216966" -dependencies = [ - "memchr", -] - -[[package]] -name = "workspace-backend" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum", - "deku", - "fastrand", - "tokio", - "workspace-database", - "workspace-glyph", -] - -[[package]] -name = "workspace-database" -version = "0.1.0" -dependencies = [ - "anyhow", - "deku", - "sled", - "workspace-shared", -] - -[[package]] -name = "workspace-font-editor" -version = "0.1.0" -dependencies = [ - "broccoli", - "deku", - "js-sys", - "lyon_geom", - "owned_ttf_parser", - "seed", - "wasm-bindgen", - "web-log", - "web-sys", - "workspace-glyph", - "workspace-glyph-builder", - "workspace-glyph-svg", -] - -[[package]] -name = "workspace-frontend" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "seed", - "wasm-bindgen", - "workspace-font-editor", -] - -[[package]] -name = "workspace-frontend-cdylib" -version = "0.1.0" -dependencies = [ - "wasm-bindgen", - "workspace-frontend", - "workspace-glyph-svg", -] - -[[package]] -name = "workspace-glyph" -version = "0.1.0" -dependencies = [ - "broccoli", - "deku", - "fastrand", -] - -[[package]] -name = "workspace-glyph-builder" -version = "0.1.0" -dependencies = [ - "fastrand", - "workspace-glyph", -] - -[[package]] -name = "workspace-glyph-svg" -version = "0.1.0" -dependencies = [ - "broccoli", - "seed", - "wasm-bindgen", - "workspace-glyph", -] - -[[package]] -name = "workspace-shared" -version = "0.1.0" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] diff --git a/src/bindgen.rs b/src/bindgen.rs index 9c2cc599..1a27ad9a 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -42,10 +42,11 @@ pub fn wasm_bindgen_build( data.target_directory() }; - let mut wasm_path = target_directory.join("wasm32-unknown-unknown"); - wasm_path.push(release_or_debug); - wasm_path.push(data.crate_name()); - wasm_path.set_extension("wasm"); + let wasm_path = target_directory + .join("wasm32-unknown-unknown") + .join(release_or_debug) + .join(data.crate_name()) + .with_extension("wasm"); let dts_arg = if disable_dts { "--no-typescript" diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 7f4da59b..718beb69 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -84,16 +84,15 @@ fn get_rustc_sysroot() -> Result { fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { let wasm32_target = "wasm32-unknown-unknown"; - let mut path = sysroot.join("lib/rustlib"); + let rustlib_path = sysroot.join("lib/rustlib"); - info!("Looking for {} in {:?}", wasm32_target, path); - path.push(wasm32_target); + info!("Looking for {} in {:?}", wasm32_target, rustlib_path); - if path.exists() { - info!("Found {} in {:?}", wasm32_target, path.parent()); + if rustlib_path.join(wasm32_target).exists() { + info!("Found {} in {:?}", wasm32_target, rustlib_path); true } else { - info!("Failed to find {} in {:?}", wasm32_target, path.parent()); + info!("Failed to find {} in {:?}", wasm32_target, rustlib_path); false } } @@ -106,13 +105,14 @@ fn check_wasm32_target() -> Result> { Ok(None) // If it doesn't exist, then we need to check if we're using rustup. } else { + let rustc_path = which::which("rustc")?; // If sysroot contains "rustup", then we can assume we're using rustup // and use rustup to add the wasm32-unknown-unknown target. if sysroot.to_string_lossy().contains("rustup") { rustup_add_wasm_target().map(|()| None) } else { Ok(Some(Wasm32Check { - rustc_path: which::which("rustc")?, + rustc_path, sysroot, found: false, is_rustup: false, From 3b49bfb2dae95ff8ad61453a764a6b14e74a6d85 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:31 +0000 Subject: [PATCH 40/85] Revert "Add more benchmarks" This reverts commit 2db60b3a4726c9d143805727e2853ec589b1234b. --- benches/bench.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 88cd6570..eae93f01 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -3,7 +3,6 @@ mod fixture; use std::ffi::OsString; -use wasm_pack::build::{check_rustc_version, wasm_target::check_for_wasm32_target}; fn run_wasm_pack() { let fixture = fixture::dual_license(); @@ -22,9 +21,4 @@ fn parse_crates_io() { assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); } -iai::main!( - run_wasm_pack, - parse_crates_io, - check_rustc_version, - check_for_wasm32_target -); +iai::main!(run_wasm_pack, parse_crates_io); From d8f2bdd8de8de640c583dc485c328db13b9352cb Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:33 +0000 Subject: [PATCH 41/85] Revert "Fix bench" This reverts commit 204b138723a27e3b92ca054f3e67c87cfc3e8afe. --- benches/bench.rs | 21 ++++---- src/lib.rs | 109 ------------------------------------------ src/main.rs | 122 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 132 insertions(+), 120 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index eae93f01..0314c2aa 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -2,19 +2,20 @@ #[allow(unused)] mod fixture; -use std::ffi::OsString; +use std::process::Stdio; fn run_wasm_pack() { let fixture = fixture::dual_license(); - std::env::set_current_dir(&fixture.path).unwrap(); - std::env::set_var("WASM_PACK_CACHE", fixture.cache_dir()); - for _ in 0..8 { - wasm_pack::main( - ["wasm-pack", "build", "--mode", "force"] - .into_iter() - .map(|i| OsString::from(i)), - ); - } + assert!(fixture + .wasm_pack() + .arg("build") + .arg("--mode") + .arg("no-install") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .unwrap() + .success()) } fn parse_crates_io() { diff --git a/src/lib.rs b/src/lib.rs index c9e51054..8410b484 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,6 @@ pub mod command; pub mod emoji; pub mod generate; pub mod install; -mod installer; pub mod license; pub mod lockfile; pub mod manifest; @@ -46,13 +45,6 @@ pub mod test; pub mod wasm_opt; use crate::progressbar::{LogLevel, ProgressOutput}; -use crate::{build::WasmPackVersion, command::run_wasm_pack}; -use anyhow::Result; -use std::env; -use std::panic; -use std::sync::mpsc; -use std::thread; -use structopt::StructOpt; /// The global progress bar and user-facing message output. pub static PBAR: ProgressOutput = ProgressOutput::new(); @@ -76,104 +68,3 @@ pub struct Cli { /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } - -fn background_check_for_updates() -> mpsc::Receiver> { - let (sender, receiver) = mpsc::channel(); - - let _detached_thread = thread::spawn(move || { - let wasm_pack_version = build::check_wasm_pack_versions(); - - if let Ok(wasm_pack_version) = wasm_pack_version { - if !wasm_pack_version.local.is_empty() - && !wasm_pack_version.latest.is_empty() - && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest - { - let _ = sender.send(Ok(wasm_pack_version)); - } - } else { - let _ = sender.send(wasm_pack_version); - } - }); - - receiver -} - -/// Runs the CLI -pub fn main(args: impl Iterator) { - let _ = env_logger::try_init(); - - setup_panic_hooks(); - - if let Err(e) = run(args) { - eprintln!("Error: {}", e); - for cause in e.chain() { - eprintln!("Caused by: {}", cause); - } - ::std::process::exit(1); - } -} - -fn run(cmd_args: impl Iterator) -> Result<()> { - let wasm_pack_version = background_check_for_updates(); - - // Deprecate `init` - if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { - println!("wasm-pack init is deprecated, consider using wasm-pack build"); - } - - if let Ok(me) = env::current_exe() { - // If we're actually running as the installer then execute our - // self-installation, otherwise just continue as usual. - if me - .file_stem() - .and_then(|s| s.to_str()) - .expect("executable should have a filename") - .starts_with("wasm-pack-init") - { - installer::install(); - } - } - - let args = Cli::from_iter(cmd_args); - - PBAR.set_log_level(args.log_level); - - if args.quiet { - PBAR.set_quiet(true); - } - - run_wasm_pack(args.cmd)?; - - if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() { - match wasm_pack_version { - Ok(wasm_pack_version) => - PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ - To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), - Err(err) => PBAR.warn(&format!("{}", err)) - } - } - Ok(()) -} - -fn setup_panic_hooks() { - let meta = human_panic::Metadata { - version: env!("CARGO_PKG_VERSION").into(), - name: env!("CARGO_PKG_NAME").into(), - authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), - homepage: env!("CARGO_PKG_HOMEPAGE").into(), - }; - - let default_hook = panic::take_hook(); - - if let Err(_) = env::var("RUST_BACKTRACE") { - panic::set_hook(Box::new(move |info: &panic::PanicInfo| { - // First call the default hook that prints to standard error. - default_hook(info); - - // Then call human_panic. - let file_path = human_panic::handle_dump(&meta, info); - human_panic::print_msg(file_path, &meta) - .expect("human-panic: printing error message to console failed"); - })); - } -} diff --git a/src/main.rs b/src/main.rs index f88b3e33..67320eda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,132 @@ +#![allow(clippy::redundant_closure, clippy::redundant_pattern_matching)] + +extern crate anyhow; +extern crate atty; +extern crate env_logger; +extern crate human_panic; +extern crate log; +extern crate structopt; extern crate wasm_pack; +extern crate which; + +use anyhow::Result; +use std::env; +use std::panic; +use std::sync::mpsc; +use std::thread; +use structopt::StructOpt; +use wasm_pack::{ + build::{self, WasmPackVersion}, + command::run_wasm_pack, + Cli, PBAR, +}; + +mod installer; #[cfg(feature = "perf")] #[global_allocator] static ALLOC: dhat::Alloc = dhat::Alloc; +fn background_check_for_updates() -> mpsc::Receiver> { + let (sender, receiver) = mpsc::channel(); + + let _detached_thread = thread::spawn(move || { + let wasm_pack_version = build::check_wasm_pack_versions(); + + if let Ok(wasm_pack_version) = wasm_pack_version { + if !wasm_pack_version.local.is_empty() + && !wasm_pack_version.latest.is_empty() + && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest + { + let _ = sender.send(Ok(wasm_pack_version)); + } + } else { + let _ = sender.send(wasm_pack_version); + } + }); + + receiver +} + fn main() { #[cfg(feature = "perf")] let _profiler = dhat::Profiler::new_heap(); - wasm_pack::main(std::env::args_os()) + env_logger::init(); + + setup_panic_hooks(); + + if let Err(e) = run() { + eprintln!("Error: {}", e); + for cause in e.chain() { + eprintln!("Caused by: {}", cause); + } + ::std::process::exit(1); + } +} + +fn run() -> Result<()> { + let wasm_pack_version = background_check_for_updates(); + + // Deprecate `init` + if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) { + println!("wasm-pack init is deprecated, consider using wasm-pack build"); + } + + if let Ok(me) = env::current_exe() { + // If we're actually running as the installer then execute our + // self-installation, otherwise just continue as usual. + if me + .file_stem() + .and_then(|s| s.to_str()) + .expect("executable should have a filename") + .starts_with("wasm-pack-init") + { + installer::install(); + } + } + + let args = Cli::from_args(); + + PBAR.set_log_level(args.log_level); + + if args.quiet { + PBAR.set_quiet(true); + } + + run_wasm_pack(args.cmd)?; + + if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() { + match wasm_pack_version { + Ok(wasm_pack_version) => + PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ + To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), + Err(err) => PBAR.warn(&format!("{}", err)) + } + } + + Ok(()) +} + +fn setup_panic_hooks() { + let meta = human_panic::Metadata { + version: env!("CARGO_PKG_VERSION").into(), + name: env!("CARGO_PKG_NAME").into(), + authors: env!("CARGO_PKG_AUTHORS").replace(":", ", ").into(), + homepage: env!("CARGO_PKG_HOMEPAGE").into(), + }; + + let default_hook = panic::take_hook(); + + if let Err(_) = env::var("RUST_BACKTRACE") { + panic::set_hook(Box::new(move |info: &panic::PanicInfo| { + // First call the default hook that prints to standard error. + default_hook(info); + + // Then call human_panic. + let file_path = human_panic::handle_dump(&meta, info); + human_panic::print_msg(file_path, &meta) + .expect("human-panic: printing error message to console failed"); + })); + } } From 4670669e4cdf27ef086468b12af841c96517d528 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:36 +0000 Subject: [PATCH 42/85] Revert "Use iai benchmark" This reverts commit 0725710ef75ebd62f2608af3dcbd25fe383b8566. --- Cargo.lock | 235 +++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- benches/bench.rs | 21 +++-- 3 files changed, 240 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efc5c675..9dac857b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "ansi_term" version = "0.12.1" @@ -277,6 +283,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.0.79" @@ -307,6 +319,33 @@ dependencies = [ "winapi", ] +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "cipher" version = "0.3.0" @@ -326,11 +365,32 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex", + "indexmap", + "textwrap 0.16.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -409,6 +469,76 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap 3.2.23", + "criterion-plot", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.15" @@ -847,6 +977,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.12.3" @@ -988,12 +1124,6 @@ dependencies = [ "tokio-native-tls", ] -[[package]] -name = "iai" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1182,6 +1312,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.16" @@ -1287,6 +1426,12 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -1359,6 +1504,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "os_str_bytes" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1429,6 +1580,34 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + [[package]] name = "predicates" version = "2.1.5" @@ -1519,6 +1698,28 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1856,7 +2057,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap", + "clap 2.34.0", "lazy_static", "structopt-derive", ] @@ -1960,6 +2161,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.40" @@ -2013,6 +2220,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2345,13 +2562,13 @@ dependencies = [ "cargo_metadata", "chrono", "console", + "criterion", "curl", "dhat", "dialoguer", "env_logger", "glob", "human-panic", - "iai", "lazy_static", "log", "openssl", diff --git a/Cargo.toml b/Cargo.toml index a3723378..512e1b18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ which = "4.4.0" [dev-dependencies] assert_cmd = "2.0.8" -iai = "0.1" +criterion = "0.4.0" lazy_static = "1.4.0" predicates = "2.1.5" serial_test = "1.0.0" diff --git a/benches/bench.rs b/benches/bench.rs index 0314c2aa..7aabc1dc 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -2,15 +2,23 @@ #[allow(unused)] mod fixture; +use criterion::{criterion_group, criterion_main, Criterion}; use std::process::Stdio; -fn run_wasm_pack() { +pub fn criterion_benchmark(c: &mut Criterion) { + let mut g = c.benchmark_group("wasm-pack"); + g.warm_up_time(std::time::Duration::from_secs(10)); let fixture = fixture::dual_license(); + run(&fixture); + g.bench_function("re-run build without code changes", |b| { + b.iter(|| run(&fixture)) + }); +} + +fn run(fixture: &fixture::Fixture) { assert!(fixture .wasm_pack() .arg("build") - .arg("--mode") - .arg("no-install") .stdout(Stdio::null()) .stderr(Stdio::null()) .status() @@ -18,8 +26,5 @@ fn run_wasm_pack() { .success()) } -fn parse_crates_io() { - assert_eq!(Some(&b"0.11.0"[..]), wasm_pack::manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)); -} - -iai::main!(run_wasm_pack, parse_crates_io); +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); From 32e39b223dab3c362d03bb12fdc82539f440883e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:38 +0000 Subject: [PATCH 43/85] Revert "Optimize lockfile" This reverts commit 4d90f54a4e9e7950906bdf0fcaf5408b9360060f. --- src/lockfile.rs | 60 +++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/src/lockfile.rs b/src/lockfile.rs index 9db10e0a..f4a68eac 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -13,55 +13,14 @@ use toml; /// This struct represents the contents of `Cargo.lock`. #[derive(Clone, Debug, Deserialize)] pub struct Lockfile { - package: Packages, -} - -#[derive(Clone, Debug, Default)] -struct Packages { - wasm_bindgen_version: Option, - wasm_bindgen_test_version: Option, + package: Vec, } /// This struct represents a single package entry in `Cargo.lock` #[derive(Clone, Debug, Deserialize)] -struct Package<'a> { - name: &'a str, - version: &'a str, -} - -impl<'de> serde::Deserialize<'de> for Packages { - fn deserialize(deserializer: D) -> std::result::Result - where - D: serde::Deserializer<'de>, - { - deserializer.deserialize_seq(PackagesVisitor) - } -} - -struct PackagesVisitor; - -impl<'de> serde::de::Visitor<'de> for PackagesVisitor { - type Value = Packages; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a sequence") - } - - fn visit_seq(self, mut seq: A) -> std::result::Result - where - A: serde::de::SeqAccess<'de>, - { - let mut result = Packages::default(); - while let Some(package) = seq.next_element::()? { - let field = match package.name { - "wasm-bindgen" => &mut result.wasm_bindgen_version, - "wasm-bindgen-test" => &mut result.wasm_bindgen_test_version, - _ => continue, - }; - *field = Some(package.version.to_owned()); - } - Ok(result) - } +struct Package { + name: String, + version: String, } impl Lockfile { @@ -77,7 +36,7 @@ impl Lockfile { /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. pub fn wasm_bindgen_version(&self) -> Option<&str> { - self.package.wasm_bindgen_version.as_deref() + self.get_package_version("wasm-bindgen") } /// Like `wasm_bindgen_version`, except it returns an error instead of @@ -95,7 +54,14 @@ impl Lockfile { /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. pub fn wasm_bindgen_test_version(&self) -> Option<&str> { - self.package.wasm_bindgen_test_version.as_deref() + self.get_package_version("wasm-bindgen-test") + } + + fn get_package_version(&self, package: &str) -> Option<&str> { + self.package + .iter() + .find(|p| p.name == package) + .map(|p| &p.version[..]) } } From d61822b4af738a95d307d481d2f4b1dc8347e2e9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:40 +0000 Subject: [PATCH 44/85] Revert "Refactor run_step" This reverts commit 130e237833e09cae1aef6e8bcebe838b81dc810b. --- src/command/utils.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/command/utils.rs b/src/command/utils.rs index 70d76bf7..2a5da5a1 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -73,16 +73,11 @@ pub fn elapsed(duration: Duration) -> String { /// Runs a funcion and reports duration if `perf` feature is enabled pub fn run_step((name, mut f): (&'static str, impl FnMut(T) -> U), arg: T) -> U { + let start = std::time::Instant::now(); + let result = f(arg); #[cfg(feature = "perf")] - { - let start = std::time::Instant::now(); - let result = f(arg); - println!("{}: {} s", name, start.elapsed().as_secs_f64()); - result - } + println!("{}: {} s", name, start.elapsed().as_secs_f64()); #[cfg(not(feature = "perf"))] - { - let _ = name; - f(arg) - } + let _ = name; + result } From 4bf43c494ae10e2691dbcef5d369da87f82c4a0d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:44 +0000 Subject: [PATCH 45/85] Revert "Add perf feature" This reverts commit 836fe7dc0d4bc0900434509d1605e1a79311f9e4. --- .gitignore | 1 - Cargo.lock | 49 -------------------------------------------- Cargo.toml | 2 -- src/command/build.rs | 4 ++-- src/command/test.rs | 4 ++-- src/command/utils.rs | 11 ---------- src/main.rs | 7 ------- 7 files changed, 4 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index cd34a72c..4d857446 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ tests/bin /build-installer docs/book docs/installer -dhat-heap.json diff --git a/Cargo.lock b/Cargo.lock index 9dac857b..8c647be5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,22 +645,6 @@ dependencies = [ "parking_lot_core", ] -[[package]] -name = "dhat" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2aaf837aaf456f6706cb46386ba8dffd4013a757e36f4ea05c20dd46b209a3" -dependencies = [ - "backtrace", - "lazy_static", - "mintex", - "parking_lot", - "rustc-hash", - "serde", - "serde_json", - "thousands", -] - [[package]] name = "dialoguer" version = "0.10.3" @@ -1336,16 +1320,6 @@ dependencies = [ "adler", ] -[[package]] -name = "mintex" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7c5ba1c3b5a23418d7bbf98c71c3d4946a0125002129231da8d6b723d559cb" -dependencies = [ - "once_cell", - "sys-info", -] - [[package]] name = "mio" version = "0.8.6" @@ -1806,12 +1780,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustix" version = "0.36.10" @@ -2103,16 +2071,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sys-info" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "tar" version = "0.4.38" @@ -2187,12 +2145,6 @@ dependencies = [ "syn 2.0.2", ] -[[package]] -name = "thousands" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" - [[package]] name = "time" version = "0.1.45" @@ -2564,7 +2516,6 @@ dependencies = [ "console", "criterion", "curl", - "dhat", "dialoguer", "env_logger", "glob", diff --git a/Cargo.toml b/Cargo.toml index 512e1b18..5c0d1808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ cargo_metadata = "0.15.2" chrono = "0.4.23" console = "0.15.5" curl = "0.4.44" -dhat = { version = "0.3.2", optional = true } dialoguer = "0.10.3" env_logger = { version = "0.10.0", default-features = false } glob = "0.3.1" @@ -54,7 +53,6 @@ tempfile = "3.3.0" [features] # OpenSSL is vendored by default, can use system OpenSSL through feature flag. default = ['openssl/vendored'] -perf = ["dep:dhat"] # Treat compiler warnings as a build error. # This only runs in CI by default diff --git a/src/command/build.rs b/src/command/build.rs index bdab0fef..a8c9e9fa 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -258,8 +258,8 @@ impl Build { let started = Instant::now(); - for process_step in process_steps { - super::utils::run_step(process_step, self)?; + for (_, process_step) in process_steps { + process_step(self)?; } let duration = crate::command::utils::elapsed(started.elapsed()); diff --git a/src/command/test.rs b/src/command/test.rs index a80603ee..db009944 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -185,8 +185,8 @@ impl Test { let process_steps = self.get_process_steps(); let started = Instant::now(); - for process_step in process_steps { - super::utils::run_step(process_step, &mut self)?; + for (_, process_step) in process_steps { + process_step(&mut self)?; } let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); diff --git a/src/command/utils.rs b/src/command/utils.rs index 2a5da5a1..152dd99a 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -70,14 +70,3 @@ pub fn elapsed(duration: Duration) -> String { format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000) } } - -/// Runs a funcion and reports duration if `perf` feature is enabled -pub fn run_step((name, mut f): (&'static str, impl FnMut(T) -> U), arg: T) -> U { - let start = std::time::Instant::now(); - let result = f(arg); - #[cfg(feature = "perf")] - println!("{}: {} s", name, start.elapsed().as_secs_f64()); - #[cfg(not(feature = "perf"))] - let _ = name; - result -} diff --git a/src/main.rs b/src/main.rs index 67320eda..72739809 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,6 @@ use wasm_pack::{ mod installer; -#[cfg(feature = "perf")] -#[global_allocator] -static ALLOC: dhat::Alloc = dhat::Alloc; - fn background_check_for_updates() -> mpsc::Receiver> { let (sender, receiver) = mpsc::channel(); @@ -49,9 +45,6 @@ fn background_check_for_updates() -> mpsc::Receiver> { } fn main() { - #[cfg(feature = "perf")] - let _profiler = dhat::Profiler::new_heap(); - env_logger::init(); setup_panic_hooks(); From 4de8b2798ab73a378a4552386fe87dbbbdc28868 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:46 +0000 Subject: [PATCH 46/85] Revert "More optimization" This reverts commit 3f35b47f09b8ead779b0d95a2ea0fe3f5cfe8f7d. --- src/bindgen.rs | 1 + src/license.rs | 26 +++++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 1a27ad9a..656521bc 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -29,6 +29,7 @@ pub fn wasm_bindgen_build( BuildProfile::Dev => "debug", }; + let out_dir = out_dir.to_str().unwrap(); let has_target_dir_overwrite = extra_options.iter().any(|i| i == "--target-dir"); let target_directory = if has_target_dir_overwrite { let i = extra_options diff --git a/src/license.rs b/src/license.rs index b1c4d44f..a9394c88 100644 --- a/src/license.rs +++ b/src/license.rs @@ -1,31 +1,23 @@ //! Copy `LICENSE` file(s) for the packaged wasm. -use anyhow::{anyhow, Context, Result}; -use std::ffi::OsString; +use anyhow::{anyhow, Result}; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use crate::manifest::CrateData; use crate::PBAR; use glob::glob; fn glob_license_files(path: &Path) -> Result> + '_> { - let mut path_buf = { - let mut os_string = OsString::with_capacity(path.as_os_str().len() + 9); - os_string.push(path); - PathBuf::from(os_string) + let joined_path = path.join("LICENSE*"); + let path_string = match joined_path.to_str() { + Some(path_string) => path_string, + None => { + return Err(anyhow!("Could not convert joined license path to String")); + } }; - // Add trailing slash - path_buf.push(""); - // Convert to String without validating the bytes in "LICENSE*" - let mut path_string = path_buf - .into_os_string() - .into_string() - .ok() - .context("Could not convert joined license path to String")?; - path_string.push_str("LICENSE*"); - Ok(glob(&path_string)?.map(|entry| match entry { + Ok(glob(path_string)?.map(|entry| match entry { Ok(globed_path) => { let file_name = match globed_path.file_name() { Some(file_name) => file_name, From 00d0ed0df431d0a2a95210b73278e372c826e4a4 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:48 +0000 Subject: [PATCH 47/85] Revert "Clippy" This reverts commit cca671c2a51ed825e1480faaa89cd42e874dae20. --- src/command/login.rs | 2 +- src/command/test.rs | 2 +- src/license.rs | 2 +- src/manifest/mod.rs | 6 +++--- src/npm.rs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command/login.rs b/src/command/login.rs index 9794a6c4..933007f2 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -25,6 +25,6 @@ pub fn login( npm::npm_login(®istry, &scope, always_auth, &auth_type)?; info!("Logged you in!"); - PBAR.info("👋 logged you in!"); + PBAR.info(&"👋 logged you in!".to_string()); Ok(()) } diff --git a/src/command/test.rs b/src/command/test.rs index db009944..3940b4af 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -129,7 +129,7 @@ impl Test { let first_arg_is_path = path_and_extra_options .get(0) - .map(|first_arg| !first_arg.starts_with('-')) + .map(|first_arg| !first_arg.starts_with("-")) .unwrap_or(false); let (path, extra_options) = if first_arg_is_path { diff --git a/src/license.rs b/src/license.rs index a9394c88..483b3496 100644 --- a/src/license.rs +++ b/src/license.rs @@ -8,7 +8,7 @@ use crate::manifest::CrateData; use crate::PBAR; use glob::glob; -fn glob_license_files(path: &Path) -> Result> + '_> { +fn glob_license_files<'a>(path: &'a Path) -> Result> + 'a> { let joined_path = path.join("LICENSE*"); let path_string = match joined_path.to_str() { Some(path_string) => path_string, diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 4561689e..4ed8bdb0 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -188,7 +188,7 @@ fn override_stamp_file( if let Some(version) = version { write!(file, "\nversion ")?; - file.write_all(version)?; + file.write(version)?; } Ok(()) @@ -522,8 +522,8 @@ impl CrateData { .iter() .find(|t| t.kind.iter().any(|k| k == "cdylib")) { - Some(lib) => lib.name.replace('-', "_"), - None => pkg.name.replace('-', "_"), + Some(lib) => lib.name.replace("-", "_"), + None => pkg.name.replace("-", "_"), } } diff --git a/src/npm.rs b/src/npm.rs index 76d3b931..11d2b5f3 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -47,7 +47,7 @@ pub fn npm_login( cmd.arg("login").arg(build_arg("--registry=", registry)); if let Some(scope) = scope { - cmd.arg(build_arg("--scope=", scope)); + cmd.arg(build_arg("--scope=", &scope)); } if always_auth { @@ -55,7 +55,7 @@ pub fn npm_login( } if let Some(auth_type) = auth_type { - cmd.arg(build_arg("--auth_type=", auth_type)); + cmd.arg(build_arg("--auth_type=", &auth_type)); } info!("Running {:?}", cmd); From 973c808685061fd3f5466d4f7d583fb1449d08a1 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:51 +0000 Subject: [PATCH 48/85] Revert "Optimize rustc version check" This reverts commit 0dc955deebcbc6b317628ab0247f2606d231e8c4. --- src/build/mod.rs | 52 +++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 7d7c33f1..2d39bc64 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -5,7 +5,7 @@ use crate::command::build::BuildProfile; use crate::emoji; use crate::manifest; use crate::PBAR; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{bail, Context, Result}; use std::ffi::OsString; use std::path::Path; use std::process::Command; @@ -25,29 +25,39 @@ pub struct WasmPackVersion { /// Ensure that `rustc` is present and that it is >= 1.30.0 pub fn check_rustc_version() -> Result { - try_check_rustc_version().unwrap_or_else(|| bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher.")) + let local_minor_version = rustc_minor_version(); + match local_minor_version { + Some(mv) => { + if mv < 30 { + bail!( + "Your version of Rust, '1.{}', is not supported. Please install Rust version 1.30.0 or higher.", + mv.to_string() + ) + } else { + Ok(mv.to_string()) + } + } + None => bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher."), + } } // from https://github.com/alexcrichton/proc-macro2/blob/79e40a113b51836f33214c6d00228934b41bd4ad/build.rs#L44-L61 -fn try_check_rustc_version() -> Option> { - let output = Command::new("rustc").arg("--version").output().ok()?.stdout; - let minor = str::from_utf8( - output - .strip_prefix(b"rustc 1.")? - .split(|&b| b == b'.') - .next()?, - ) - .ok()?; - let supported = match minor.len() { - 2 => minor >= "30", - 1 => false, - _ => true, - }; - Some(if supported { - Ok(minor.to_owned()) - } else { - Err(anyhow!("Your version of Rust, '1.{}', is not supported. Please install Rust version 1.30.0 or higher.", minor)) - }) +fn rustc_minor_version() -> Option { + macro_rules! otry { + ($e:expr) => { + match $e { + Some(e) => e, + None => return None, + } + }; + } + let output = otry!(Command::new("rustc").arg("--version").output().ok()); + let version = otry!(str::from_utf8(&output.stdout).ok()); + let mut pieces = version.split('.'); + if pieces.next() != Some("rustc 1") { + return None; + } + otry!(pieces.next()).parse().ok() } /// Checks and returns local and latest versions of wasm-pack From 05f31ee67702a7b58b06e34a22093e4c08f7508f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:53 +0000 Subject: [PATCH 49/85] Revert "More optimization" This reverts commit b5f7654dbd183c29a10f208a0ca5c653e2aca01d. --- src/build/wasm_target.rs | 26 ++++++++++++++++++-------- src/wasm_opt.rs | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 718beb69..8631086f 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -58,8 +58,8 @@ pub fn check_for_wasm32_target() -> Result<()> { // Check if wasm32 target is present, otherwise bail. match check_wasm32_target() { - Ok(None) => Ok(()), - Ok(Some(wasm32_check)) => bail!("{}", wasm32_check), + Ok(ref wasm32_check) if wasm32_check.found => Ok(()), + Ok(wasm32_check) => bail!("{}", wasm32_check), Err(err) => Err(err), } } @@ -97,26 +97,36 @@ fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { } } -fn check_wasm32_target() -> Result> { +fn check_wasm32_target() -> Result { let sysroot = get_rustc_sysroot()?; + let rustc_path = which::which("rustc")?; // If wasm32-unknown-unknown already exists we're ok. if is_wasm32_target_in_sysroot(&sysroot) { - Ok(None) + Ok(Wasm32Check { + rustc_path, + sysroot, + found: true, + is_rustup: false, + }) // If it doesn't exist, then we need to check if we're using rustup. } else { - let rustc_path = which::which("rustc")?; // If sysroot contains "rustup", then we can assume we're using rustup // and use rustup to add the wasm32-unknown-unknown target. if sysroot.to_string_lossy().contains("rustup") { - rustup_add_wasm_target().map(|()| None) + rustup_add_wasm_target().map(|()| Wasm32Check { + rustc_path, + sysroot, + found: true, + is_rustup: true, + }) } else { - Ok(Some(Wasm32Check { + Ok(Wasm32Check { rustc_path, sysroot, found: false, is_rustup: false, - })) + }) } } } diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 9df8102b..6e2149ae 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -29,7 +29,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo for file in out_dir.read_dir()? { let file = file?; let path = file.path(); - if path.extension().filter(|&ext| ext == "wasm").is_none() { + if path.extension().and_then(|s| s.to_str()) != Some("wasm") { continue; } From c2949807cde5ca6060749fd39dd64306349d6080 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:55 +0000 Subject: [PATCH 50/85] Revert "Allow unused" This reverts commit 87e0e26f89ea6837dc5ed4777cc7692a6bd87abe. --- benches/bench.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/benches/bench.rs b/benches/bench.rs index 7aabc1dc..f5c6211a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,5 +1,4 @@ #[path = "../tests/all/utils/fixture.rs"] -#[allow(unused)] mod fixture; use criterion::{criterion_group, criterion_main, Criterion}; From 1dd7e7836f1919595384cc52982d59e4ce2b5de9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:53:58 +0000 Subject: [PATCH 51/85] Revert "increase warm up time" This reverts commit dd71328c0f20da00e7f54460e95efdd3957a86ef. --- benches/bench.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index f5c6211a..d4c4ac14 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -5,11 +5,9 @@ use criterion::{criterion_group, criterion_main, Criterion}; use std::process::Stdio; pub fn criterion_benchmark(c: &mut Criterion) { - let mut g = c.benchmark_group("wasm-pack"); - g.warm_up_time(std::time::Duration::from_secs(10)); let fixture = fixture::dual_license(); run(&fixture); - g.bench_function("re-run build without code changes", |b| { + c.bench_function("re-run build without code changes", |b| { b.iter(|| run(&fixture)) }); } From 259dcda903d53f42dfa3f72a5437d7085616b11d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:00 +0000 Subject: [PATCH 52/85] Revert "Add benchmark" This reverts commit ade563a589a1f798c0917e3ec5228507dd1aaba7. --- Cargo.lock | 228 +---------------------------------------------- Cargo.toml | 5 -- benches/bench.rs | 27 ------ 3 files changed, 2 insertions(+), 258 deletions(-) delete mode 100644 benches/bench.rs diff --git a/Cargo.lock b/Cargo.lock index 8c647be5..7c97c905 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,12 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "ansi_term" version = "0.12.1" @@ -283,12 +277,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.79" @@ -319,33 +307,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ciborium" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" - -[[package]] -name = "ciborium-ll" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "cipher" version = "0.3.0" @@ -365,32 +326,11 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap 0.11.0", + "textwrap", "unicode-width", "vec_map", ] -[[package]] -name = "clap" -version = "3.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" -dependencies = [ - "bitflags", - "clap_lex", - "indexmap", - "textwrap 0.16.0", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -469,76 +409,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" -dependencies = [ - "anes", - "atty", - "cast", - "ciborium", - "clap 3.2.23", - "criterion-plot", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - [[package]] name = "crossbeam-utils" version = "0.8.15" @@ -961,12 +831,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - [[package]] name = "hashbrown" version = "0.12.3" @@ -1296,15 +1160,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.16" @@ -1400,12 +1255,6 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "opaque-debug" version = "0.3.0" @@ -1478,12 +1327,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1554,34 +1397,6 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" -[[package]] -name = "plotters" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" - -[[package]] -name = "plotters-svg" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" -dependencies = [ - "plotters-backend", -] - [[package]] name = "predicates" version = "2.1.5" @@ -1672,28 +1487,6 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -[[package]] -name = "rayon" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -2025,7 +1818,7 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" dependencies = [ - "clap 2.34.0", + "clap", "lazy_static", "structopt-derive", ] @@ -2119,12 +1912,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.40" @@ -2172,16 +1959,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -2514,7 +2291,6 @@ dependencies = [ "cargo_metadata", "chrono", "console", - "criterion", "curl", "dialoguer", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 5c0d1808..a4a38f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,6 @@ readme = "README.md" categories = ["wasm"] documentation = "https://rustwasm.github.io/wasm-pack/" -[[bench]] -name = "bench" -harness = false - [dependencies] anyhow = "1.0.68" atty = "0.2.14" @@ -44,7 +40,6 @@ which = "4.4.0" [dev-dependencies] assert_cmd = "2.0.8" -criterion = "0.4.0" lazy_static = "1.4.0" predicates = "2.1.5" serial_test = "1.0.0" diff --git a/benches/bench.rs b/benches/bench.rs deleted file mode 100644 index d4c4ac14..00000000 --- a/benches/bench.rs +++ /dev/null @@ -1,27 +0,0 @@ -#[path = "../tests/all/utils/fixture.rs"] -mod fixture; - -use criterion::{criterion_group, criterion_main, Criterion}; -use std::process::Stdio; - -pub fn criterion_benchmark(c: &mut Criterion) { - let fixture = fixture::dual_license(); - run(&fixture); - c.bench_function("re-run build without code changes", |b| { - b.iter(|| run(&fixture)) - }); -} - -fn run(fixture: &fixture::Fixture) { - assert!(fixture - .wasm_pack() - .arg("build") - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .unwrap() - .success()) -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); From 6043c9cbe2a60a3197098623f7d49804d2f9f39b Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:02 +0000 Subject: [PATCH 53/85] Revert "Reduce heap allocations" This reverts commit 114d12b6482d8d89a6031ae929b68c84e6cee382. --- src/command/test.rs | 16 ++++++++-------- src/install/mod.rs | 6 +++--- src/license.rs | 41 +++++++++++++++++++++-------------------- src/manifest/mod.rs | 9 +++++---- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/command/test.rs b/src/command/test.rs index 3940b4af..616f99ad 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -194,17 +194,17 @@ impl Test { Ok(()) } - fn get_process_steps(&self) -> impl Iterator { - let identity = |i| i; + fn get_process_steps(&self) -> Vec<(&'static str, TestStep)> { macro_rules! steps { ($($name:ident $(if $e:expr)* ),+) => { { - vec![$({ - let step: TestStep = Test::$name; - Some((stringify!($name), step))$(.filter(|_| $e))* - },)*] - .into_iter() - .filter_map(identity) + let mut steps: Vec<(&'static str, TestStep)> = Vec::new(); + $( + $(if $e)* { + steps.push((stringify!($name), Test::$name)); + } + )* + steps } }; ($($name:ident $(if $e:expr)* ,)*) => (steps![$($name $(if $e)* ),*]) diff --git a/src/install/mod.rs b/src/install/mod.rs index c4361407..6debaccd 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -270,9 +270,9 @@ pub fn cargo_install( // just want them in `$root/*` directly (which matches how the tarballs are // laid out, and where the rest of our code expects them to be). So we do a // little renaming here. - let binaries: Result<&[&str]> = match tool { - Tool::WasmBindgen => Ok(&["wasm-bindgen", "wasm-bindgen-test-runner"]), - Tool::CargoGenerate => Ok(&["cargo-generate"]), + let binaries: Result> = match tool { + Tool::WasmBindgen => Ok(vec!["wasm-bindgen", "wasm-bindgen-test-runner"]), + Tool::CargoGenerate => Ok(vec!["cargo-generate"]), Tool::WasmOpt => bail!("Cannot install wasm-opt with cargo."), }; diff --git a/src/license.rs b/src/license.rs index 483b3496..5305e41e 100644 --- a/src/license.rs +++ b/src/license.rs @@ -8,29 +8,32 @@ use crate::manifest::CrateData; use crate::PBAR; use glob::glob; -fn glob_license_files<'a>(path: &'a Path) -> Result> + 'a> { - let joined_path = path.join("LICENSE*"); - let path_string = match joined_path.to_str() { - Some(path_string) => path_string, +fn glob_license_files(path: &Path) -> Result> { + let mut license_files: Vec = Vec::new(); + let path_string = match path.join("LICENSE*").to_str() { + Some(path_string) => path_string.to_owned(), None => { return Err(anyhow!("Could not convert joined license path to String")); } }; - Ok(glob(path_string)?.map(|entry| match entry { - Ok(globed_path) => { - let file_name = match globed_path.file_name() { - Some(file_name) => file_name, - None => return Err(anyhow!("Could not get file name from path")), - }; - let file_name_string = match file_name.to_str() { - Some(file_name_string) => file_name_string.to_owned(), - None => return Err(anyhow!("Could not convert filename to String")), - }; - Ok(file_name_string) + for entry in glob(&path_string)? { + match entry { + Ok(globed_path) => { + let file_name = match globed_path.file_name() { + Some(file_name) => file_name, + None => return Err(anyhow!("Could not get file name from path")), + }; + let file_name_string = match file_name.to_str() { + Some(file_name_string) => file_name_string.to_owned(), + None => return Err(anyhow!("Could not convert filename to String")), + }; + license_files.push(file_name_string); + } + Err(e) => println!("{:?}", e), } - Err(e) => Err(anyhow!("{:?}", e)), - })) + } + Ok(license_files) } /// Copy the crate's license into the `pkg` directory. @@ -51,13 +54,11 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R match license_files { Ok(files) => { - let mut files = files.peekable(); - if files.peek().is_none() { + if files.is_empty() { PBAR.info("License key is set in Cargo.toml but no LICENSE file(s) were found; Please add the LICENSE file(s) to your project directory"); return Ok(()); } for license_file in files { - let license_file = license_file?; let crate_license_path = path.join(&license_file); let new_license_path = out_dir.join(&license_file); if fs::copy(&crate_license_path, &new_license_path).is_err() { diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 4ed8bdb0..b0814eb6 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -604,8 +604,7 @@ impl CrateData { let name_prefix = self.name_prefix(); let wasm_file = format!("{}_bg.wasm", name_prefix); let js_file = format!("{}.js", name_prefix); - let mut files = Vec::with_capacity(6); - files.push(wasm_file); + let mut files = vec![wasm_file]; files.push(js_file.clone()); if add_js_bg_to_package_json { @@ -640,7 +639,9 @@ impl CrateData { .filter_map(|e| e.file_name().into_string().ok()) .filter(|f| f.starts_with("LICENSE")) .filter(|f| f != "LICENSE"); - files.extend(file_names); + for file_name in file_names { + files.push(file_name); + } } NpmData { @@ -789,7 +790,7 @@ impl CrateData { } fn check_optional_fields(&self) { - let mut messages = Vec::with_capacity(3); + let mut messages = vec![]; if self.pkg().description.is_none() { messages.push("description"); } From 4fc118bc2ddd6ee38d6da698ffd4a8f4b6f68b1e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:04 +0000 Subject: [PATCH 54/85] Revert "Reduce conversions from OsString to String" This reverts commit 85586ee861957631cc613c0357a85564a6e6bae3. --- src/bindgen.rs | 7 +++--- src/build/mod.rs | 3 +-- src/command/build.rs | 49 +++++++++++++++++--------------------- src/command/generate.rs | 6 ++--- src/command/login.rs | 15 ++++-------- src/command/mod.rs | 28 ++++++++-------------- src/command/publish/mod.rs | 13 +++++----- src/command/test.rs | 2 +- src/generate.rs | 5 ++-- src/install/mode.rs | 26 ++++++++++---------- src/npm.rs | 35 +++++++++++---------------- 11 files changed, 78 insertions(+), 111 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 656521bc..58fab360 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -6,7 +6,6 @@ use crate::install::{self, Tool}; use crate::manifest::CrateData; use anyhow::{bail, Context, Result}; use semver; -use std::ffi::{OsStr, OsString}; use std::path::Path; use std::process::Command; @@ -22,7 +21,7 @@ pub fn wasm_bindgen_build( reference_types: bool, target: Target, profile: BuildProfile, - extra_options: &Vec, + extra_options: &Vec, ) -> Result<()> { let release_or_debug = match profile { BuildProfile::Release | BuildProfile::Profiling => "release", @@ -30,10 +29,10 @@ pub fn wasm_bindgen_build( }; let out_dir = out_dir.to_str().unwrap(); - let has_target_dir_overwrite = extra_options.iter().any(|i| i == "--target-dir"); + let has_target_dir_overwrite = extra_options.contains(&"--target-dir".to_string()); let target_directory = if has_target_dir_overwrite { let i = extra_options - .binary_search_by(|i| i.as_os_str().cmp(OsStr::new("--target-dir"))) + .binary_search(&"--target-dir".to_string()) .unwrap(); extra_options .get(i + 1) diff --git a/src/build/mod.rs b/src/build/mod.rs index 2d39bc64..5fb9e375 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -6,7 +6,6 @@ use crate::emoji; use crate::manifest; use crate::PBAR; use anyhow::{bail, Context, Result}; -use std::ffi::OsString; use std::path::Path; use std::process::Command; use std::str; @@ -77,7 +76,7 @@ fn wasm_pack_local_version() -> Option<&'static str> { pub fn cargo_build_wasm( path: &Path, profile: BuildProfile, - extra_options: &[OsString], + extra_options: &[String], ) -> Result<()> { let msg = format!("{}Compiling to Wasm...", emoji::CYCLONE); PBAR.info(&msg); diff --git a/src/command/build.rs b/src/command/build.rs index a8c9e9fa..f1902042 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -12,12 +12,12 @@ use crate::manifest; use crate::readme; use crate::wasm_opt; use crate::PBAR; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Error, Result}; use binary_install::Cache; use log::info; -use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::PathBuf; +use std::str::FromStr; use std::time::Instant; use structopt::clap::AppSettings; @@ -37,7 +37,7 @@ pub struct Build { pub out_name: Option, pub bindgen: Option, pub cache: Cache, - pub extra_options: Vec, + pub extra_options: Vec, } /// What sort of output we're going to be generating and flags we're invoking @@ -81,23 +81,16 @@ impl fmt::Display for Target { } } -impl Target { - /// Converts from `OsStr` - pub fn parse(s: &OsStr) -> Result { - if s == "bundler" || s == "browser" { - Ok(Target::Bundler) - } else if s == "web" { - Ok(Target::Web) - } else if s == "nodejs" { - Ok(Target::Nodejs) - } else if s == "no-modules" { - Ok(Target::NoModules) - } else if s == "deno" { - Ok(Target::Deno) - } else { - let mut err = OsString::from("Unknown target: "); - err.push(s); - Err(err) +impl FromStr for Target { + type Err = Error; + fn from_str(s: &str) -> Result { + match s { + "bundler" | "browser" => Ok(Target::Bundler), + "web" => Ok(Target::Web), + "nodejs" => Ok(Target::Nodejs), + "no-modules" => Ok(Target::NoModules), + "deno" => Ok(Target::Deno), + _ => bail!("Unknown target: {}", s), } } } @@ -132,7 +125,7 @@ pub struct BuildOptions { #[structopt(long = "scope", short = "s")] pub scope: Option, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, @@ -149,7 +142,7 @@ pub struct BuildOptions { /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[structopt(long = "target", short = "t", default_value = "bundler", parse(try_from_os_str = Target::parse))] + #[structopt(long = "target", short = "t", default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, @@ -172,15 +165,15 @@ pub struct BuildOptions { #[structopt(long = "out-dir", short = "d", default_value = "pkg")] /// Sets the output directory with a relative path. - pub out_dir: OsString, + pub out_dir: String, #[structopt(long = "out-name")] /// Sets the output file names. Defaults to package name. pub out_name: Option, - #[structopt(allow_hyphen_values = true, parse(from_os_str))] + #[structopt(allow_hyphen_values = true)] /// List of extra options to pass to `cargo build` - pub extra_options: Vec, + pub extra_options: Vec, } impl Default for BuildOptions { @@ -197,7 +190,7 @@ impl Default for BuildOptions { dev: false, release: false, profiling: false, - out_dir: OsString::new(), + out_dir: String::new(), out_name: None, extra_options: Vec::new(), } @@ -212,7 +205,9 @@ impl Build { if let Some(path) = &build_opts.path { if path.to_string_lossy().starts_with("--") { let path = build_opts.path.take().unwrap(); - build_opts.extra_options.insert(0, path.into()); + build_opts + .extra_options + .insert(0, path.to_string_lossy().into_owned()); } } let crate_path = get_crate_path(build_opts.path)?; diff --git a/src/command/generate.rs b/src/command/generate.rs index 58cc73a7..609a0b53 100644 --- a/src/command/generate.rs +++ b/src/command/generate.rs @@ -1,5 +1,3 @@ -use std::ffi::OsString; - use crate::cache; use crate::generate; use crate::install::{self, Tool}; @@ -9,7 +7,7 @@ use log::info; /// Executes the 'cargo-generate' command in the current directory /// which generates a new rustwasm project from a template. -pub fn generate(template: OsString, name: OsString, install_permitted: bool) -> Result<()> { +pub fn generate(template: String, name: String, install_permitted: bool) -> Result<()> { info!("Generating a new rustwasm project..."); let download = install::download_prebuilt_or_cargo_install( Tool::CargoGenerate, @@ -19,7 +17,7 @@ pub fn generate(template: OsString, name: OsString, install_permitted: bool) -> )?; generate::generate(&template, &name, &download)?; - let msg = format!("🐑 Generated new project at /{}", name.to_string_lossy()); + let msg = format!("🐑 Generated new project at /{}", name); PBAR.info(&msg); Ok(()) } diff --git a/src/command/login.rs b/src/command/login.rs index 933007f2..817ae168 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -1,25 +1,20 @@ -use std::ffi::OsString; - use crate::npm; use crate::PBAR; use anyhow::Result; use log::info; pub fn login( - registry: Option, - scope: &Option, + registry: Option, + scope: &Option, always_auth: bool, - auth_type: &Option, + auth_type: &Option, ) -> Result<()> { - let registry = registry.unwrap_or_else(|| npm::DEFAULT_NPM_REGISTRY.to_string().into()); + let registry = registry.unwrap_or_else(|| npm::DEFAULT_NPM_REGISTRY.to_string()); info!("Logging in to npm..."); info!( "Scope: {:?} Registry: {}, Always Auth: {}, Auth Type: {:?}.", - &scope, - ®istry.to_string_lossy(), - always_auth, - &auth_type + &scope, ®istry, always_auth, &auth_type ); info!("npm info located in the npm debug log"); npm::npm_login(®istry, &scope, always_auth, &auth_type)?; diff --git a/src/command/mod.rs b/src/command/mod.rs index ffa7e1ba..190e8738 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -19,7 +19,6 @@ use self::test::{Test, TestOptions}; use crate::install::InstallMode; use anyhow::Result; use log::info; -use std::ffi::OsString; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. @@ -41,17 +40,15 @@ pub enum Command { /// 🐑 create a new project with a template Generate { /// The name of the project - #[structopt(parse(from_os_str))] - name: OsString, + name: String, /// The URL to the template #[structopt( long = "template", short = "temp", - default_value = "https://github.com/rustwasm/wasm-pack-template", - parse(from_os_str) + default_value = "https://github.com/rustwasm/wasm-pack-template" )] - template: OsString, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + template: String, + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, @@ -59,14 +56,9 @@ pub enum Command { #[structopt(name = "publish")] /// 🎆 pack up your npm package and publish! Publish { - #[structopt( - long = "target", - short = "t", - default_value = "bundler", - parse(from_os_str) - )] + #[structopt(long = "target", short = "t", default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] - target: OsString, + target: String, /// The access level for the package to be published #[structopt(long = "access", short = "a")] @@ -75,7 +67,7 @@ pub enum Command { /// The distribution tag being used for publishing. /// See https://docs.npmjs.com/cli/dist-tag #[structopt(long = "tag")] - tag: Option, + tag: Option, /// The path to the Rust crate. If not set, searches up the path from the current directory. #[structopt(parse(from_os_str))] @@ -91,13 +83,13 @@ pub enum Command { /// specified, this registry will only be used for packages with that /// scope. scope defaults to the scope of the project directory you're /// currently in, if any. - registry: Option, + registry: Option, #[structopt(long = "scope", short = "s")] /// Default: none. /// If specified, the user and login credentials given will be /// associated with the specified scope. - scope: Option, + scope: Option, #[structopt(long = "always-auth", short = "a")] /// If specified, save configuration indicating that all requests to the @@ -111,7 +103,7 @@ pub enum Command { /// What authentication strategy to use with adduser/login. Some npm /// registries (for example, npmE) might support alternative auth /// strategies besides classic username/password entry in legacy npm. - auth_type: Option, + auth_type: Option, }, #[structopt(name = "test")] diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 70bce2c7..92c6f3f7 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -6,19 +6,19 @@ use crate::command::build::{Build, BuildOptions, Target}; use crate::command::utils::{find_pkg_directory, get_crate_path}; use crate::npm; use crate::PBAR; -use anyhow::{anyhow, bail, Error, Result}; +use anyhow::{anyhow, bail, Result}; use dialoguer::{Confirm, Input, Select}; use log::info; -use std::ffi::{OsStr, OsString}; use std::path::PathBuf; +use std::str::FromStr; /// Creates a tarball from a 'pkg' directory /// and publishes it to the NPM registry pub fn publish( - _target: &OsStr, + _target: &str, path: Option, access: Option, - tag: Option, + tag: Option, ) -> Result<()> { let crate_path = get_crate_path(path)?; @@ -39,15 +39,14 @@ pub fn publish( .default(".".to_string()) .show_default(false) .interact()?; - let out_dir = OsString::from(format!("{}/pkg", out_dir)); + let out_dir = format!("{}/pkg", out_dir); let target = Select::new() .with_prompt("target[default: bundler]") .items(&["bundler", "nodejs", "web", "no-modules"]) .default(0) .interact()? .to_string(); - let target = Target::parse(OsStr::new(&target)) - .map_err(|err| Error::msg(err.to_string_lossy().into_owned()))?; + let target = Target::from_str(&target)?; let build_opts = BuildOptions { path: Some(crate_path.clone()), target, diff --git a/src/command/test.rs b/src/command/test.rs index 616f99ad..d7b66424 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -71,7 +71,7 @@ pub struct TestOptions { /// UI or windows. pub headless: bool, - #[structopt(long = "mode", short = "m", default_value = "normal", parse(try_from_os_str = InstallMode::parse))] + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, diff --git a/src/generate.rs b/src/generate.rs index 5ea920bd..660f123b 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -4,12 +4,11 @@ use crate::child; use crate::emoji; use crate::install::{self, Tool}; use anyhow::{Context, Result}; -use std::ffi::OsStr; use std::process::Command; /// Run `cargo generate` in the current directory to create a new /// project from a template -pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status) -> Result<()> { +pub fn generate(template: &str, name: &str, install_status: &install::Status) -> Result<()> { let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); @@ -20,7 +19,7 @@ pub fn generate(template: &OsStr, name: &OsStr, install_status: &install::Status println!( "{} Generating a new rustwasm project with name '{}'...", emoji::SHEEP, - name.to_string_lossy() + name ); child::run(cmd, "cargo-generate").context("Running cargo-generate")?; Ok(()) diff --git a/src/install/mode.rs b/src/install/mode.rs index b017d9a3..a55153de 100644 --- a/src/install/mode.rs +++ b/src/install/mode.rs @@ -1,4 +1,5 @@ -use std::ffi::{OsStr, OsString}; +use anyhow::{bail, Error, Result}; +use std::str::FromStr; /// The `InstallMode` determines which mode of initialization we are running, and /// what install steps we perform. @@ -19,22 +20,19 @@ impl Default for InstallMode { } } -impl InstallMode { - /// Converts from `OsStr` - pub fn parse(s: &OsStr) -> Result { - if s == "no-install" { - Ok(InstallMode::Noinstall) - } else if s == "normal" { - Ok(InstallMode::Normal) - } else if s == "force" { - Ok(InstallMode::Force) - } else { - let mut err = OsString::from("Unknown build mode: "); - err.push(s); - Err(err) +impl FromStr for InstallMode { + type Err = Error; + fn from_str(s: &str) -> Result { + match s { + "no-install" => Ok(InstallMode::Noinstall), + "normal" => Ok(InstallMode::Normal), + "force" => Ok(InstallMode::Force), + _ => bail!("Unknown build mode: {}", s), } } +} +impl InstallMode { /// Determines if installation is permitted during a function call based on --mode flag pub fn install_permitted(self) -> bool { match self { diff --git a/src/npm.rs b/src/npm.rs index 11d2b5f3..7c4f08b0 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -1,7 +1,5 @@ //! Functionality related to publishing to npm. -use std::ffi::{OsStr, OsString}; - use crate::child; use crate::command::publish::access::Access; use anyhow::{bail, Context, Result}; @@ -19,7 +17,7 @@ pub fn npm_pack(path: &str) -> Result<()> { } /// Run the `npm publish` command. -pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { +pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); match access { Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), @@ -35,39 +33,34 @@ pub fn npm_publish(path: &str, access: Option, tag: Option) -> /// Run the `npm login` command. pub fn npm_login( - registry: &OsStr, - scope: &Option, + registry: &str, + scope: &Option, always_auth: bool, - auth_type: &Option, + auth_type: &Option, ) -> Result<()> { - // Interactively ask user for npm login info. - // (child::run does not support interactive input) - let mut cmd = child::new_command("npm"); - - cmd.arg("login").arg(build_arg("--registry=", registry)); + let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; if let Some(scope) = scope { - cmd.arg(build_arg("--scope=", &scope)); + args.push(format!("--scope={}", scope)); } if always_auth { - cmd.arg("--always_auth"); + args.push("--always_auth".to_string()); } if let Some(auth_type) = auth_type { - cmd.arg(build_arg("--auth_type=", &auth_type)); + args.push(format!("--auth_type={}", auth_type)); } + // Interactively ask user for npm login info. + // (child::run does not support interactive input) + let mut cmd = child::new_command("npm"); + cmd.args(args); + info!("Running {:?}", cmd); if cmd.status()?.success() { Ok(()) } else { - bail!("Login to registry {} failed", registry.to_string_lossy()) + bail!("Login to registry {} failed", registry) } } - -fn build_arg(prefix: &'static str, value: &OsStr) -> OsString { - let mut s = OsString::from(prefix); - s.push(value); - s -} From 9ad11fdb06771e4cdc40652d4cbfa4be197bff08 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:06 +0000 Subject: [PATCH 55/85] Revert "Optimize version check" This reverts commit 9d375922b18edc4b8832c1f6a7d590aada2147a2. --- src/build/mod.rs | 6 +- src/main.rs | 4 +- src/manifest/mod.rs | 210 ++++++++++++++++++++++-------------------- tests/all/manifest.rs | 5 - 4 files changed, 113 insertions(+), 112 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 5fb9e375..78e89b60 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -3,7 +3,7 @@ use crate::child; use crate::command::build::BuildProfile; use crate::emoji; -use crate::manifest; +use crate::manifest::Crate; use crate::PBAR; use anyhow::{bail, Context, Result}; use std::path::Path; @@ -19,7 +19,7 @@ pub struct WasmPackVersion { pub local: &'static str, /// The latest version of wasm-pack that's released at /// crates.io. - pub latest: Vec, + pub latest: String, } /// Ensure that `rustc` is present and that it is >= 1.30.0 @@ -62,7 +62,7 @@ fn rustc_minor_version() -> Option { /// Checks and returns local and latest versions of wasm-pack pub fn check_wasm_pack_versions() -> Result { match wasm_pack_local_version() { - Some(local) => Ok(WasmPackVersion {local, latest: manifest::return_wasm_pack_latest_version()?.unwrap_or_else(|| Vec::new())}), + Some(local) => Ok(WasmPackVersion {local, latest: Crate::return_wasm_pack_latest_version()?.unwrap_or_else(|| "".to_string())}), None => bail!("We can't figure out what your wasm-pack version is, make sure the installation path is correct.") } } diff --git a/src/main.rs b/src/main.rs index 72739809..c77f845d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ fn background_check_for_updates() -> mpsc::Receiver> { if let Ok(wasm_pack_version) = wasm_pack_version { if !wasm_pack_version.local.is_empty() && !wasm_pack_version.latest.is_empty() - && wasm_pack_version.local.as_bytes() != wasm_pack_version.latest + && wasm_pack_version.local != wasm_pack_version.latest { let _ = sender.send(Ok(wasm_pack_version)); } @@ -93,7 +93,7 @@ fn run() -> Result<()> { match wasm_pack_version { Ok(wasm_pack_version) => PBAR.warn(&format!("There's a newer version of wasm-pack available, the new version is: {}, you are using: {}. \ - To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", String::from_utf8_lossy(&wasm_pack_version.latest), wasm_pack_version.local)), + To update, navigate to: https://rustwasm.github.io/wasm-pack/installer/", wasm_pack_version.latest, wasm_pack_version.local)), Err(err) => PBAR.warn(&format!("{}", err)) } } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index b0814eb6..56c635f1 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -129,132 +129,138 @@ impl easy::Handler for Collector { } } -/// Returns latest wasm-pack version -pub fn return_wasm_pack_latest_version() -> Result>> { - let current_time = chrono::offset::Local::now(); - let old_metadata_file = return_wasm_pack_file(); - - match old_metadata_file { - Some(ref file_contents) => { - let last_updated = return_stamp_file_value(&file_contents, b"created") - .and_then(|t| DateTime::parse_from_str(&String::from_utf8_lossy(t), "%+").ok()); - - last_updated - .map(|last_updated| { - if current_time.signed_duration_since(last_updated).num_hours() > 24 { - return_api_call_result(current_time).map(Some) - } else { - Ok(return_stamp_file_value(&file_contents, b"version") - .map(|f| f.to_owned())) - } - }) - .unwrap_or_else(|| Ok(None)) +/// Struct for storing information received from crates.io +#[derive(Deserialize, Debug)] +pub struct Crate { + #[serde(rename = "crate")] + crt: CrateInformation, +} + +#[derive(Deserialize, Debug)] +struct CrateInformation { + max_version: String, +} + +impl Crate { + /// Returns latest wasm-pack version + pub fn return_wasm_pack_latest_version() -> Result> { + let current_time = chrono::offset::Local::now(); + let old_metadata_file = Self::return_wasm_pack_file(); + + match old_metadata_file { + Some(ref file_contents) => { + let last_updated = Self::return_stamp_file_value(&file_contents, "created") + .and_then(|t| DateTime::parse_from_str(t.as_str(), "%+").ok()); + + last_updated + .map(|last_updated| { + if current_time.signed_duration_since(last_updated).num_hours() > 24 { + Self::return_api_call_result(current_time).map(Some) + } else { + Ok(Self::return_stamp_file_value(&file_contents, "version")) + } + }) + .unwrap_or_else(|| Ok(None)) + } + None => Self::return_api_call_result(current_time).map(Some), } - None => return_api_call_result(current_time).map(Some), } -} -fn return_api_call_result(current_time: DateTime) -> Result> { - let version = return_latest_wasm_pack_version(); + fn return_api_call_result(current_time: DateTime) -> Result { + let version = Self::return_latest_wasm_pack_version(); - // We always override the stamp file with the current time because we don't - // want to hit the API all the time if it fails. It should follow the same - // "policy" as the success. This means that the 24 hours rate limiting - // will be active regardless if the check succeeded or failed. - match version { - Ok(ref version) => override_stamp_file(current_time, Some(&version)).ok(), - Err(_) => override_stamp_file(current_time, None).ok(), - }; + // We always override the stamp file with the current time because we don't + // want to hit the API all the time if it fails. It should follow the same + // "policy" as the success. This means that the 24 hours rate limiting + // will be active regardless if the check succeeded or failed. + match version { + Ok(ref version) => Self::override_stamp_file(current_time, Some(&version)).ok(), + Err(_) => Self::override_stamp_file(current_time, None).ok(), + }; - version -} + version + } -fn override_stamp_file( - current_time: DateTime, - version: Option<&[u8]>, -) -> Result<()> { - let path = env::current_exe()?; + fn override_stamp_file( + current_time: DateTime, + version: Option<&str>, + ) -> Result<()> { + let path = env::current_exe()?; - let mut file = fs::OpenOptions::new() - .read(true) - .write(true) - .append(true) - .create(true) - .open(path.with_extension("stamp"))?; + let mut file = fs::OpenOptions::new() + .read(true) + .write(true) + .append(true) + .create(true) + .open(path.with_extension("stamp"))?; - file.set_len(0)?; + file.set_len(0)?; - write!(file, "created {:?}", current_time)?; + write!(file, "created {:?}", current_time)?; - if let Some(version) = version { - write!(file, "\nversion ")?; - file.write(version)?; - } + if let Some(version) = version { + write!(file, "\nversion {}", version)?; + } - Ok(()) -} + Ok(()) + } -/// Return stamp file where metadata is stored. -fn return_wasm_pack_file() -> Option> { - if let Ok(path) = env::current_exe() { - if let Ok(file) = fs::read(path.with_extension("stamp")) { - return Some(file); + /// Return stamp file where metadata is stored. + fn return_wasm_pack_file() -> Option { + if let Ok(path) = env::current_exe() { + if let Ok(file) = fs::read_to_string(path.with_extension("stamp")) { + return Some(file); + } } + None } - None -} -/// Returns wasm-pack latest version (if it's received) by executing check_wasm_pack_latest_version function. -fn return_latest_wasm_pack_version() -> Result> { - check_wasm_pack_latest_version() -} + /// Returns wasm-pack latest version (if it's received) by executing check_wasm_pack_latest_version function. + fn return_latest_wasm_pack_version() -> Result { + Self::check_wasm_pack_latest_version().map(|crt| crt.crt.max_version) + } -/// Read the stamp file and return value assigned to a certain key. -fn return_stamp_file_value<'a>(file: &'a [u8], word: &[u8]) -> Option<&'a [u8]> { - file.split(|&byte| byte == b'\n') - .find_map(|line| line.strip_prefix(word)) - .and_then(|l| l.get(1..)) -} + /// Read the stamp file and return value assigned to a certain key. + fn return_stamp_file_value(file: &str, word: &str) -> Option { + let created = file + .lines() + .find(|line| line.starts_with(word)) + .and_then(|l| l.split_whitespace().nth(1)); -/// Call to the crates.io api and return the latest version of `wasm-pack` -fn check_wasm_pack_latest_version() -> Result> { - let url = "https://crates.io/api/v1/crates/wasm-pack"; + created.map(|s| s.to_string()) + } - let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); + /// Call to the crates.io api and return the latest version of `wasm-pack` + fn check_wasm_pack_latest_version() -> Result { + let url = "https://crates.io/api/v1/crates/wasm-pack"; - easy.useragent(&format!( - "wasm-pack/{} ({})", - WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), - WASM_PACK_REPO_URL - ))?; + let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); - easy.url(url)?; - easy.get(true)?; - easy.perform()?; + easy.useragent(&format!( + "wasm-pack/{} ({})", + WASM_PACK_VERSION.unwrap_or_else(|| "unknown"), + WASM_PACK_REPO_URL + ))?; - let status_code = easy.response_code()?; + easy.url(url)?; + easy.get(true)?; + easy.perform()?; - if 200 <= status_code && status_code < 300 { - let contents = easy.get_ref(); - let version_bytes = get_max_version(&contents.0) - .context("max_version field not found when checking for newer wasm-pack version")?; + let status_code = easy.response_code()?; - Ok(version_bytes.to_owned()) - } else { - bail!( - "Received a bad HTTP status code ({}) when checking for newer wasm-pack version at: {}", - status_code, - url - ) - } -} + if 200 <= status_code && status_code < 300 { + let contents = easy.get_ref(); + let result = String::from_utf8_lossy(&contents.0); -/// Returns the `max_version` field of given JSON from crates.io API -pub fn get_max_version(crate_info: &[u8]) -> Option<&[u8]> { - crate_info - .split(|&byte| byte == b',') - .find_map(|slice| slice.strip_prefix(b"\"max_version\":\"")) - .and_then(|slice| slice.split(|&byte| byte == b'"').next()) + Ok(serde_json::from_str(result.into_owned().as_str())?) + } else { + bail!( + "Received a bad HTTP status code ({}) when checking for newer wasm-pack version at: {}", + status_code, + url + ) + } + } } #[derive(Clone, Deserialize)] diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index e46b02c9..abf0e759 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -641,8 +641,3 @@ fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { let crate_data = manifest::CrateData::new(&path, None); assert!(crate_data.is_err()); } - -#[test] -fn get_max_version_works() { - assert_eq!(Some(&b"0.11.0"[..]), manifest::get_max_version(br#"{"categories":[{"category":"WebAssembly","crates_cnt":1319,"created_at":"2018-03-01T16:00:11.531177+00:00","description":"Crates for use when targeting WebAssembly, or for manipulating WebAssembly.","id":"wasm","slug":"wasm"}],"crate":{"badges":[],"categories":["wasm"],"created_at":"2018-03-16T08:37:12.179096+00:00","description":" your favorite rust -> wasm workflow tool!","documentation":"https://rustwasm.github.io/wasm-pack/","downloads":572316,"exact_match":false,"homepage":null,"id":"wasm-pack","keywords":[],"links":{"owner_team":"/api/v1/crates/wasm-pack/owner_team","owner_user":"/api/v1/crates/wasm-pack/owner_user","owners":"/api/v1/crates/wasm-pack/owners","reverse_dependencies":"/api/v1/crates/wasm-pack/reverse_dependencies","version_downloads":"/api/v1/crates/wasm-pack/downloads","versions":null},"max_stable_version":"0.11.0","max_version":"0.11.0","name":"wasm-pack","newest_version":"0.11.0","recent_downloads":57531,"repository":"https://github.com/rustwasm/wasm-pack.git","updated_at":"2023-03-19T18:34:09.441463+00:00","versions":[753886,566082,469444,421933,396623,210640,208425,143211,142828,139463,128362,111637,109520,101086,99719,97024,95449,94906,90427,85070]},"keywords":[]}]}"#)) -} From 1f3b2a418698683821fbb5833531656dd0d6759d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:08 +0000 Subject: [PATCH 56/85] Revert "Use &'static str for local version" This reverts commit 08a66e68a4a5f47d9a1fddf78844e8fa0223d1d4. --- src/build/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 78e89b60..691ec490 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -16,7 +16,7 @@ pub mod wasm_target; /// wasm-pack version with the latest on crates.io. pub struct WasmPackVersion { /// The currently installed wasm-pack version. - pub local: &'static str, + pub local: String, /// The latest version of wasm-pack that's released at /// crates.io. pub latest: String, @@ -67,9 +67,9 @@ pub fn check_wasm_pack_versions() -> Result { } } -fn wasm_pack_local_version() -> Option<&'static str> { +fn wasm_pack_local_version() -> Option { let output = env!("CARGO_PKG_VERSION"); - Some(output) + Some(output.to_string()) } /// Run `cargo build` targetting `wasm32-unknown-unknown`. From 25e638d698e1a53a912f910d737453b4e6ad516c Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:54:10 +0000 Subject: [PATCH 57/85] Revert "Use Vec::with_capacity in check_wasm_pack_lastet_version" This reverts commit 8ac82f26c736055442cf454115a8047625f0e171. --- src/manifest/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 56c635f1..54f77403 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -234,7 +234,7 @@ impl Crate { fn check_wasm_pack_latest_version() -> Result { let url = "https://crates.io/api/v1/crates/wasm-pack"; - let mut easy = easy::Easy2::new(Collector(Vec::with_capacity(32768))); + let mut easy = easy::Easy2::new(Collector(Vec::new())); easy.useragent(&format!( "wasm-pack/{} ({})", From e9b96c9341b2ff0a08fb2f22cdd7363a87be965d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 13:56:25 +0000 Subject: [PATCH 58/85] Revert "Optimize get_process_steps" This reverts commit 4f29034fb67af1e7058b17cdd6e2ab4eb21e5d25. --- src/command/build.rs | 60 +++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index f1902042..75374ad1 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -274,43 +274,39 @@ impl Build { Ok(()) } - fn get_process_steps(mode: InstallMode) -> impl Iterator { + fn get_process_steps(mode: InstallMode) -> Vec<(&'static str, BuildStep)> { macro_rules! steps { ($($name:ident),+) => { { - let steps: &'static [(_, BuildStep)] = &[ - $((stringify!($name), Build::$name),)* - ]; - steps - } - }; + let mut steps: Vec<(&'static str, BuildStep)> = Vec::new(); + $(steps.push((stringify!($name), Build::$name));)* + steps + } + }; ($($name:ident,)*) => (steps![$($name),*]) } - [ - match &mode { - InstallMode::Force => &[], - _ => { - steps![ - step_check_rustc_version, - step_check_crate_config, - step_check_for_wasm_target, - ] - } - }, - steps![ - step_build_wasm, - step_create_dir, - step_copy_readme, - step_copy_license, - step_install_wasm_bindgen, - step_run_wasm_bindgen, - step_run_wasm_opt, - step_create_json, - ], - ] - .into_iter() - .flatten() - .copied() + let mut steps = Vec::new(); + match &mode { + InstallMode::Force => {} + _ => { + steps.extend(steps![ + step_check_rustc_version, + step_check_crate_config, + step_check_for_wasm_target, + ]); + } + } + steps.extend(steps![ + step_build_wasm, + step_create_dir, + step_copy_readme, + step_copy_license, + step_install_wasm_bindgen, + step_run_wasm_bindgen, + step_run_wasm_opt, + step_create_json, + ]); + steps } fn step_check_rustc_version(&mut self) -> Result<()> { From 83763368cd544ea51e74606a6f7c134caff2c1f9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 14:43:08 +0000 Subject: [PATCH 59/85] Multithreaded checks --- src/command/build.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 77a9eae9..b47dd4e2 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -296,11 +296,7 @@ impl Build { match &mode { InstallMode::Force => {} _ => { - steps.extend(steps![ - step_check_rustc_version, - step_check_crate_config, - step_check_for_wasm_target, - ]); + steps.extend(steps![step_run_checks,]); } } @@ -323,7 +319,20 @@ impl Build { steps } - fn step_check_rustc_version(&mut self) -> Result<()> { + fn step_run_checks(&mut self) -> Result<()> { + std::thread::scope(|s| { + for handle in [ + s.spawn(|| self.step_check_rustc_version()), + s.spawn(|| self.step_check_crate_config()), + s.spawn(|| self.step_check_for_wasm_target()), + ] { + handle.join().unwrap()?; + } + Ok(()) + }) + } + + fn step_check_rustc_version(&self) -> Result<()> { info!("Checking rustc version..."); let version = build::check_rustc_version()?; let msg = format!("rustc version is {}.", version); @@ -331,14 +340,14 @@ impl Build { Ok(()) } - fn step_check_crate_config(&mut self) -> Result<()> { + fn step_check_crate_config(&self) -> Result<()> { info!("Checking crate configuration..."); self.crate_data.check_crate_config()?; info!("Crate is correctly configured."); Ok(()) } - fn step_check_for_wasm_target(&mut self) -> Result<()> { + fn step_check_for_wasm_target(&self) -> Result<()> { info!("Checking for wasm-target..."); build::wasm_target::check_for_wasm32_target()?; info!("Checking for wasm-target was successful."); From 86fd962deb64207379890e0c9952e40ecce107fa Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 2 Jun 2023 15:32:56 +0000 Subject: [PATCH 60/85] Optimize lockfile --- src/lockfile.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lockfile.rs b/src/lockfile.rs index f4a68eac..ae935934 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -13,6 +13,7 @@ use toml; /// This struct represents the contents of `Cargo.lock`. #[derive(Clone, Debug, Deserialize)] pub struct Lockfile { + #[serde(deserialize_with = "deserialize_package_list")] package: Vec, } @@ -23,6 +24,37 @@ struct Package { version: String, } +/// Deserializer that only includes packages with a name starting with "wasm-bindgen" +fn deserialize_package_list<'de, D>(deserializer: D) -> std::result::Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + deserializer.deserialize_seq(PackagesVisitor) +} + +struct PackagesVisitor; + +impl<'de> serde::de::Visitor<'de> for PackagesVisitor { + type Value = Vec; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("a sequence") + } + + fn visit_seq(self, mut seq: A) -> std::result::Result + where + A: serde::de::SeqAccess<'de>, + { + let mut result = Vec::new(); + while let Some(package) = seq.next_element::()? { + if package.name.starts_with("wasm-bindgen") { + result.push(package); + } + } + Ok(result) + } +} + impl Lockfile { /// Read the `Cargo.lock` file for the crate at the given path. pub fn new(crate_data: &CrateData) -> Result { From b6d095c73f9edad53a9047031481bc1cf7bc34e6 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 3 Jun 2023 22:30:46 +0000 Subject: [PATCH 61/85] Add dhat heap profiler --- .gitignore | 1 + Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +++ src/main.rs | 7 +++++++ 4 files changed, 60 insertions(+) diff --git a/.gitignore b/.gitignore index b0b6ed39..9918b2c5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ tests/bin /build-installer docs/book docs/installer +dhat-*.json .idea diff --git a/Cargo.lock b/Cargo.lock index 563ef43f..1372beba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -451,6 +451,22 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "dhat" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2aaf837aaf456f6706cb46386ba8dffd4013a757e36f4ea05c20dd46b209a3" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot", + "rustc-hash", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "dialoguer" version = "0.10.4" @@ -975,6 +991,16 @@ dependencies = [ "adler", ] +[[package]] +name = "mintex" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7c5ba1c3b5a23418d7bbf98c71c3d4946a0125002129231da8d6b723d559cb" +dependencies = [ + "once_cell", + "sys-info", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -1267,6 +1293,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustix" version = "0.37.19" @@ -1545,6 +1577,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sys-info" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "tar" version = "0.4.38" @@ -1604,6 +1646,12 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "time" version = "0.1.45" @@ -1892,6 +1940,7 @@ dependencies = [ "cargo_metadata", "chrono", "console", + "dhat", "dialoguer", "env_logger", "glob", diff --git a/Cargo.toml b/Cargo.toml index 0268d36c..1fa675cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ binary-install = "0.1.0" cargo_metadata = "0.15.2" chrono = "0.4.23" console = "0.15.5" +dhat = { version = "0.3.2", optional = true } dialoguer = "0.10.3" env_logger = { version = "0.10.0", default-features = false } glob = "0.3.1" @@ -43,3 +44,5 @@ predicates = "2.1.5" serial_test = "1.0.0" tempfile = "3.3.0" +[features] +dhat-heap = ["dep:dhat"] diff --git a/src/main.rs b/src/main.rs index c77f845d..3151d818 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,14 @@ fn background_check_for_updates() -> mpsc::Receiver> { receiver } +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + env_logger::init(); setup_panic_hooks(); From 32c624801bd99daa05c32b94eb0d459513a61862 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sun, 4 Jun 2023 15:31:32 +0000 Subject: [PATCH 62/85] Add FixtureBuilder for parallel file writes --- tests/all/build.rs | 48 ++++---- tests/all/generate.rs | 4 +- tests/all/license.rs | 10 +- tests/all/lockfile.rs | 16 +-- tests/all/log_level.rs | 12 +- tests/all/manifest.rs | 85 ++++++++------- tests/all/readme.rs | 4 +- tests/all/test.rs | 45 ++++---- tests/all/utils/fixture.rs | 217 ++++++++++++++++++------------------- tests/all/wasm_opt.rs | 38 ++++--- tests/all/webdriver.rs | 4 +- 11 files changed, 249 insertions(+), 234 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index 4b87e4fb..25e01239 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -5,7 +5,7 @@ use std::path::Path; #[test] fn build_in_non_crate_directory_doesnt_panic() { - let fixture = utils::fixture::not_a_crate(); + let fixture = utils::fixture::not_a_crate().build(); fixture .wasm_pack() .arg("build") @@ -17,13 +17,13 @@ fn build_in_non_crate_directory_doesnt_panic() { #[test] fn it_should_build_js_hello_world_example() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture.wasm_pack().arg("build").assert().success(); } #[test] fn it_should_not_make_a_pkg_json_if_passed_no_pack() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture .wasm_pack() .arg("build") @@ -39,8 +39,7 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() { #[test] fn it_should_build_crates_in_a_workspace() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" @@ -76,7 +75,8 @@ fn it_should_build_crates_in_a_workspace() { pub fn hello() -> u32 { 42 } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); fixture .wasm_pack() .current_dir(&fixture.path.join("blah")) @@ -87,8 +87,7 @@ fn it_should_build_crates_in_a_workspace() { #[test] fn renamed_crate_name_works() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -116,14 +115,14 @@ fn renamed_crate_name_works() { pub fn one() -> u32 { 1 } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); fixture.wasm_pack().arg("build").assert().success(); } #[test] fn dash_dash_web_target_has_error_on_old_bindgen() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -151,7 +150,8 @@ fn dash_dash_web_target_has_error_on_old_bindgen() { pub fn one() -> u32 { 1 } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); let cmd = fixture .wasm_pack() .arg("build") @@ -170,7 +170,7 @@ fn dash_dash_web_target_has_error_on_old_bindgen() { #[test] fn it_should_build_nested_project_with_transitive_dependencies() { - let fixture = utils::fixture::transitive_dependencies(); + let fixture = utils::fixture::transitive_dependencies().build(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -182,7 +182,7 @@ fn it_should_build_nested_project_with_transitive_dependencies() { #[test] fn build_different_profiles() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture.install_local_wasm_bindgen(); for profile in ["--dev", "--debug", "--profiling", "--release"] @@ -201,8 +201,7 @@ fn build_different_profiles() { #[test] fn build_with_and_without_wasm_bindgen_debug() { for debug in [true, false].iter().cloned() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -251,7 +250,8 @@ fn build_with_and_without_wasm_bindgen_debug() { } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -275,7 +275,7 @@ fn build_with_and_without_wasm_bindgen_debug() { #[test] fn build_with_arbitrary_cargo_options() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -287,7 +287,7 @@ fn build_with_arbitrary_cargo_options() { #[test] fn build_no_install() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -300,7 +300,7 @@ fn build_no_install() { #[test] fn build_force() { - let fixture = utils::fixture::js_hello_world(); + let fixture = utils::fixture::js_hello_world().build(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -313,7 +313,7 @@ fn build_force() { #[test] fn build_from_new() { - let fixture = utils::fixture::not_a_crate(); + let fixture = utils::fixture::not_a_crate().build(); let name = "generated-project"; fixture.wasm_pack().arg("new").arg(name).assert().success(); let project_location = fixture.path.join(&name); @@ -327,8 +327,7 @@ fn build_from_new() { #[test] fn build_crates_with_same_names() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "somename1/Cargo.toml", @@ -382,7 +381,8 @@ fn build_crates_with_same_names() { 0 } "#, - ); + ) + .build(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() diff --git a/tests/all/generate.rs b/tests/all/generate.rs index b2f695e1..32b1dd9b 100644 --- a/tests/all/generate.rs +++ b/tests/all/generate.rs @@ -3,14 +3,14 @@ use assert_cmd::prelude::*; #[test] fn new_with_no_name_errors() { - let fixture = utils::fixture::not_a_crate(); + let fixture = utils::fixture::not_a_crate().build(); fixture.install_local_cargo_generate(); fixture.wasm_pack().arg("new").assert().failure(); } #[test] fn new_with_name_succeeds() { - let fixture = utils::fixture::not_a_crate(); + let fixture = utils::fixture::not_a_crate().build(); fixture.install_local_cargo_generate(); fixture .wasm_pack() diff --git a/tests/all/license.rs b/tests/all/license.rs index ae0a6a7e..bb4b612a 100644 --- a/tests/all/license.rs +++ b/tests/all/license.rs @@ -9,7 +9,7 @@ use wasm_pack::manifest::CrateData; #[test] fn it_copies_a_license_default_path() { - let fixture = fixture::single_license(); + let fixture = fixture::single_license().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -34,7 +34,7 @@ fn it_copies_a_license_default_path() { #[test] fn it_copies_a_license_provided_path() { - let fixture = fixture::single_license(); + let fixture = fixture::single_license().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -57,7 +57,7 @@ fn it_copies_a_license_provided_path() { #[test] fn it_copies_all_licenses_default_path() { - let fixture = fixture::dual_license(); + let fixture = fixture::dual_license().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -92,7 +92,7 @@ fn it_copies_all_licenses_default_path() { #[test] fn it_copies_all_licenses_provided_path() { - let fixture = fixture::dual_license(); + let fixture = fixture::dual_license().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -128,7 +128,7 @@ fn it_copies_all_licenses_provided_path() { #[test] fn it_copies_a_non_standard_license_provided_path() { let license_file = "NON-STANDARD-LICENSE"; - let fixture = fixture::non_standard_license(license_file); + let fixture = fixture::non_standard_license(license_file).build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index 94b938b7..9b50835e 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -4,7 +4,7 @@ use wasm_pack::manifest::CrateData; #[test] fn it_gets_wasm_bindgen_version() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); let lock = Lockfile::new(&data).unwrap(); @@ -13,7 +13,7 @@ fn it_gets_wasm_bindgen_version() { #[test] fn it_gets_wasm_bindgen_test_version() { - let fixture = fixture::wbg_test_node(); + let fixture = fixture::wbg_test_node().build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); let lock = Lockfile::new(&data).unwrap(); @@ -22,8 +22,7 @@ fn it_gets_wasm_bindgen_test_version() { #[test] fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" @@ -58,7 +57,8 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[wasm_bindgen] pub fn hello() -> u32 { 42 } "#, - ); + ) + .build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("blah"), None).unwrap(); let lock = Lockfile::new(&data).unwrap(); @@ -67,8 +67,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[test] fn it_gets_wasm_bindgen_version_from_dependencies() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" @@ -126,7 +125,8 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { extern crate child; pub use child::*; "#, - ); + ) + .build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("parent"), None).unwrap(); let lock = Lockfile::new(&data).unwrap(); diff --git a/tests/all/log_level.rs b/tests/all/log_level.rs index ec95378a..f58f304d 100644 --- a/tests/all/log_level.rs +++ b/tests/all/log_level.rs @@ -28,9 +28,10 @@ fn matches_cargo() -> impl Predicate + PredicateReflection { #[test] fn quiet() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() + .build() .wasm_pack() .arg("--quiet") .arg("build") @@ -42,9 +43,10 @@ fn quiet() { #[test] fn log_level_info() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() + .build() .wasm_pack() .arg("--log-level") .arg("info") @@ -57,9 +59,10 @@ fn log_level_info() { #[test] fn log_level_warn() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() + .build() .wasm_pack() .arg("--log-level") .arg("warn") @@ -76,9 +79,10 @@ fn log_level_warn() { #[test] fn log_level_error() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() + .build() .wasm_pack() .arg("--log-level") .arg("error") diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index abf0e759..97cce656 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -17,7 +17,7 @@ fn it_gets_the_crate_name_default_path() { #[test] fn it_gets_the_crate_name_provided_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert_eq!(crate_data.crate_name(), "js_hello_world"); } @@ -40,7 +40,7 @@ fn it_gets_the_name_prefix_passed_from_cli() { #[test] fn it_checks_has_cdylib_default_path() { - let fixture = fixture::no_cdylib(); + let fixture = fixture::no_cdylib().build(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -49,7 +49,7 @@ fn it_checks_has_cdylib_default_path() { #[test] fn it_checks_has_cdylib_provided_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -58,14 +58,14 @@ fn it_checks_has_cdylib_provided_path() { #[test] fn it_checks_has_cdylib_wrong_crate_type() { - let fixture = fixture::bad_cargo_toml(); + let fixture = fixture::bad_cargo_toml().build(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert!(crate_data.check_crate_config().is_err()); } #[test] fn it_recognizes_a_map_during_depcheck() { - let fixture = fixture::serde_feature(); + let fixture = fixture::serde_feature().build(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -74,7 +74,7 @@ fn it_recognizes_a_map_during_depcheck() { #[test] fn it_creates_a_package_json_default_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -113,7 +113,7 @@ fn it_creates_a_package_json_default_path() { #[test] fn it_creates_a_package_json_provided_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -142,7 +142,7 @@ fn it_creates_a_package_json_provided_path() { #[test] fn it_creates_a_package_json_provided_path_with_scope() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -171,7 +171,7 @@ fn it_creates_a_package_json_provided_path_with_scope() { #[test] fn it_creates_a_pkg_json_with_correct_files_on_node() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -205,7 +205,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { #[test] fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -239,7 +239,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { #[test] fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, Some("index".to_owned())).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -271,7 +271,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() { #[test] fn it_creates_a_pkg_json_in_out_dir() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("./custom/out"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -286,7 +286,7 @@ fn it_creates_a_pkg_json_in_out_dir() { #[test] fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -319,7 +319,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { #[test] fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -367,7 +367,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() { #[test] fn it_errors_when_wasm_bindgen_is_not_declared() { - let fixture = fixture::bad_cargo_toml(); + let fixture = fixture::bad_cargo_toml().build(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert!(crate_data.check_crate_config().is_err()); } @@ -375,10 +375,11 @@ fn it_errors_when_wasm_bindgen_is_not_declared() { #[test] fn it_sets_homepage_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::Fixture::new(); - fixture.hello_world_src_lib().file( - "Cargo.toml", - r#" + let fixture = utils::fixture::FixtureBuilder::new() + .hello_world_src_lib() + .file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -397,7 +398,8 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { [dev-dependencies] wasm-bindgen-test = "=0.2" "#, - ); + ) + .build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -414,7 +416,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { ); // When 'homepage' is unavailable - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -430,10 +432,11 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { #[test] fn it_sets_keywords_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::Fixture::new(); - fixture.hello_world_src_lib().file( - "Cargo.toml", - r#" + let fixture = utils::fixture::FixtureBuilder::new() + .hello_world_src_lib() + .file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -452,7 +455,8 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { [dev-dependencies] wasm-bindgen-test = "=0.2" "#, - ); + ) + .build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -471,7 +475,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { ); // When 'keywords' is unavailable - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -486,7 +490,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { #[test] fn it_does_not_error_when_wasm_bindgen_is_declared() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -495,10 +499,12 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { #[test] fn configure_wasm_bindgen_debug_incorrectly_is_error() { - let fixture = utils::fixture::Fixture::new(); - fixture.readme().hello_world_src_lib().file( - "Cargo.toml", - r#" + let fixture = utils::fixture::FixtureBuilder::new() + .readme() + .hello_world_src_lib() + .file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -516,7 +522,8 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { [package.metadata.wasm-pack.profile.dev.wasm-bindgen] debug-js-glue = "not a boolean" "#, - ); + ) + .build(); fixture .wasm_pack() .arg("build") @@ -530,8 +537,7 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { #[test] fn parse_crate_data_returns_unused_keys_in_cargo_toml() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -556,7 +562,8 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { "#, ) .hello_world_src_lib() - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); fixture .wasm_pack() .arg("build") @@ -571,7 +578,7 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { #[test] fn it_lists_license_files_in_files_field_of_package_json() { - let fixture = fixture::dual_license(); + let fixture = fixture::dual_license().build(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -601,7 +608,7 @@ fn it_lists_license_files_in_files_field_of_package_json() { #[test] fn it_recurses_up_the_path_to_find_cargo_toml() { - let fixture = utils::fixture::Fixture::new(); + let fixture = utils::fixture::FixtureBuilder::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" @@ -623,7 +630,7 @@ fn it_recurses_up_the_path_to_find_cargo_toml() { #[test] fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { - let fixture = utils::fixture::Fixture::new(); + let fixture = utils::fixture::FixtureBuilder::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" diff --git a/tests/all/readme.rs b/tests/all/readme.rs index cefb01f0..370a84e1 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -8,7 +8,7 @@ use wasm_pack::readme; #[test] fn it_copies_a_readme_default_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); @@ -32,7 +32,7 @@ fn it_copies_a_readme_default_path() { #[test] fn it_copies_a_readme_provided_path() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); diff --git a/tests/all/test.rs b/tests/all/test.rs index c5bba4e6..8e33d6ad 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -5,7 +5,7 @@ use std::env; #[test] fn it_can_run_node_tests() { - let fixture = fixture::wbg_test_node(); + let fixture = fixture::wbg_test_node().build(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -18,7 +18,7 @@ fn it_can_run_node_tests() { #[test] fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { - let fixture = fixture::wbg_test_diff_versions(); + let fixture = fixture::wbg_test_diff_versions().build(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -38,7 +38,7 @@ fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { all(target_os = "windows", target_arch = "x86_64") ))] fn it_can_run_browser_tests() { - let fixture = fixture::wbg_test_browser(); + let fixture = fixture::wbg_test_browser().build(); fixture.install_local_wasm_bindgen(); let firefox = cfg!(any( @@ -87,7 +87,7 @@ fn it_can_run_browser_tests() { #[test] fn it_can_run_failing_tests() { - let fixture = fixture::wbg_test_fail(); + let fixture = fixture::wbg_test_fail().build(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -111,7 +111,7 @@ fn it_can_run_failing_tests() { all(target_os = "windows", target_arch = "x86_64") ))] fn it_can_find_a_webdriver_on_path() { - let fixture = fixture::wbg_test_browser(); + let fixture = fixture::wbg_test_browser().build(); let local_geckodriver = fixture.install_local_geckodriver(); let local_wasm_bindgen = fixture.install_local_wasm_bindgen(); @@ -135,7 +135,7 @@ fn it_can_find_a_webdriver_on_path() { #[test] fn it_requires_node_or_a_browser() { - let fixture = fixture::wbg_test_node(); + let fixture = fixture::wbg_test_node().build(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -148,7 +148,7 @@ fn it_requires_node_or_a_browser() { #[test] fn the_headless_flag_requires_a_browser() { - let fixture = fixture::wbg_test_node(); + let fixture = fixture::wbg_test_node().build(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -163,8 +163,7 @@ fn the_headless_flag_requires_a_browser() { #[test] fn complains_about_missing_wasm_bindgen_test_dependency() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -188,7 +187,8 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { "#, ) .hello_world_src_lib() - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -205,8 +205,7 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { #[test] fn renamed_crate_name_works() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -237,7 +236,8 @@ fn renamed_crate_name_works() { pub fn one() -> u32 { 1 } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -249,8 +249,7 @@ fn renamed_crate_name_works() { #[test] fn cdylib_not_required() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -285,7 +284,8 @@ fn cdylib_not_required() { } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -297,8 +297,7 @@ fn cdylib_not_required() { #[test] fn test_output_is_printed_once_in_both_stdout_and_failures() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .readme() .cargo_toml("test-output-printed-once") .hello_world_src_lib() @@ -323,7 +322,8 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { } "#, ) - .install_local_wasm_bindgen(); + .build(); + fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); // there will be only one log in stdout, and only one log in failures @@ -343,8 +343,7 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { #[test] fn extra_options_is_passed_to_cargo_when_building_tests() { - let fixture = fixture::Fixture::new(); - fixture + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -389,8 +388,8 @@ fn extra_options_is_passed_to_cargo_when_building_tests() { panic!("This should be filtered from test execution."); } "#, - ) - .install_local_wasm_bindgen(); + ).build(); + fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 13f9e79a..45e359f1 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -5,6 +5,8 @@ use std::fs; use std::mem::ManuallyDrop; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use std::sync::atomic::{AtomicI8, Ordering}; +use std::sync::Arc; use std::sync::{MutexGuard, Once}; use std::thread; use tempfile::TempDir; @@ -20,9 +22,15 @@ pub struct Fixture { pub path: PathBuf, } -impl Fixture { +/// A builder for `Fixture'. +pub struct FixtureBuilder { + fixture: Fixture, + pending_writes: Arc, +} + +impl FixtureBuilder { /// Create a new test fixture in a temporary directory. - pub fn new() -> Fixture { + pub fn new() -> FixtureBuilder { // Make sure that all fixtures end up sharing a target dir, and we don't // recompile wasm-bindgen and friends many times over. static SET_TARGET_DIR: Once = Once::new(); @@ -36,9 +44,13 @@ impl Fixture { let dir = TempDir::new_in(&root).unwrap(); let path = dir.path().join("wasm-pack"); eprintln!("Created fixture at {}", path.display()); - Fixture { + let fixture = Fixture { dir: ManuallyDrop::new(dir), path, + }; + FixtureBuilder { + fixture, + pending_writes: Arc::new(AtomicI8::new(0)), } } @@ -48,18 +60,31 @@ impl Fixture { /// fixture's path). /// /// The `contents` are written to the file. - pub fn file, C: AsRef<[u8]>>(&self, path: P, contents: C) -> &Self { + pub fn file, C: AsRef<[u8]> + Send + 'static>( + self, + path: P, + contents: C, + ) -> Self { assert!(path.as_ref().is_relative()); - let path = self.path.join(path); - if let Some(parent) = path.parent() { - fs::create_dir_all(parent).unwrap(); - } - fs::write(path, contents).unwrap(); + let path = self.fixture.path.join(path); + self.pending_writes + .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |n| n.checked_add(1)) + .unwrap(); + let pending_writes = Arc::clone(&self.pending_writes); + std::thread::spawn(move || { + if let Some(parent) = path.parent() { + fs::create_dir_all(parent).unwrap(); + } + fs::write(path, contents).unwrap(); + pending_writes + .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |n| n.checked_sub(1)) + .unwrap(); + }); self } /// Add a generic `README.md` file to the fixture. - pub fn readme(&self) -> &Self { + pub fn readme(self) -> Self { self.file( "README.md", r#" @@ -70,7 +95,7 @@ impl Fixture { } /// Add `LICENSE` file to the fixture. - pub fn license(&self) -> &Self { + pub fn license(self) -> Self { self.file( "LICENSE", r#" @@ -80,7 +105,7 @@ impl Fixture { } /// Add `WTFPL LICENSE` file to the fixture. - pub fn wtfpl_license(&self) -> &Self { + pub fn wtfpl_license(self) -> Self { self.file( "LICENSE-WTFPL", r#" @@ -102,7 +127,7 @@ impl Fixture { } /// Add `MIT LICENSE` file to the fixture. - pub fn mit_license(&self) -> &Self { + pub fn mit_license(self) -> Self { self.file( "LICENSE-MIT", r#" @@ -122,10 +147,10 @@ impl Fixture { /// ["cdylib"]`. /// /// `name` is the crate's name. - pub fn cargo_toml(&self, name: &str) -> &Self { + pub fn cargo_toml(self, name: &str) -> Self { self.file( "Cargo.toml", - &format!( + format!( r#" [package] authors = ["The wasm-pack developers"] @@ -160,10 +185,10 @@ impl Fixture { /// /// `name` is the crate's name. /// `license_file` is license file path - pub fn cargo_toml_with_license_file(&self, name: &str, license_file: &str) -> &Self { + pub fn cargo_toml_with_license_file(self, name: &str, license_file: &str) -> Self { self.file( "Cargo.toml", - &format!( + format!( r#" [package] authors = ["The wasm-pack developers"] @@ -188,7 +213,7 @@ impl Fixture { } /// Add a `src/lib.rs` file that contains a "hello world" program. - pub fn hello_world_src_lib(&self) -> &Self { + pub fn hello_world_src_lib(self) -> Self { self.file( "src/lib.rs", r#" @@ -211,6 +236,14 @@ impl Fixture { ) } + /// Wait for files to be written, then return the fixture. + pub fn build(self) -> Fixture { + while self.pending_writes.load(Ordering::SeqCst) != 0 {} + self.fixture + } +} + +impl Fixture { /// Install a local wasm-bindgen for this fixture. /// /// Takes care not to re-install for every fixture, but only the one time @@ -371,9 +404,8 @@ impl Drop for Fixture { } } -pub fn bad_cargo_toml() -> Fixture { - let fixture = Fixture::new(); - fixture.readme().hello_world_src_lib().file( +pub fn bad_cargo_toml() -> FixtureBuilder { + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -387,22 +419,18 @@ pub fn bad_cargo_toml() -> Fixture { [dependencies] # Note: no wasm-bindgen dependency! "#, - ); - fixture + ) } -pub fn js_hello_world() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn js_hello_world() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("js-hello-world") - .hello_world_src_lib(); - fixture + .hello_world_src_lib() } -pub fn no_cdylib() -> Fixture { - let fixture = Fixture::new(); - fixture.readme().hello_world_src_lib().file( +pub fn no_cdylib() -> FixtureBuilder { + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -422,19 +450,15 @@ pub fn no_cdylib() -> Fixture { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ); - fixture + ) } -pub fn not_a_crate() -> Fixture { - let fixture = Fixture::new(); - fixture.file("README.md", "This is not a Rust crate!"); - fixture +pub fn not_a_crate() -> FixtureBuilder { + FixtureBuilder::new().file("README.md", "This is not a Rust crate!") } -pub fn serde_feature() -> Fixture { - let fixture = Fixture::new(); - fixture.readme().hello_world_src_lib().file( +pub fn serde_feature() -> FixtureBuilder { + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -449,13 +473,11 @@ pub fn serde_feature() -> Fixture { version = "^0.2" features = ["serde-serialize"] "#, - ); - fixture + ) } -pub fn wbg_test_diff_versions() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn wbg_test_diff_versions() -> FixtureBuilder { + FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -501,13 +523,11 @@ pub fn wbg_test_diff_versions() -> Fixture { assert_eq!(wbg_test_diff_versions::one(), 1); } "#, - ); - fixture + ) } -pub fn wbg_test_browser() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn wbg_test_browser() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-browser") .hello_world_src_lib() @@ -524,13 +544,11 @@ pub fn wbg_test_browser() -> Fixture { assert_eq!(1, 1); } "#, - ); - fixture + ) } -pub fn wbg_test_fail() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn wbg_test_fail() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-fail") .hello_world_src_lib() @@ -545,13 +563,11 @@ pub fn wbg_test_fail() -> Fixture { assert_eq!(1, 2); } "#, - ); - fixture + ) } -pub fn wbg_test_node() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn wbg_test_node() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-node") .hello_world_src_lib() @@ -566,14 +582,14 @@ pub fn wbg_test_node() -> Fixture { assert_eq!(1, 1); } "#, - ); - fixture + ) } -pub fn transitive_dependencies() -> Fixture { - fn project_main_fixture(fixture: &mut Fixture) { - fixture.file(PathBuf::from("main/README"), "# Main Fixture\n"); - fixture.file( +pub fn transitive_dependencies() -> FixtureBuilder { + FixtureBuilder::new() + // main + .file(PathBuf::from("main/README"), "# Main Fixture\n") + .file( PathBuf::from("main/Cargo.toml"), r#" [package] @@ -595,8 +611,8 @@ pub fn transitive_dependencies() -> Fixture { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ); - fixture.file( + ) + .file( PathBuf::from("main/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -615,15 +631,13 @@ pub fn transitive_dependencies() -> Fixture { alert(&format!("Hello, {}!", name)); } "#, - ); - } - - fn project_a_fixture(fixture: &mut Fixture) { - fixture.file( + ) + // a + .file( PathBuf::from("project_a/README"), "# Project Alpha Fixture\n", - ); - fixture.file( + ) + .file( PathBuf::from("project_a/Cargo.toml"), r#" [package] @@ -644,8 +658,8 @@ pub fn transitive_dependencies() -> Fixture { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ); - fixture.file( + ) + .file( PathBuf::from("project_a/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -665,15 +679,13 @@ pub fn transitive_dependencies() -> Fixture { alert(&format!("Hello, {}!", name)); } "#, - ); - } - - fn project_b_fixture(fixture: &mut Fixture) { - fixture.file( + ) + // b + .file( PathBuf::from("project_b/README"), "# Project Beta Fixture\n", - ); - fixture.file( + ) + .file( PathBuf::from("project_b/Cargo.toml"), r#" [package] @@ -693,8 +705,8 @@ pub fn transitive_dependencies() -> Fixture { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ); - fixture.file( + ) + .file( PathBuf::from("project_b/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -713,43 +725,30 @@ pub fn transitive_dependencies() -> Fixture { alert(&format!("Hello, {}!", name)); } "#, - ); - } - - let mut fixture = Fixture::new(); - project_b_fixture(&mut fixture); - project_a_fixture(&mut fixture); - project_main_fixture(&mut fixture); - fixture + ) } -pub fn single_license() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn single_license() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("single_license") .license() - .hello_world_src_lib(); - fixture + .hello_world_src_lib() } -pub fn dual_license() -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn dual_license() -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml("dual_license") .wtfpl_license() .mit_license() - .hello_world_src_lib(); - fixture + .hello_world_src_lib() } -pub fn non_standard_license(license_file: &str) -> Fixture { - let fixture = Fixture::new(); - fixture +pub fn non_standard_license(license_file: &str) -> FixtureBuilder { + FixtureBuilder::new() .readme() .cargo_toml_with_license_file("dual_license", license_file) .file(license_file, "license file for test") - .hello_world_src_lib(); - fixture + .hello_world_src_lib() } diff --git a/tests/all/wasm_opt.rs b/tests/all/wasm_opt.rs index 68c0dc9b..42ab9a6b 100644 --- a/tests/all/wasm_opt.rs +++ b/tests/all/wasm_opt.rs @@ -4,8 +4,11 @@ use predicates::prelude::*; #[test] fn off_in_dev() { - let fixture = utils::fixture::Fixture::new(); - fixture.readme().cargo_toml("foo").file("src/lib.rs", ""); + let fixture = utils::fixture::FixtureBuilder::new() + .readme() + .cargo_toml("foo") + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -20,8 +23,11 @@ fn off_in_dev() { #[test] fn on_in_release() { - let fixture = utils::fixture::Fixture::new(); - fixture.readme().cargo_toml("foo").file("src/lib.rs", ""); + let fixture = utils::fixture::FixtureBuilder::new() + .readme() + .cargo_toml("foo") + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -35,8 +41,7 @@ fn on_in_release() { #[test] fn disable_in_release() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -59,7 +64,8 @@ fn disable_in_release() { wasm-opt = false "#, ) - .file("src/lib.rs", ""); + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -73,8 +79,7 @@ fn disable_in_release() { #[test] fn enable_in_dev() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -97,7 +102,8 @@ fn enable_in_dev() { wasm-opt = true "#, ) - .file("src/lib.rs", ""); + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -114,8 +120,7 @@ fn enable_in_dev() { #[test] fn custom_args() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -138,7 +143,8 @@ fn custom_args() { wasm-opt = ['--not-accepted-argument'] "#, ) - .file("src/lib.rs", ""); + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -152,8 +158,7 @@ fn custom_args() { #[test] fn misconfigured() { - let fixture = utils::fixture::Fixture::new(); - fixture + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -176,7 +181,8 @@ fn misconfigured() { wasm-opt = 32 "#, ) - .file("src/lib.rs", ""); + .file("src/lib.rs", "") + .build(); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); diff --git a/tests/all/webdriver.rs b/tests/all/webdriver.rs index 3cd93c94..eb5d0740 100644 --- a/tests/all/webdriver.rs +++ b/tests/all/webdriver.rs @@ -10,7 +10,7 @@ use wasm_pack::test::webdriver; all(target_os = "windows", target_arch = "x86_64") ))] fn can_install_chromedriver() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let cache = Cache::at(&fixture.path); assert!(webdriver::install_chromedriver(&cache, true).is_ok()); } @@ -25,7 +25,7 @@ fn can_install_chromedriver() { all(target_os = "windows", target_arch = "x86_64") ))] fn can_install_geckodriver() { - let fixture = fixture::js_hello_world(); + let fixture = fixture::js_hello_world().build(); let cache = Cache::at(&fixture.path); assert!(webdriver::install_geckodriver(&cache, true).is_ok()); } From d692fc7a151cfdb8f27317aba539048dba79dde8 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 5 Jun 2023 03:03:03 +0000 Subject: [PATCH 63/85] Refactor lockfile name filtering --- src/lockfile.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lockfile.rs b/src/lockfile.rs index ae935934..1af654ca 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -10,6 +10,8 @@ use anyhow::{anyhow, bail, Context, Result}; use console::style; use toml; +const PACKAGE_NAMES: &[&str] = &["wasm-bindgen", "wasm-bindgen-test"]; + /// This struct represents the contents of `Cargo.lock`. #[derive(Clone, Debug, Deserialize)] pub struct Lockfile { @@ -47,7 +49,7 @@ impl<'de> serde::de::Visitor<'de> for PackagesVisitor { { let mut result = Vec::new(); while let Some(package) = seq.next_element::()? { - if package.name.starts_with("wasm-bindgen") { + if PACKAGE_NAMES.contains(&package.name.as_str()) { result.push(package); } } @@ -90,6 +92,7 @@ impl Lockfile { } fn get_package_version(&self, package: &str) -> Option<&str> { + debug_assert!(PACKAGE_NAMES.contains(&package)); self.package .iter() .find(|p| p.name == package) From 592be5b423aac484d8ad41b8a79d3424b318d105 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 5 Jun 2023 18:42:38 +0000 Subject: [PATCH 64/85] Use Command::args with slices (partial) --- src/build/mod.rs | 47 ++++++++++++++++++++++++----------------------- src/generate.rs | 4 +--- src/npm.rs | 30 +++++++++++++++++++++--------- src/wasm_opt.rs | 2 +- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 691ec490..3c04b80e 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -82,32 +82,33 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--lib"); + cmd.current_dir(path); - if PBAR.quiet() { - cmd.arg("--quiet"); - } + let [a1, a2, a3, a4] = ["build", "--lib", "--target", "wasm32-unknown-unknown"]; + let quiet_arg = PBAR.quiet().then_some("--quiet"); + let release_arg = match profile { + // Once there are DWARF debug info consumers, force enable debug + // info, because builds that use the release cargo profile disables + // debug info. + // + // cmd.env("RUSTFLAGS", "-g"); + BuildProfile::Profiling => Some("--release"), - match profile { - BuildProfile::Profiling => { - // Once there are DWARF debug info consumers, force enable debug - // info, because builds that use the release cargo profile disables - // debug info. - // - // cmd.env("RUSTFLAGS", "-g"); - cmd.arg("--release"); - } - BuildProfile::Release => { - cmd.arg("--release"); - } - BuildProfile::Dev => { - // Plain cargo builds use the dev cargo profile, which includes - // debug info by default. - } - } + BuildProfile::Release => Some("--release"), + + // Plain cargo builds use the dev cargo profile, which includes + // debug info by default. + BuildProfile::Dev => None, + }; + + let options = extra_options.iter().map(|s|s.as_str()); + + match (quiet_arg, release_arg) { + (None, None) => cmd.args([a1, a2, a3, a4].iter().copied().chain(options)), + (Some(a5), None) | (None, Some(a5)) => cmd.args([a1, a2, a3, a4, a5].iter().copied().chain(options)), + (Some(a5), Some(a6)) => cmd.args([a1, a2, a3, a4, a5, a6].iter().copied().chain(options)), + }; - cmd.arg("--target").arg("wasm32-unknown-unknown"); - cmd.args(extra_options); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } diff --git a/src/generate.rs b/src/generate.rs index 660f123b..9d4c0c05 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,9 +12,7 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) -> let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); - cmd.arg("generate"); - cmd.arg("--git").arg(&template); - cmd.arg("--name").arg(&name); + cmd.args(["generate", "--git", template, "--name", name].as_slice()); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/npm.rs b/src/npm.rs index 9cdadaa6..e4c63cf2 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -1,5 +1,7 @@ //! Functionality related to publishing to npm. +use std::ffi::{OsStr, OsString}; + use crate::child; use crate::command::publish::access::Access; use anyhow::{bail, Context, Result}; @@ -19,12 +21,14 @@ pub fn npm_pack(path: &str) -> Result<()> { /// Run the `npm publish` command. pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); - match access { - Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), - None => cmd.current_dir(path).arg("publish"), - }; - if let Some(tag) = tag { - cmd.arg("--tag").arg(tag); + cmd.current_dir(path); + let arg1 = OsStr::new("publish"); + let access_string = access.map(|a| a.to_string()); + // Using cmd.args(match ...) would cause a "temporary value dropped while borrowed" error on each array + match (access_string, tag) { + (None, None) => cmd.args([arg1].as_slice()), + (Some(arg2), None) | (None, Some(arg2)) => cmd.args([arg1, arg2.as_ref()].as_slice()), + (Some(arg2), Some(arg3)) => cmd.args([arg1, arg2.as_ref(), arg3.as_ref()].as_slice()), }; child::run(cmd, "npm publish").context("Publishing to npm failed")?; @@ -33,7 +37,11 @@ pub fn npm_publish(path: &str, access: Option, tag: Option) -> R /// Run the `npm login` command. pub fn npm_login(registry: &str, scope: &Option, auth_type: &Option) -> Result<()> { - let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; + let arg1 = OsStr::new("login"); + let arg2 = OsString::from(format!("--registry={}", registry)); + let scope_arg = scope.as_deref().map(|s| OsString::from(format!("--scope={}", s))); + let auth_type_arg = auth_type.as_deref().map(|s| OsString::from(format!("--auth_type={}", s))); + /*let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; if let Some(scope) = scope { args.push(format!("--scope={}", scope)); @@ -41,12 +49,16 @@ pub fn npm_login(registry: &str, scope: &Option, auth_type: &Option cmd.args([arg1, arg2.as_ref()].as_slice()), + (Some(arg3), None) | (None, Some(arg3)) => cmd.args([arg1, &arg2, &arg3].as_slice()), + (Some(arg3), Some(arg4)) => cmd.args([arg1, &arg2, &arg3, &arg4].as_slice()), + }; info!("Running {:?}", cmd); if cmd.status()?.success() { diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 8dd81d30..0d23dbbf 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -29,7 +29,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo let tmp = path.with_extension("wasm-opt.wasm"); let mut cmd = Command::new(&wasm_opt_path); - cmd.arg(&path).arg("-o").arg(&tmp).args(args); + cmd.args([path.as_os_str(), "-o".as_ref(), tmp.as_os_str()].as_slice().iter().copied().chain(args.iter().map(|s|s.as_ref()))); child::run(cmd, "wasm-opt")?; std::fs::rename(&tmp, &path)?; } From 04fb5a16109b0c2b3047e5b25636e57b2d6e39b0 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Mon, 5 Jun 2023 18:46:16 +0000 Subject: [PATCH 65/85] Revert "Use Command::args with slices (partial)" This reverts commit 592be5b423aac484d8ad41b8a79d3424b318d105. --- src/build/mod.rs | 47 +++++++++++++++++++++++------------------------ src/generate.rs | 4 +++- src/npm.rs | 30 +++++++++--------------------- src/wasm_opt.rs | 2 +- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 3c04b80e..691ec490 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -82,33 +82,32 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path); + cmd.current_dir(path).arg("build").arg("--lib"); - let [a1, a2, a3, a4] = ["build", "--lib", "--target", "wasm32-unknown-unknown"]; - let quiet_arg = PBAR.quiet().then_some("--quiet"); - let release_arg = match profile { - // Once there are DWARF debug info consumers, force enable debug - // info, because builds that use the release cargo profile disables - // debug info. - // - // cmd.env("RUSTFLAGS", "-g"); - BuildProfile::Profiling => Some("--release"), - - BuildProfile::Release => Some("--release"), - - // Plain cargo builds use the dev cargo profile, which includes - // debug info by default. - BuildProfile::Dev => None, - }; - - let options = extra_options.iter().map(|s|s.as_str()); + if PBAR.quiet() { + cmd.arg("--quiet"); + } - match (quiet_arg, release_arg) { - (None, None) => cmd.args([a1, a2, a3, a4].iter().copied().chain(options)), - (Some(a5), None) | (None, Some(a5)) => cmd.args([a1, a2, a3, a4, a5].iter().copied().chain(options)), - (Some(a5), Some(a6)) => cmd.args([a1, a2, a3, a4, a5, a6].iter().copied().chain(options)), - }; + match profile { + BuildProfile::Profiling => { + // Once there are DWARF debug info consumers, force enable debug + // info, because builds that use the release cargo profile disables + // debug info. + // + // cmd.env("RUSTFLAGS", "-g"); + cmd.arg("--release"); + } + BuildProfile::Release => { + cmd.arg("--release"); + } + BuildProfile::Dev => { + // Plain cargo builds use the dev cargo profile, which includes + // debug info by default. + } + } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + cmd.args(extra_options); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) } diff --git a/src/generate.rs b/src/generate.rs index 9d4c0c05..660f123b 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,7 +12,9 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) -> let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); - cmd.args(["generate", "--git", template, "--name", name].as_slice()); + cmd.arg("generate"); + cmd.arg("--git").arg(&template); + cmd.arg("--name").arg(&name); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/npm.rs b/src/npm.rs index e4c63cf2..9cdadaa6 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -1,7 +1,5 @@ //! Functionality related to publishing to npm. -use std::ffi::{OsStr, OsString}; - use crate::child; use crate::command::publish::access::Access; use anyhow::{bail, Context, Result}; @@ -21,14 +19,12 @@ pub fn npm_pack(path: &str) -> Result<()> { /// Run the `npm publish` command. pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); - cmd.current_dir(path); - let arg1 = OsStr::new("publish"); - let access_string = access.map(|a| a.to_string()); - // Using cmd.args(match ...) would cause a "temporary value dropped while borrowed" error on each array - match (access_string, tag) { - (None, None) => cmd.args([arg1].as_slice()), - (Some(arg2), None) | (None, Some(arg2)) => cmd.args([arg1, arg2.as_ref()].as_slice()), - (Some(arg2), Some(arg3)) => cmd.args([arg1, arg2.as_ref(), arg3.as_ref()].as_slice()), + match access { + Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), + None => cmd.current_dir(path).arg("publish"), + }; + if let Some(tag) = tag { + cmd.arg("--tag").arg(tag); }; child::run(cmd, "npm publish").context("Publishing to npm failed")?; @@ -37,11 +33,7 @@ pub fn npm_publish(path: &str, access: Option, tag: Option) -> R /// Run the `npm login` command. pub fn npm_login(registry: &str, scope: &Option, auth_type: &Option) -> Result<()> { - let arg1 = OsStr::new("login"); - let arg2 = OsString::from(format!("--registry={}", registry)); - let scope_arg = scope.as_deref().map(|s| OsString::from(format!("--scope={}", s))); - let auth_type_arg = auth_type.as_deref().map(|s| OsString::from(format!("--auth_type={}", s))); - /*let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; + let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; if let Some(scope) = scope { args.push(format!("--scope={}", scope)); @@ -49,16 +41,12 @@ pub fn npm_login(registry: &str, scope: &Option, auth_type: &Option cmd.args([arg1, arg2.as_ref()].as_slice()), - (Some(arg3), None) | (None, Some(arg3)) => cmd.args([arg1, &arg2, &arg3].as_slice()), - (Some(arg3), Some(arg4)) => cmd.args([arg1, &arg2, &arg3, &arg4].as_slice()), - }; + cmd.args(args); info!("Running {:?}", cmd); if cmd.status()?.success() { diff --git a/src/wasm_opt.rs b/src/wasm_opt.rs index 0d23dbbf..8dd81d30 100644 --- a/src/wasm_opt.rs +++ b/src/wasm_opt.rs @@ -29,7 +29,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo let tmp = path.with_extension("wasm-opt.wasm"); let mut cmd = Command::new(&wasm_opt_path); - cmd.args([path.as_os_str(), "-o".as_ref(), tmp.as_os_str()].as_slice().iter().copied().chain(args.iter().map(|s|s.as_ref()))); + cmd.arg(&path).arg("-o").arg(&tmp).args(args); child::run(cmd, "wasm-opt")?; std::fs::rename(&tmp, &path)?; } From 31751f8295d317c1d8ea80a78c21f9ccedef6a01 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 6 Jun 2023 16:15:59 +0000 Subject: [PATCH 66/85] Use Command::args with arrays --- rust | 1 + src/bindgen.rs | 9 +++------ src/build/mod.rs | 9 ++++----- src/build/wasm_target.rs | 2 +- src/child.rs | 2 +- src/generate.rs | 4 +--- src/install/mod.rs | 9 +++------ src/npm.rs | 4 ++-- src/test/mod.rs | 5 ++--- 9 files changed, 18 insertions(+), 27 deletions(-) create mode 160000 rust diff --git a/rust b/rust new file mode 160000 index 00000000..ca6b0087 --- /dev/null +++ b/rust @@ -0,0 +1 @@ +Subproject commit ca6b008756b2743b07c9aa77b88f3918547747b4 diff --git a/src/bindgen.rs b/src/bindgen.rs index 58fab360..84241bb2 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -57,10 +57,7 @@ pub fn wasm_bindgen_build( .binary(&Tool::WasmBindgen.to_string())?; let mut cmd = Command::new(&bindgen_path); - cmd.arg(&wasm_path) - .arg("--out-dir") - .arg(out_dir) - .arg(dts_arg); + cmd.arg(&wasm_path).args(["--out-dir", out_dir, dts_arg]); if weak_refs { cmd.arg("--weak-refs"); @@ -72,13 +69,13 @@ pub fn wasm_bindgen_build( let target_arg = build_target_arg(target, &bindgen_path)?; if supports_dash_dash_target(&bindgen_path)? { - cmd.arg("--target").arg(target_arg); + cmd.args(["--target", &target_arg]); } else { cmd.arg(target_arg); } if let Some(value) = out_name { - cmd.arg("--out-name").arg(value); + cmd.args(["--out-name", &value]); } let profile = data.configured_profile(profile); diff --git a/src/build/mod.rs b/src/build/mod.rs index 691ec490..e7651119 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -82,7 +82,8 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--lib"); + cmd.current_dir(path) + .args(["build", "--lib", "--target", "wasm32-unknown-unknown"]); if PBAR.quiet() { cmd.arg("--quiet"); @@ -106,7 +107,6 @@ pub fn cargo_build_wasm( } } - cmd.arg("--target").arg("wasm32-unknown-unknown"); cmd.args(extra_options); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) @@ -128,7 +128,8 @@ pub fn cargo_build_wasm( pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]) -> Result<()> { let mut cmd = Command::new("cargo"); - cmd.current_dir(path).arg("build").arg("--tests"); + cmd.current_dir(path) + .args(["build", "--tests", "--target", "wasm32-unknown-unknown"]); if PBAR.quiet() { cmd.arg("--quiet"); @@ -138,8 +139,6 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String] cmd.arg("--release"); } - cmd.arg("--target").arg("wasm32-unknown-unknown"); - cmd.args(extra_options); child::run(cmd, "cargo build").context("Compilation of your program failed")?; diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 8631086f..2ffb227b 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -134,7 +134,7 @@ fn check_wasm32_target() -> Result { /// Add wasm32-unknown-unknown using `rustup`. fn rustup_add_wasm_target() -> Result<()> { let mut cmd = Command::new("rustup"); - cmd.arg("target").arg("add").arg("wasm32-unknown-unknown"); + cmd.args(["target", "add", "wasm32-unknown-unknown"]); child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?; Ok(()) diff --git a/src/child.rs b/src/child.rs index 52249ac3..e5888d2a 100644 --- a/src/child.rs +++ b/src/child.rs @@ -17,7 +17,7 @@ pub fn new_command(program: &str) -> Command { if cfg!(windows) { let mut cmd = Command::new("cmd"); - cmd.arg("/c").arg(program); + cmd.args(["/c", program]); cmd } else { Command::new(program) diff --git a/src/generate.rs b/src/generate.rs index 660f123b..7f39da40 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,9 +12,7 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) -> let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); - cmd.arg("generate"); - cmd.arg("--git").arg(&template); - cmd.arg("--name").arg(&name); + cmd.args(["generate", "--git", template, "--name", name]); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/mod.rs b/src/install/mod.rs index 747a1691..440d945c 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -253,14 +253,11 @@ pub fn cargo_install( }; let mut cmd = Command::new("cargo"); - cmd.arg("install") - .arg("--force") - .arg(crate_name) - .arg("--root") - .arg(&tmp); + cmd.args(["install", "--force", &crate_name, "--root"]); + cmd.arg(&tmp); if version != "latest" { - cmd.arg("--version").arg(version); + cmd.args(["--version", version]); } let context = format!("Installing {} with cargo", tool); diff --git a/src/npm.rs b/src/npm.rs index 9cdadaa6..996b5240 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -20,11 +20,11 @@ pub fn npm_pack(path: &str) -> Result<()> { pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); match access { - Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), + Some(a) => cmd.current_dir(path).args(["publish", &a.to_string()]), None => cmd.current_dir(path).arg("publish"), }; if let Some(tag) = tag { - cmd.arg("--tag").arg(tag); + cmd.args(["--tag", &tag]); }; child::run(cmd, "npm publish").context("Publishing to npm failed")?; diff --git a/src/test/mod.rs b/src/test/mod.rs index 1fbe920d..8be326a0 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -25,7 +25,8 @@ where let mut cmd = Command::new("cargo"); cmd.envs(envs); - cmd.current_dir(path).arg("test"); + cmd.current_dir(path) + .args(["test", "--target", "wasm32-unknown-unknown"]); if PBAR.quiet() { cmd.arg("--quiet"); @@ -35,8 +36,6 @@ where cmd.arg("--release"); } - cmd.arg("--target").arg("wasm32-unknown-unknown"); - cmd.args(extra_options); child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?; From db8ba8e440c03311527660298ede3c853e8dcc2e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 6 Jun 2023 22:35:40 +0000 Subject: [PATCH 67/85] Remove rust file --- rust | 1 - 1 file changed, 1 deletion(-) delete mode 160000 rust diff --git a/rust b/rust deleted file mode 160000 index ca6b0087..00000000 --- a/rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ca6b008756b2743b07c9aa77b88f3918547747b4 From a5d1e8e8b9fd2ecf3c5289328d23915f565acf47 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 04:09:30 +0000 Subject: [PATCH 68/85] Revert "Remove rust file" This reverts commit db8ba8e440c03311527660298ede3c853e8dcc2e. --- rust | 1 + 1 file changed, 1 insertion(+) create mode 160000 rust diff --git a/rust b/rust new file mode 160000 index 00000000..ca6b0087 --- /dev/null +++ b/rust @@ -0,0 +1 @@ +Subproject commit ca6b008756b2743b07c9aa77b88f3918547747b4 From 45dc3945618fe43c3a0d3006f65bdf7ad4038def Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 04:09:45 +0000 Subject: [PATCH 69/85] Revert "Revert "Remove rust file"" This reverts commit a5d1e8e8b9fd2ecf3c5289328d23915f565acf47. --- rust | 1 - 1 file changed, 1 deletion(-) delete mode 160000 rust diff --git a/rust b/rust deleted file mode 160000 index ca6b0087..00000000 --- a/rust +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ca6b008756b2743b07c9aa77b88f3918547747b4 From 7f395068e10dfd4f33e306c0e8bf951354955b50 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 04:15:58 +0000 Subject: [PATCH 70/85] Add args directly in npm_login --- src/npm.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/npm.rs b/src/npm.rs index 996b5240..373bf917 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -33,21 +33,19 @@ pub fn npm_publish(path: &str, access: Option, tag: Option) -> R /// Run the `npm login` command. pub fn npm_login(registry: &str, scope: &Option, auth_type: &Option) -> Result<()> { - let mut args = vec!["login".to_string(), format!("--registry={}", registry)]; + // Interactively ask user for npm login info. + // (child::run does not support interactive input) + let mut cmd = child::new_command("npm"); + cmd.args(["login".to_string(), format!("--registry={}", registry)]); if let Some(scope) = scope { - args.push(format!("--scope={}", scope)); + cmd.arg(format!("--scope={}", scope)); } if let Some(auth_type) = auth_type { - args.push(format!("--auth_type={}", auth_type)); + cmd.arg(format!("--auth_type={}", auth_type)); } - // Interactively ask user for npm login info. - // (child::run does not support interactive input) - let mut cmd = child::new_command("npm"); - cmd.args(args); - info!("Running {:?}", cmd); if cmd.status()?.success() { Ok(()) From eaf3430ba7b13cc98d1e8ebebc3e026c44e4f463 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 04:27:28 +0000 Subject: [PATCH 71/85] Use trim_backtraces(None) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3151d818..7075eb6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ static ALLOC: dhat::Alloc = dhat::Alloc; fn main() { #[cfg(feature = "dhat-heap")] - let _profiler = dhat::Profiler::new_heap(); + let _profiler = dhat::Profiler::builder().trim_backtraces(None).build(); env_logger::init(); From 6d56036e2774fa4afb27c6110e886f94241609ed Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 04:59:19 +0000 Subject: [PATCH 72/85] Optimize usage of cargo_metadata (removes most memory usage) --- src/manifest/mod.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 26c28e47..b208efb0 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -9,7 +9,7 @@ use anyhow::{anyhow, bail, Context, Result}; mod npm; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::{collections::HashMap, fs}; use self::npm::{ @@ -17,7 +17,6 @@ use self::npm::{ }; use crate::command::build::{BuildProfile, Target}; use crate::PBAR; -use cargo_metadata::Metadata; use chrono::offset; use chrono::DateTime; use serde::{self, Deserialize}; @@ -34,8 +33,9 @@ const WASM_PACK_REPO_URL: &str = "https://github.com/rustwasm/wasm-pack"; /// Store for metadata learned about a crate pub struct CrateData { - data: Metadata, - current_idx: usize, + package: cargo_metadata::Package, + target_directory: PathBuf, + workspace_root: PathBuf, manifest: CargoManifest, out_name: Option, } @@ -395,25 +395,27 @@ impl CrateData { let data = cargo_metadata::MetadataCommand::new() .manifest_path(&manifest_path) + .no_deps() .exec()?; let manifest_and_keys = CrateData::parse_crate_data(&manifest_path)?; CrateData::warn_for_unused_keys(&manifest_and_keys); let manifest = manifest_and_keys.manifest; - let current_idx = data + let package = data .packages - .iter() - .position(|pkg| { + .into_iter() + .find(|pkg| { pkg.name == manifest.package.name && CrateData::is_same_path(pkg.manifest_path.as_std_path(), &manifest_path) }) .ok_or_else(|| anyhow!("failed to find package in metadata"))?; Ok(CrateData { - data, + package, + workspace_root: data.workspace_root.into(), + target_directory: data.target_directory.into(), manifest, - current_idx, out_name, }) } @@ -487,7 +489,7 @@ impl CrateData { } fn check_crate_type(&self) -> Result<()> { - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; let any_cdylib = pkg .targets .iter() @@ -505,7 +507,7 @@ impl CrateData { } fn pkg(&self) -> &cargo_metadata::Package { - &self.data.packages[self.current_idx] + &self.package } /// Get the crate name for the crate at the given path. @@ -545,12 +547,12 @@ impl CrateData { /// Returns the path to this project's target directory where artifacts are /// located after a cargo build. pub fn target_directory(&self) -> &Path { - Path::new(&self.data.target_directory) + Path::new(&self.target_directory) } /// Returns the path to this project's root cargo workspace directory pub fn workspace_root(&self) -> &Path { - Path::new(&self.data.workspace_root) + Path::new(&self.workspace_root) } /// Generate a package.json file inside in `./pkg`. @@ -606,7 +608,7 @@ impl CrateData { files.push(js_bg_file); } - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; let npm_name = match scope { Some(s) => format!("@{}/{}", s, pkg.name), None => pkg.name.clone(), @@ -665,7 +667,7 @@ impl CrateData { out_dir: &Path, ) -> NpmPackage { let data = self.npm_data(scope, false, disable_dts, out_dir); - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; self.check_optional_fields(); @@ -696,7 +698,7 @@ impl CrateData { out_dir: &Path, ) -> NpmPackage { let data = self.npm_data(scope, true, disable_dts, out_dir); - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; self.check_optional_fields(); @@ -728,7 +730,7 @@ impl CrateData { out_dir: &Path, ) -> NpmPackage { let data = self.npm_data(scope, false, disable_dts, out_dir); - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; self.check_optional_fields(); @@ -760,7 +762,7 @@ impl CrateData { out_dir: &Path, ) -> NpmPackage { let data = self.npm_data(scope, false, disable_dts, out_dir); - let pkg = &self.data.packages[self.current_idx]; + let pkg = &self.package; self.check_optional_fields(); From 01d09128bf2236e20d49a5c483ca242010b3c1f9 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 05:26:45 +0000 Subject: [PATCH 73/85] Avoid running `which` if wasm target is found --- src/build/wasm_target.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 2ffb227b..24bd2ed5 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -58,8 +58,7 @@ pub fn check_for_wasm32_target() -> Result<()> { // Check if wasm32 target is present, otherwise bail. match check_wasm32_target() { - Ok(ref wasm32_check) if wasm32_check.found => Ok(()), - Ok(wasm32_check) => bail!("{}", wasm32_check), + Ok(()) => Ok(()), Err(err) => Err(err), } } @@ -97,36 +96,29 @@ fn is_wasm32_target_in_sysroot(sysroot: &Path) -> bool { } } -fn check_wasm32_target() -> Result { +fn check_wasm32_target() -> Result<()> { let sysroot = get_rustc_sysroot()?; - let rustc_path = which::which("rustc")?; // If wasm32-unknown-unknown already exists we're ok. if is_wasm32_target_in_sysroot(&sysroot) { - Ok(Wasm32Check { - rustc_path, - sysroot, - found: true, - is_rustup: false, - }) + Ok(()) // If it doesn't exist, then we need to check if we're using rustup. } else { + let rustc_path = which::which("rustc")?; // If sysroot contains "rustup", then we can assume we're using rustup // and use rustup to add the wasm32-unknown-unknown target. if sysroot.to_string_lossy().contains("rustup") { - rustup_add_wasm_target().map(|()| Wasm32Check { - rustc_path, - sysroot, - found: true, - is_rustup: true, - }) + rustup_add_wasm_target() } else { - Ok(Wasm32Check { - rustc_path, - sysroot, - found: false, - is_rustup: false, - }) + bail!( + "{}", + Wasm32Check { + rustc_path, + sysroot, + found: false, + is_rustup: false, + } + ); } } } From dc9e99c66ceac009b4c803bf93d371db3f6d636d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Wed, 7 Jun 2023 19:41:21 +0000 Subject: [PATCH 74/85] Optimize lockfile --- src/command/build.rs | 6 +- src/command/test.rs | 17 ++-- src/lockfile.rs | 189 +++++++++++++++++++++++++++--------------- tests/all/lockfile.rs | 18 ++-- 4 files changed, 141 insertions(+), 89 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index b47dd4e2..b4d4f829 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -7,7 +7,7 @@ use crate::command::utils::{create_pkg_dir, get_crate_path}; use crate::emoji; use crate::install::{self, InstallMode, Tool}; use crate::license; -use crate::lockfile::Lockfile; +use crate::lockfile; use crate::manifest; use crate::readme; use crate::wasm_opt; @@ -406,8 +406,8 @@ impl Build { fn step_install_wasm_bindgen(&mut self) -> Result<()> { info!("Identifying wasm-bindgen dependency..."); - let lockfile = Lockfile::new(&self.crate_data)?; - let bindgen_version = lockfile.require_wasm_bindgen()?; + let [package] = lockfile::Package::get(&self.crate_data, ["wasm-bindgen"])?; + let bindgen_version = package.require_version_or_suggest("dependencies", "0.2")?; info!("Installing wasm-bindgen-cli..."); let bindgen = install::download_prebuilt_or_cargo_install( Tool::WasmBindgen, diff --git a/src/command/test.rs b/src/command/test.rs index d7b66424..0a5cff9b 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -4,12 +4,11 @@ use crate::build; use crate::cache; use crate::command::utils::get_crate_path; use crate::install::{self, InstallMode, Tool}; -use crate::lockfile::Lockfile; +use crate::lockfile; use crate::manifest; use crate::test::{self, webdriver}; use anyhow::{bail, Result}; use binary_install::Cache; -use console::style; use log::info; use std::path::PathBuf; use std::str::FromStr; @@ -282,22 +281,16 @@ impl Test { fn step_install_wasm_bindgen(&mut self) -> Result<()> { info!("Identifying wasm-bindgen dependency..."); - let lockfile = Lockfile::new(&self.crate_data)?; - let bindgen_version = lockfile.require_wasm_bindgen()?; + let [bindgen, bindgen_test] = + lockfile::Package::get(&self.crate_data, ["wasm-bindgen", "wasm-bindgen-test"])?; + let bindgen_version = bindgen.require_version_or_suggest("dependencies", "0.2")?; // Unlike `wasm-bindgen` and `wasm-bindgen-cli`, `wasm-bindgen-test` // will work with any semver compatible `wasm-bindgen-cli`, so just make // sure that it is depended upon, so we can run tests on // `wasm32-unkown-unknown`. Don't enforce that it is the same version as // `wasm-bindgen`. - if lockfile.wasm_bindgen_test_version().is_none() { - bail!( - "Ensure that you have \"{}\" as a dependency in your Cargo.toml file:\n\ - [dev-dependencies]\n\ - wasm-bindgen-test = \"0.2\"", - style("wasm-bindgen-test").bold().dim(), - ) - } + bindgen_test.require_version_or_suggest("dev-dependencies", "0.2")?; let status = install::download_prebuilt_or_cargo_install( Tool::WasmBindgen, diff --git a/src/lockfile.rs b/src/lockfile.rs index 1af654ca..053eba23 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -2,104 +2,163 @@ #![allow(clippy::new_ret_no_self)] -use std::fs; use std::path::PathBuf; +use std::{borrow::Cow, fs}; use crate::manifest::CrateData; use anyhow::{anyhow, bail, Context, Result}; use console::style; +use serde::{ + de::{DeserializeSeed, Error, IgnoredAny, Visitor}, + Deserializer, +}; use toml; -const PACKAGE_NAMES: &[&str] = &["wasm-bindgen", "wasm-bindgen-test"]; - -/// This struct represents the contents of `Cargo.lock`. -#[derive(Clone, Debug, Deserialize)] -pub struct Lockfile { - #[serde(deserialize_with = "deserialize_package_list")] - package: Vec, -} - /// This struct represents a single package entry in `Cargo.lock` -#[derive(Clone, Debug, Deserialize)] -struct Package { - name: String, - version: String, +pub struct Package<'a> { + name: &'a str, + version: Option, } -/// Deserializer that only includes packages with a name starting with "wasm-bindgen" -fn deserialize_package_list<'de, D>(deserializer: D) -> std::result::Result, D::Error> -where - D: serde::Deserializer<'de>, -{ - deserializer.deserialize_seq(PackagesVisitor) +impl<'a> Package<'a> { + /// Read the `Cargo.lock` file for the crate at the given path and get the versions of the named dependencies. + pub fn get( + crate_data: &CrateData, + dep_names: [&'a str; N], + ) -> Result<[Self; N]> { + let lock_path = get_lockfile_path(crate_data)?; + let lockfile = fs::read_to_string(&lock_path) + .with_context(|| anyhow!("failed to read: {}", lock_path.display()))?; + toml::Deserializer::new(&lockfile) + .deserialize_struct("Lockfile", &["package"], LockfileVisitor { dep_names }) + .with_context(|| anyhow!("failed to parse: {}", lock_path.display())) + } + + /// Get the version of this package used in the `Cargo.lock`. + pub fn version(&self) -> Option<&str> { + self.version.as_deref() + } + + /// Like `version`, except it returns an error instead of `None`. `suggested_version` is only used when showing an example of adding the dependency to `Cargo.toml`. + pub fn require_version_or_suggest( + &self, + section: &str, + suggested_version: &str, + ) -> Result<&str> { + self.version().ok_or_else(|| { + anyhow!( + "Ensure that you have \"{}\" as a dependency in your Cargo.toml file:\n\ + [{}]\n\ + {} = \"{}\"", + style(self.name).bold().dim(), + section, + self.name, + suggested_version, + ) + }) + } } -struct PackagesVisitor; +struct LockfileVisitor<'a, const N: usize> { + dep_names: [&'a str; N], +} -impl<'de> serde::de::Visitor<'de> for PackagesVisitor { - type Value = Vec; +impl<'de, 'a, const N: usize> Visitor<'de> for LockfileVisitor<'a, N> { + type Value = [Package<'a>; N]; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("a sequence") + formatter.write_str("struct Lockfile") } - fn visit_seq(self, mut seq: A) -> std::result::Result + fn visit_map(self, mut map: A) -> std::result::Result where - A: serde::de::SeqAccess<'de>, + A: serde::de::MapAccess<'de>, { - let mut result = Vec::new(); - while let Some(package) = seq.next_element::()? { - if PACKAGE_NAMES.contains(&package.name.as_str()) { - result.push(package); + #[derive(Deserialize)] + #[serde(field_identifier, rename_all = "lowercase")] + enum Field { + Package, + Other(IgnoredAny), + } + + while let Some(key) = map.next_key()? { + match key { + Field::Package => { + return map.next_value_seed(PackagesSeed { + dep_names: self.dep_names, + }) + } + Field::Other(_) => { + map.next_value::()?; + } } } - Ok(result) + Err(A::Error::missing_field("package")) } } -impl Lockfile { - /// Read the `Cargo.lock` file for the crate at the given path. - pub fn new(crate_data: &CrateData) -> Result { - let lock_path = get_lockfile_path(crate_data)?; - let lockfile = fs::read_to_string(&lock_path) - .with_context(|| anyhow!("failed to read: {}", lock_path.display()))?; - let lockfile = toml::from_str(&lockfile) - .with_context(|| anyhow!("failed to parse: {}", lock_path.display()))?; - Ok(lockfile) - } +struct PackagesSeed<'a, const N: usize> { + dep_names: [&'a str; N], +} - /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. - pub fn wasm_bindgen_version(&self) -> Option<&str> { - self.get_package_version("wasm-bindgen") - } +impl<'de, 'a, const N: usize> DeserializeSeed<'de> for PackagesSeed<'a, N> { + type Value = [Package<'a>; N]; - /// Like `wasm_bindgen_version`, except it returns an error instead of - /// `None`. - pub fn require_wasm_bindgen(&self) -> Result<&str> { - self.wasm_bindgen_version().ok_or_else(|| { - anyhow!( - "Ensure that you have \"{}\" as a dependency in your Cargo.toml file:\n\ - [dependencies]\n\ - wasm-bindgen = \"0.2\"", - style("wasm-bindgen").bold().dim(), - ) - }) + fn deserialize(self, deserializer: D) -> std::result::Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_seq(self) } +} - /// Get the version of `wasm-bindgen` dependency used in the `Cargo.lock`. - pub fn wasm_bindgen_test_version(&self) -> Option<&str> { - self.get_package_version("wasm-bindgen-test") +impl<'de, 'a, const N: usize> Visitor<'de> for PackagesSeed<'a, N> { + type Value = [Package<'a>; N]; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("a sequence") } - fn get_package_version(&self, package: &str) -> Option<&str> { - debug_assert!(PACKAGE_NAMES.contains(&package)); - self.package - .iter() - .find(|p| p.name == package) - .map(|p| &p.version[..]) + fn visit_seq(self, mut seq: A) -> std::result::Result + where + A: serde::de::SeqAccess<'de>, + { + let mut packages = self.dep_names.map(|name| Package { + name, + version: None, + }); + while let Some(PackageValue { name, version }) = seq.next_element()? { + #[cfg(test)] + assert_eq!( + (true, true), + ( + matches!(name, Cow::Borrowed(_)), + matches!(version, Cow::Borrowed(_)) + ) + ); + for package in &mut packages { + if package.name == name { + package.version = Some(version.into_owned()); + if packages.iter().all(|i| i.version.is_some()) { + return Ok(packages); + } else { + break; + } + } + } + } + Ok(packages) } } +#[derive(Deserialize)] +struct PackageValue<'a> { + #[serde(borrow)] + name: Cow<'a, str>, + #[serde(borrow)] + version: Cow<'a, str>, +} + /// Given the path to the crate that we are building, return a `PathBuf` /// containing the location of the lock file, by finding the workspace root. fn get_lockfile_path(crate_data: &CrateData) -> Result { diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index 9b50835e..d8318834 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -1,5 +1,5 @@ use crate::utils::fixture; -use wasm_pack::lockfile::Lockfile; +use wasm_pack::lockfile; use wasm_pack::manifest::CrateData; #[test] @@ -7,8 +7,8 @@ fn it_gets_wasm_bindgen_version() { let fixture = fixture::js_hello_world().build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); - let lock = Lockfile::new(&data).unwrap(); - assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),); + let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); + assert_eq!(package.version(), Some("0.2.74"),); } #[test] @@ -16,8 +16,8 @@ fn it_gets_wasm_bindgen_test_version() { let fixture = fixture::wbg_test_node().build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); - let lock = Lockfile::new(&data).unwrap(); - assert_eq!(lock.wasm_bindgen_test_version(), Some("0.3.24"),); + let [package] = lockfile::Package::get(&data, ["wasm-bindgen-test"]).unwrap(); + assert_eq!(package.version(), Some("0.3.24"),); } #[test] @@ -61,8 +61,8 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { .build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("blah"), None).unwrap(); - let lock = Lockfile::new(&data).unwrap(); - assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),); + let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); + assert_eq!(package.version(), Some("0.2.74"),); } #[test] @@ -129,6 +129,6 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { .build(); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("parent"), None).unwrap(); - let lock = Lockfile::new(&data).unwrap(); - assert_eq!(lock.wasm_bindgen_version(), Some("0.2.74"),); + let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); + assert_eq!(package.version(), Some("0.2.74"),); } From 06923770e67375333314d47c796411172c49006e Mon Sep 17 00:00:00 2001 From: dullbananas Date: Thu, 8 Jun 2023 02:35:14 +0000 Subject: [PATCH 75/85] Replace structopt with clap (allocations increased) --- Cargo.lock | 138 ++++++++++------------------------ Cargo.toml | 2 +- src/command/build.rs | 39 +++++----- src/command/mod.rs | 34 ++++----- src/command/publish/access.rs | 2 +- src/command/test.rs | 32 ++++---- src/lib.rs | 10 +-- src/main.rs | 6 +- tests/all/main.rs | 2 +- 9 files changed, 97 insertions(+), 168 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1372beba..a927710e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,15 +52,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.3.2" @@ -327,19 +318,46 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2" dependencies = [ - "ansi_term", - "atty", + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" +dependencies = [ + "anstream", + "anstyle", "bitflags", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", + "clap_lex", + "strsim", ] +[[package]] +name = "clap_derive" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "colorchoice" version = "1.0.0" @@ -742,12 +760,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -1172,30 +1187,6 @@ dependencies = [ "termtree", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.59" @@ -1513,42 +1504,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "subtle" version = "2.5.0" @@ -1617,15 +1578,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.40" @@ -1764,12 +1716,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" @@ -1832,12 +1778,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -1939,6 +1879,7 @@ dependencies = [ "binary-install", "cargo_metadata", "chrono", + "clap", "console", "dhat", "dialoguer", @@ -1956,8 +1897,7 @@ dependencies = [ "serde_json", "serial_test", "siphasher", - "strsim 0.10.0", - "structopt", + "strsim", "tempfile", "toml 0.5.11", "ureq", diff --git a/Cargo.toml b/Cargo.toml index 1fa675cb..038ff155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ atty = "0.2.14" binary-install = "0.1.0" cargo_metadata = "0.15.2" chrono = "0.4.23" +clap = { version = "4.3.2", features = ["derive"] } console = "0.15.5" dhat = { version = "0.3.2", optional = true } dialoguer = "0.10.3" @@ -31,7 +32,6 @@ serde_ignored = "0.1.7" serde_json = "1.0.91" siphasher = "0.3.10" strsim = "0.10.0" -structopt = "0.3.26" toml = "0.5.11" ureq = { version = "2.6.2", features = ["json"] } walkdir = "2.3.2" diff --git a/src/command/build.rs b/src/command/build.rs index b4d4f829..6267c6c4 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -19,7 +19,6 @@ use std::fmt; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; -use structopt::clap::AppSettings; /// Everything required to configure and run the `wasm-pack build` command. #[allow(missing_docs)] @@ -109,74 +108,70 @@ pub enum BuildProfile { } /// Everything required to configure and run the `wasm-pack build` command. -#[derive(Debug, StructOpt)] -#[structopt( +#[derive(Debug, Parser)] +#[command( // Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`. - setting = AppSettings::AllowLeadingHyphen, - - // Allows `--` to be parsed as an argument, so we can forward it to `cargo`. - setting = AppSettings::TrailingVarArg, + allow_hyphen_values = true, )] pub struct BuildOptions { /// The path to the Rust crate. If not set, searches up the path from the current directory. - #[structopt(parse(from_os_str))] pub path: Option, /// The npm scope to use in package.json, if any. - #[structopt(long = "scope", short = "s")] + #[arg(long = "scope", short = 's')] pub scope: Option, - #[structopt(long = "mode", short = "m", default_value = "normal")] + #[arg(long = "mode", short = 'm', default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, - #[structopt(long = "no-typescript")] + #[arg(long = "no-typescript")] /// By default a *.d.ts file is generated for the generated JS file, but /// this flag will disable generating this TypeScript file. pub disable_dts: bool, - #[structopt(long = "weak-refs")] + #[arg(long = "weak-refs")] /// Enable usage of the JS weak references proposal. pub weak_refs: bool, - #[structopt(long = "reference-types")] + #[arg(long = "reference-types")] /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[structopt(long = "target", short = "t", default_value = "bundler")] + #[arg(long = "target", short = 't', default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, - #[structopt(long = "debug")] + #[arg(long = "debug")] /// Deprecated. Renamed to `--dev`. pub debug: bool, - #[structopt(long = "dev")] + #[arg(long = "dev")] /// Create a development build. Enable debug info, and disable /// optimizations. pub dev: bool, - #[structopt(long = "release")] + #[arg(long = "release")] /// Create a release build. Enable optimizations and disable debug info. pub release: bool, - #[structopt(long = "profiling")] + #[arg(long = "profiling")] /// Create a profiling build. Enable optimizations and debug info. pub profiling: bool, - #[structopt(long = "out-dir", short = "d", default_value = "pkg")] + #[arg(long = "out-dir", short = 'd', default_value = "pkg")] /// Sets the output directory with a relative path. pub out_dir: String, - #[structopt(long = "out-name")] + #[arg(long = "out-name")] /// Sets the output file names. Defaults to package name. pub out_name: Option, - #[structopt(long = "no-pack", alias = "no-package")] + #[arg(long = "no-pack", alias = "no-package")] /// Option to not generate a package.json pub no_pack: bool, - #[structopt(allow_hyphen_values = true)] + #[structopt(allow_hyphen_values = true, trailing_var_arg = true)] /// List of extra options to pass to `cargo build` pub extra_options: Vec, } diff --git a/src/command/mod.rs b/src/command/mod.rs index 631eca71..3090e8b9 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -22,62 +22,60 @@ use log::info; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. -#[derive(Debug, StructOpt)] +#[derive(Debug, Subcommand)] pub enum Command { /// 🏗️ build your npm package! - #[structopt(name = "build", alias = "init")] + #[command(name = "build", alias = "init")] Build(BuildOptions), - #[structopt(name = "pack")] + #[command(name = "pack")] /// 🍱 create a tar of your npm package but don't publish! Pack { /// The path to the Rust crate. If not set, searches up the path from the current directory. - #[structopt(parse(from_os_str))] path: Option, }, - #[structopt(name = "new")] + #[command(name = "new")] /// 🐑 create a new project with a template Generate { /// The name of the project name: String, /// The URL to the template - #[structopt( + #[arg( long = "template", - short = "temp", + short = 't', default_value = "https://github.com/rustwasm/wasm-pack-template" )] template: String, - #[structopt(long = "mode", short = "m", default_value = "normal")] + #[arg(long = "mode", short = 'm', default_value = "normal")] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, - #[structopt(name = "publish")] + #[command(name = "publish")] /// 🎆 pack up your npm package and publish! Publish { - #[structopt(long = "target", short = "t", default_value = "bundler")] + #[arg(long = "target", short = 't', default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] target: String, /// The access level for the package to be published - #[structopt(long = "access", short = "a")] + #[arg(long = "access", short = 'a')] access: Option, /// The distribution tag being used for publishing. /// See https://docs.npmjs.com/cli/dist-tag - #[structopt(long = "tag")] + #[arg(long = "tag")] tag: Option, /// The path to the Rust crate. If not set, searches up the path from the current directory. - #[structopt(parse(from_os_str))] path: Option, }, - #[structopt(name = "login", alias = "adduser", alias = "add-user")] + #[command(name = "login", alias = "adduser", alias = "add-user")] /// 👤 Add an npm registry user account! (aliases: adduser, add-user) Login { - #[structopt(long = "registry", short = "r")] + #[arg(long = "registry", short = 'r')] /// Default: 'https://registry.npmjs.org/'. /// The base URL of the npm package registry. If scope is also /// specified, this registry will only be used for packages with that @@ -85,13 +83,13 @@ pub enum Command { /// currently in, if any. registry: Option, - #[structopt(long = "scope", short = "s")] + #[arg(long = "scope", short = 's')] /// Default: none. /// If specified, the user and login credentials given will be /// associated with the specified scope. scope: Option, - #[structopt(long = "auth-type", short = "t")] + #[arg(long = "auth-type", short = 't')] /// Default: 'legacy'. /// Type: 'legacy', 'sso', 'saml', 'oauth'. /// What authentication strategy to use with adduser/login. Some npm @@ -100,7 +98,7 @@ pub enum Command { auth_type: Option, }, - #[structopt(name = "test")] + #[command(name = "test")] /// 👩‍🔬 test your wasm! Test(TestOptions), } diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index 6b374b4c..6ae572ca 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -3,7 +3,7 @@ use std::fmt; use std::str::FromStr; /// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`. -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum Access { /// Access is granted to all. All unscoped packages *must* be public. Public, diff --git a/src/command/test.rs b/src/command/test.rs index 0a5cff9b..aa6ea6a1 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -13,68 +13,64 @@ use log::info; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; -use structopt::clap::AppSettings; -#[derive(Debug, Default, StructOpt)] -#[structopt( +#[derive(Debug, Default, Parser)] +#[command( // Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`. - setting = AppSettings::AllowLeadingHyphen, - - // Allows `--` to be parsed as an argument, so we can forward it to `cargo`. - setting = AppSettings::TrailingVarArg, + allow_hyphen_values = true, )] /// Everything required to configure the `wasm-pack test` command. pub struct TestOptions { - #[structopt(long = "node")] + #[arg(long = "node")] /// Run the tests in Node.js. pub node: bool, - #[structopt(long = "firefox")] + #[arg(long = "firefox")] /// Run the tests in Firefox. This machine must have a Firefox installation. /// If the `geckodriver` WebDriver client is not on the `$PATH`, and not /// specified with `--geckodriver`, then `wasm-pack` will download a local /// copy. pub firefox: bool, - #[structopt(long = "geckodriver", parse(from_os_str))] + #[arg(long = "geckodriver")] /// The path to the `geckodriver` WebDriver client for testing in /// Firefox. Implies `--firefox`. pub geckodriver: Option, - #[structopt(long = "chrome")] + #[arg(long = "chrome")] /// Run the tests in Chrome. This machine must have a Chrome installation. /// If the `chromedriver` WebDriver client is not on the `$PATH`, and not /// specified with `--chromedriver`, then `wasm-pack` will download a local /// copy. pub chrome: bool, - #[structopt(long = "chromedriver", parse(from_os_str))] + #[arg(long = "chromedriver")] /// The path to the `chromedriver` WebDriver client for testing in /// Chrome. Implies `--chrome`. pub chromedriver: Option, - #[structopt(long = "safari")] + #[arg(long = "safari")] /// Run the tests in Safari. This machine must have a Safari installation, /// and the `safaridriver` WebDriver client must either be on the `$PATH` or /// specified explicitly with the `--safaridriver` flag. `wasm-pack` cannot /// download the `safaridriver` WebDriver client for you. pub safari: bool, - #[structopt(long = "safaridriver", parse(from_os_str))] + #[arg(long = "safaridriver")] /// The path to the `safaridriver` WebDriver client for testing in /// Safari. Implies `--safari`. pub safaridriver: Option, - #[structopt(long = "headless")] + #[arg(long = "headless")] /// When running browser tests, run the browser in headless mode without any /// UI or windows. pub headless: bool, - #[structopt(long = "mode", short = "m", default_value = "normal")] + #[arg(long = "mode", short = 'm', default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, - #[structopt(long = "release", short = "r")] + #[arg(long = "release", short = 'r')] /// Build with the release profile. pub release: bool, @@ -84,7 +80,7 @@ pub struct TestOptions { /// /// This is a workaround to allow wasm pack to provide the same command line interface as `cargo`. /// See for more information. - #[structopt(allow_hyphen_values = true)] + #[structopt(allow_hyphen_values = true, trailing_var_arg = true)] pub path_and_extra_options: Vec, } diff --git a/src/lib.rs b/src/lib.rs index 1f5c5085..563dc7c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ extern crate serde_derive; extern crate serde_ignored; extern crate serde_json; #[macro_use] -extern crate structopt; +extern crate clap; extern crate binary_install; extern crate chrono; extern crate dialoguer; @@ -49,21 +49,21 @@ use crate::progressbar::{LogLevel, ProgressOutput}; pub static PBAR: ProgressOutput = ProgressOutput::new(); /// 📦 ✨ pack and publish your wasm! -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Cli { /// The subcommand to run. #[structopt(subcommand)] // Note that we mark a field as a subcommand pub cmd: command::Command, /// Log verbosity is based off the number of v used - #[structopt(long = "verbose", short = "v", parse(from_occurrences))] + #[arg(long = "verbose", short = 'v', action = clap::ArgAction::Count)] pub verbosity: u8, - #[structopt(long = "quiet", short = "q")] + #[arg(long = "quiet", short = 'q')] /// No output printed to stdout pub quiet: bool, - #[structopt(long = "log-level", default_value = "info")] + #[arg(long = "log-level", default_value = "info")] /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } diff --git a/src/main.rs b/src/main.rs index 7075eb6d..a02c4e3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,19 @@ extern crate anyhow; extern crate atty; +extern crate clap; extern crate env_logger; extern crate human_panic; extern crate log; -extern crate structopt; extern crate wasm_pack; extern crate which; use anyhow::Result; +use clap::Parser; use std::env; use std::panic; use std::sync::mpsc; use std::thread; -use structopt::StructOpt; use wasm_pack::{ build::{self, WasmPackVersion}, command::run_wasm_pack, @@ -86,7 +86,7 @@ fn run() -> Result<()> { } } - let args = Cli::from_args(); + let args = Cli::parse(); PBAR.set_log_level(args.log_level); diff --git a/tests/all/main.rs b/tests/all/main.rs index c99a871c..a7cdb8bf 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -8,7 +8,7 @@ extern crate binary_install; extern crate serde_json; #[macro_use] extern crate serial_test; -extern crate structopt; +extern crate clap; extern crate tempfile; extern crate wasm_pack; From ba4c9025b846ba50ab400a300ff29e28979f27aa Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 9 Jun 2023 04:57:15 +0000 Subject: [PATCH 76/85] Revert "Use Command::args with arrays" This reverts commit 31751f8295d317c1d8ea80a78c21f9ccedef6a01. --- src/bindgen.rs | 9 ++++++--- src/build/mod.rs | 9 +++++---- src/build/wasm_target.rs | 2 +- src/child.rs | 2 +- src/generate.rs | 4 +++- src/install/mod.rs | 9 ++++++--- src/npm.rs | 4 ++-- src/test/mod.rs | 5 +++-- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 84241bb2..58fab360 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -57,7 +57,10 @@ pub fn wasm_bindgen_build( .binary(&Tool::WasmBindgen.to_string())?; let mut cmd = Command::new(&bindgen_path); - cmd.arg(&wasm_path).args(["--out-dir", out_dir, dts_arg]); + cmd.arg(&wasm_path) + .arg("--out-dir") + .arg(out_dir) + .arg(dts_arg); if weak_refs { cmd.arg("--weak-refs"); @@ -69,13 +72,13 @@ pub fn wasm_bindgen_build( let target_arg = build_target_arg(target, &bindgen_path)?; if supports_dash_dash_target(&bindgen_path)? { - cmd.args(["--target", &target_arg]); + cmd.arg("--target").arg(target_arg); } else { cmd.arg(target_arg); } if let Some(value) = out_name { - cmd.args(["--out-name", &value]); + cmd.arg("--out-name").arg(value); } let profile = data.configured_profile(profile); diff --git a/src/build/mod.rs b/src/build/mod.rs index e7651119..691ec490 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -82,8 +82,7 @@ pub fn cargo_build_wasm( PBAR.info(&msg); let mut cmd = Command::new("cargo"); - cmd.current_dir(path) - .args(["build", "--lib", "--target", "wasm32-unknown-unknown"]); + cmd.current_dir(path).arg("build").arg("--lib"); if PBAR.quiet() { cmd.arg("--quiet"); @@ -107,6 +106,7 @@ pub fn cargo_build_wasm( } } + cmd.arg("--target").arg("wasm32-unknown-unknown"); cmd.args(extra_options); child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?; Ok(()) @@ -128,8 +128,7 @@ pub fn cargo_build_wasm( pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]) -> Result<()> { let mut cmd = Command::new("cargo"); - cmd.current_dir(path) - .args(["build", "--tests", "--target", "wasm32-unknown-unknown"]); + cmd.current_dir(path).arg("build").arg("--tests"); if PBAR.quiet() { cmd.arg("--quiet"); @@ -139,6 +138,8 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String] cmd.arg("--release"); } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + cmd.args(extra_options); child::run(cmd, "cargo build").context("Compilation of your program failed")?; diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index 24bd2ed5..e31d3909 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -126,7 +126,7 @@ fn check_wasm32_target() -> Result<()> { /// Add wasm32-unknown-unknown using `rustup`. fn rustup_add_wasm_target() -> Result<()> { let mut cmd = Command::new("rustup"); - cmd.args(["target", "add", "wasm32-unknown-unknown"]); + cmd.arg("target").arg("add").arg("wasm32-unknown-unknown"); child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?; Ok(()) diff --git a/src/child.rs b/src/child.rs index e5888d2a..52249ac3 100644 --- a/src/child.rs +++ b/src/child.rs @@ -17,7 +17,7 @@ pub fn new_command(program: &str) -> Command { if cfg!(windows) { let mut cmd = Command::new("cmd"); - cmd.args(["/c", program]); + cmd.arg("/c").arg(program); cmd } else { Command::new(program) diff --git a/src/generate.rs b/src/generate.rs index 7f39da40..660f123b 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -12,7 +12,9 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) -> let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)? .binary(&Tool::CargoGenerate.to_string())?; let mut cmd = Command::new(&bin_path); - cmd.args(["generate", "--git", template, "--name", name]); + cmd.arg("generate"); + cmd.arg("--git").arg(&template); + cmd.arg("--name").arg(&name); println!( "{} Generating a new rustwasm project with name '{}'...", diff --git a/src/install/mod.rs b/src/install/mod.rs index 440d945c..747a1691 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -253,11 +253,14 @@ pub fn cargo_install( }; let mut cmd = Command::new("cargo"); - cmd.args(["install", "--force", &crate_name, "--root"]); - cmd.arg(&tmp); + cmd.arg("install") + .arg("--force") + .arg(crate_name) + .arg("--root") + .arg(&tmp); if version != "latest" { - cmd.args(["--version", version]); + cmd.arg("--version").arg(version); } let context = format!("Installing {} with cargo", tool); diff --git a/src/npm.rs b/src/npm.rs index 373bf917..adcde515 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -20,11 +20,11 @@ pub fn npm_pack(path: &str) -> Result<()> { pub fn npm_publish(path: &str, access: Option, tag: Option) -> Result<()> { let mut cmd = child::new_command("npm"); match access { - Some(a) => cmd.current_dir(path).args(["publish", &a.to_string()]), + Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()), None => cmd.current_dir(path).arg("publish"), }; if let Some(tag) = tag { - cmd.args(["--tag", &tag]); + cmd.arg("--tag").arg(tag); }; child::run(cmd, "npm publish").context("Publishing to npm failed")?; diff --git a/src/test/mod.rs b/src/test/mod.rs index 8be326a0..1fbe920d 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -25,8 +25,7 @@ where let mut cmd = Command::new("cargo"); cmd.envs(envs); - cmd.current_dir(path) - .args(["test", "--target", "wasm32-unknown-unknown"]); + cmd.current_dir(path).arg("test"); if PBAR.quiet() { cmd.arg("--quiet"); @@ -36,6 +35,8 @@ where cmd.arg("--release"); } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + cmd.args(extra_options); child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?; From 64401297da96e4d2236b4934eeb4c635719ad1cf Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 9 Jun 2023 05:10:40 +0000 Subject: [PATCH 77/85] Run step_check_crate_config in main thread --- src/command/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/build.rs b/src/command/build.rs index 6267c6c4..64420eed 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -315,10 +315,10 @@ impl Build { } fn step_run_checks(&mut self) -> Result<()> { + self.step_check_crate_config()?; std::thread::scope(|s| { for handle in [ s.spawn(|| self.step_check_rustc_version()), - s.spawn(|| self.step_check_crate_config()), s.spawn(|| self.step_check_for_wasm_target()), ] { handle.join().unwrap()?; From 845638b166c86e7758538ddaf6fe8dc075cf77fb Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 9 Jun 2023 06:10:56 +0000 Subject: [PATCH 78/85] Avoid calls to serde_ignored callback --- src/manifest/mod.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index b208efb0..6a08957b 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -19,7 +19,7 @@ use crate::command::build::{BuildProfile, Target}; use crate::PBAR; use chrono::offset; use chrono::DateTime; -use serde::{self, Deserialize}; +use serde::{self, de::IgnoredAny, Deserialize}; use serde_json; use std::collections::BTreeSet; use std::env; @@ -44,6 +44,9 @@ pub struct CrateData { #[derive(Deserialize)] pub struct CargoManifest { package: CargoPackage, + + #[serde(flatten, deserialize_with = "deserialize_unchecked_keys")] + _unchecked_keys: IgnoredAny, } #[derive(Deserialize)] @@ -52,6 +55,18 @@ struct CargoPackage { #[serde(default)] metadata: CargoMetadata, + + #[serde(flatten, deserialize_with = "deserialize_unchecked_keys")] + _unchecked_keys: IgnoredAny, +} + +/// This doesn't trigger the callback given to `serde_ignored::deserialize` +/// because it doesn't call `Deserializer::deserialize_ignored_any`. +fn deserialize_unchecked_keys<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + deserializer.deserialize_map(IgnoredAny) } #[derive(Default, Deserialize)] @@ -447,9 +462,11 @@ impl CrateData { let manifest: CargoManifest = serde_ignored::deserialize(manifest, |path| { let path_string = path.to_string(); - if path_string.starts_with("package.metadata") - && (path_string.contains("wasm-pack") - || levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold) + // Check that deserialize_unchecked_keys works correctly + debug_assert!(path_string.starts_with("package.metadata")); + + if path_string.contains("wasm-pack") + || levenshtein(WASM_PACK_METADATA_KEY, &path_string) <= levenshtein_threshold { unused_keys.insert(path_string); } From 7cd74e9cf185ada9ef0a8b49f6892909e78ce3be Mon Sep 17 00:00:00 2001 From: dullbananas Date: Fri, 9 Jun 2023 18:06:34 +0000 Subject: [PATCH 79/85] Move FixtureBuilder::new to Fixture::new --- tests/all/build.rs | 10 ++--- tests/all/lockfile.rs | 4 +- tests/all/log_level.rs | 8 ++-- tests/all/manifest.rs | 12 +++--- tests/all/readme.rs | 4 +- tests/all/test.rs | 10 ++--- tests/all/utils/fixture.rs | 76 +++++++++++++++++++------------------- tests/all/wasm_opt.rs | 12 +++--- 8 files changed, 68 insertions(+), 68 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index 25e01239..c4e2a67d 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -39,7 +39,7 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() { #[test] fn it_should_build_crates_in_a_workspace() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .file( "Cargo.toml", r#" @@ -87,7 +87,7 @@ fn it_should_build_crates_in_a_workspace() { #[test] fn renamed_crate_name_works() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -122,7 +122,7 @@ fn renamed_crate_name_works() { #[test] fn dash_dash_web_target_has_error_on_old_bindgen() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -201,7 +201,7 @@ fn build_different_profiles() { #[test] fn build_with_and_without_wasm_bindgen_debug() { for debug in [true, false].iter().cloned() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -327,7 +327,7 @@ fn build_from_new() { #[test] fn build_crates_with_same_names() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "somename1/Cargo.toml", diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index d8318834..b01382d8 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -22,7 +22,7 @@ fn it_gets_wasm_bindgen_test_version() { #[test] fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .file( "Cargo.toml", r#" @@ -67,7 +67,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[test] fn it_gets_wasm_bindgen_version_from_dependencies() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .file( "Cargo.toml", r#" diff --git a/tests/all/log_level.rs b/tests/all/log_level.rs index f58f304d..ca6cd6b5 100644 --- a/tests/all/log_level.rs +++ b/tests/all/log_level.rs @@ -28,7 +28,7 @@ fn matches_cargo() -> impl Predicate + PredicateReflection { #[test] fn quiet() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -43,7 +43,7 @@ fn quiet() { #[test] fn log_level_info() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -59,7 +59,7 @@ fn log_level_info() { #[test] fn log_level_warn() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -79,7 +79,7 @@ fn log_level_warn() { #[test] fn log_level_error() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 97cce656..cc8d81b2 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -375,7 +375,7 @@ fn it_errors_when_wasm_bindgen_is_not_declared() { #[test] fn it_sets_homepage_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -432,7 +432,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { #[test] fn it_sets_keywords_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -499,7 +499,7 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { #[test] fn configure_wasm_bindgen_debug_incorrectly_is_error() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .hello_world_src_lib() .file( @@ -537,7 +537,7 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { #[test] fn parse_crate_data_returns_unused_keys_in_cargo_toml() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -608,7 +608,7 @@ fn it_lists_license_files_in_files_field_of_package_json() { #[test] fn it_recurses_up_the_path_to_find_cargo_toml() { - let fixture = utils::fixture::FixtureBuilder::new(); + let fixture = utils::fixture::Fixture::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" @@ -630,7 +630,7 @@ fn it_recurses_up_the_path_to_find_cargo_toml() { #[test] fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { - let fixture = utils::fixture::FixtureBuilder::new(); + let fixture = utils::fixture::Fixture::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" diff --git a/tests/all/readme.rs b/tests/all/readme.rs index 1c76fd88..cc298a1b 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -36,7 +36,7 @@ fn it_copies_a_readme_default_path() { #[test] fn it_copies_a_readme_provided_path() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -97,7 +97,7 @@ fn it_copies_a_readme_provided_path() { #[test] fn it_ignores_a_disabled_readme() { - fixture::FixtureBuilder::new() + fixture::Fixture::new() .hello_world_src_lib() .file( "Cargo.toml", diff --git a/tests/all/test.rs b/tests/all/test.rs index 8e33d6ad..b37f64f6 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -163,7 +163,7 @@ fn the_headless_flag_requires_a_browser() { #[test] fn complains_about_missing_wasm_bindgen_test_dependency() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -205,7 +205,7 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { #[test] fn renamed_crate_name_works() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -249,7 +249,7 @@ fn renamed_crate_name_works() { #[test] fn cdylib_not_required() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -297,7 +297,7 @@ fn cdylib_not_required() { #[test] fn test_output_is_printed_once_in_both_stdout_and_failures() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .readme() .cargo_toml("test-output-printed-once") .hello_world_src_lib() @@ -343,7 +343,7 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { #[test] fn extra_options_is_passed_to_cargo_when_building_tests() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new() .readme() .file( "Cargo.toml", diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 3973197a..5a9c39b3 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -29,31 +29,6 @@ pub struct FixtureBuilder { } impl FixtureBuilder { - /// Create a new test fixture in a temporary directory. - pub fn new() -> FixtureBuilder { - // Make sure that all fixtures end up sharing a target dir, and we don't - // recompile wasm-bindgen and friends many times over. - static SET_TARGET_DIR: Once = Once::new(); - let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); - SET_TARGET_DIR.call_once(|| { - env::set_var("CARGO_TARGET_DIR", &target_dir); - }); - - let root = target_dir.join("t"); - fs::create_dir_all(&root).unwrap(); - let dir = TempDir::new_in(&root).unwrap(); - let path = dir.path().join("wasm-pack"); - eprintln!("Created fixture at {}", path.display()); - let fixture = Fixture { - dir: ManuallyDrop::new(dir), - path, - }; - FixtureBuilder { - fixture, - pending_writes: Arc::new(AtomicI8::new(0)), - } - } - /// Create a file within this fixture. /// /// `path` should be a relative path to the file (relative within this @@ -244,6 +219,31 @@ impl FixtureBuilder { } impl Fixture { + /// Create a new test fixture in a temporary directory. + pub fn new() -> FixtureBuilder { + // Make sure that all fixtures end up sharing a target dir, and we don't + // recompile wasm-bindgen and friends many times over. + static SET_TARGET_DIR: Once = Once::new(); + let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); + SET_TARGET_DIR.call_once(|| { + env::set_var("CARGO_TARGET_DIR", &target_dir); + }); + + let root = target_dir.join("t"); + fs::create_dir_all(&root).unwrap(); + let dir = TempDir::new_in(&root).unwrap(); + let path = dir.path().join("wasm-pack"); + eprintln!("Created fixture at {}", path.display()); + let fixture = Fixture { + dir: ManuallyDrop::new(dir), + path, + }; + FixtureBuilder { + fixture, + pending_writes: Arc::new(AtomicI8::new(0)), + } + } + /// Install a local wasm-bindgen for this fixture. /// /// Takes care not to re-install for every fixture, but only the one time @@ -409,7 +409,7 @@ impl Drop for Fixture { } pub fn bad_cargo_toml() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( + Fixture::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -427,14 +427,14 @@ pub fn bad_cargo_toml() -> FixtureBuilder { } pub fn js_hello_world() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("js-hello-world") .hello_world_src_lib() } pub fn no_cdylib() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( + Fixture::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -458,11 +458,11 @@ pub fn no_cdylib() -> FixtureBuilder { } pub fn not_a_crate() -> FixtureBuilder { - FixtureBuilder::new().file("README.md", "This is not a Rust crate!") + Fixture::new().file("README.md", "This is not a Rust crate!") } pub fn serde_feature() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( + Fixture::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -481,7 +481,7 @@ pub fn serde_feature() -> FixtureBuilder { } pub fn wbg_test_diff_versions() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .file( "Cargo.toml", @@ -531,7 +531,7 @@ pub fn wbg_test_diff_versions() -> FixtureBuilder { } pub fn wbg_test_browser() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("wbg-test-browser") .hello_world_src_lib() @@ -552,7 +552,7 @@ pub fn wbg_test_browser() -> FixtureBuilder { } pub fn wbg_test_fail() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("wbg-test-fail") .hello_world_src_lib() @@ -571,7 +571,7 @@ pub fn wbg_test_fail() -> FixtureBuilder { } pub fn wbg_test_node() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("wbg-test-node") .hello_world_src_lib() @@ -590,7 +590,7 @@ pub fn wbg_test_node() -> FixtureBuilder { } pub fn transitive_dependencies() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() // main .file(PathBuf::from("main/README"), "# Main Fixture\n") .file( @@ -733,7 +733,7 @@ pub fn transitive_dependencies() -> FixtureBuilder { } pub fn single_license() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("single_license") .license() @@ -741,7 +741,7 @@ pub fn single_license() -> FixtureBuilder { } pub fn dual_license() -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml("dual_license") .wtfpl_license() @@ -750,7 +750,7 @@ pub fn dual_license() -> FixtureBuilder { } pub fn non_standard_license(license_file: &str) -> FixtureBuilder { - FixtureBuilder::new() + Fixture::new() .readme() .cargo_toml_with_license_file("dual_license", license_file) .file(license_file, "license file for test") diff --git a/tests/all/wasm_opt.rs b/tests/all/wasm_opt.rs index 42ab9a6b..27b91c34 100644 --- a/tests/all/wasm_opt.rs +++ b/tests/all/wasm_opt.rs @@ -4,7 +4,7 @@ use predicates::prelude::*; #[test] fn off_in_dev() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .cargo_toml("foo") .file("src/lib.rs", "") @@ -23,7 +23,7 @@ fn off_in_dev() { #[test] fn on_in_release() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .cargo_toml("foo") .file("src/lib.rs", "") @@ -41,7 +41,7 @@ fn on_in_release() { #[test] fn disable_in_release() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -79,7 +79,7 @@ fn disable_in_release() { #[test] fn enable_in_dev() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -120,7 +120,7 @@ fn enable_in_dev() { #[test] fn custom_args() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", @@ -158,7 +158,7 @@ fn custom_args() { #[test] fn misconfigured() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new() .readme() .file( "Cargo.toml", From 07ab317b8673db9250a234bc60200802b58f41db Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:14:19 +0000 Subject: [PATCH 80/85] Revert "Replace structopt with clap (allocations increased)" This reverts commit 06923770e67375333314d47c796411172c49006e. --- Cargo.lock | 138 ++++++++++++++++++++++++---------- Cargo.toml | 2 +- src/command/build.rs | 39 +++++----- src/command/mod.rs | 34 +++++---- src/command/publish/access.rs | 2 +- src/command/test.rs | 32 ++++---- src/lib.rs | 10 +-- src/main.rs | 6 +- tests/all/main.rs | 2 +- 9 files changed, 168 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a927710e..1372beba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,15 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anstream" version = "0.3.2" @@ -318,46 +327,19 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] - -[[package]] -name = "clap_builder" -version = "4.3.1" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "anstream", - "anstyle", + "ansi_term", + "atty", "bitflags", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.18", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", ] -[[package]] -name = "clap_lex" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" - [[package]] name = "colorchoice" version = "1.0.0" @@ -760,9 +742,12 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" -version = "0.4.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -1187,6 +1172,30 @@ dependencies = [ "termtree", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.59" @@ -1504,12 +1513,42 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "structopt" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "subtle" version = "2.5.0" @@ -1578,6 +1617,15 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.40" @@ -1716,6 +1764,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + [[package]] name = "unicode-width" version = "0.1.10" @@ -1778,6 +1832,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" @@ -1879,7 +1939,6 @@ dependencies = [ "binary-install", "cargo_metadata", "chrono", - "clap", "console", "dhat", "dialoguer", @@ -1897,7 +1956,8 @@ dependencies = [ "serde_json", "serial_test", "siphasher", - "strsim", + "strsim 0.10.0", + "structopt", "tempfile", "toml 0.5.11", "ureq", diff --git a/Cargo.toml b/Cargo.toml index 038ff155..1fa675cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ atty = "0.2.14" binary-install = "0.1.0" cargo_metadata = "0.15.2" chrono = "0.4.23" -clap = { version = "4.3.2", features = ["derive"] } console = "0.15.5" dhat = { version = "0.3.2", optional = true } dialoguer = "0.10.3" @@ -32,6 +31,7 @@ serde_ignored = "0.1.7" serde_json = "1.0.91" siphasher = "0.3.10" strsim = "0.10.0" +structopt = "0.3.26" toml = "0.5.11" ureq = { version = "2.6.2", features = ["json"] } walkdir = "2.3.2" diff --git a/src/command/build.rs b/src/command/build.rs index 7d2c317f..b6430757 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -19,6 +19,7 @@ use std::fmt; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; +use structopt::clap::AppSettings; /// Everything required to configure and run the `wasm-pack build` command. #[allow(missing_docs)] @@ -108,70 +109,74 @@ pub enum BuildProfile { } /// Everything required to configure and run the `wasm-pack build` command. -#[derive(Debug, Parser)] -#[command( +#[derive(Debug, StructOpt)] +#[structopt( // Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`. - allow_hyphen_values = true, + setting = AppSettings::AllowLeadingHyphen, + + // Allows `--` to be parsed as an argument, so we can forward it to `cargo`. + setting = AppSettings::TrailingVarArg, )] pub struct BuildOptions { /// The path to the Rust crate. If not set, searches up the path from the current directory. + #[structopt(parse(from_os_str))] pub path: Option, /// The npm scope to use in package.json, if any. - #[arg(long = "scope", short = 's')] + #[structopt(long = "scope", short = "s")] pub scope: Option, - #[arg(long = "mode", short = 'm', default_value = "normal")] + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal, force] pub mode: InstallMode, - #[arg(long = "no-typescript")] + #[structopt(long = "no-typescript")] /// By default a *.d.ts file is generated for the generated JS file, but /// this flag will disable generating this TypeScript file. pub disable_dts: bool, - #[arg(long = "weak-refs")] + #[structopt(long = "weak-refs")] /// Enable usage of the JS weak references proposal. pub weak_refs: bool, - #[arg(long = "reference-types")] + #[structopt(long = "reference-types")] /// Enable usage of WebAssembly reference types. pub reference_types: bool, - #[arg(long = "target", short = 't', default_value = "bundler")] + #[structopt(long = "target", short = "t", default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] pub target: Target, - #[arg(long = "debug")] + #[structopt(long = "debug")] /// Deprecated. Renamed to `--dev`. pub debug: bool, - #[arg(long = "dev")] + #[structopt(long = "dev")] /// Create a development build. Enable debug info, and disable /// optimizations. pub dev: bool, - #[arg(long = "release")] + #[structopt(long = "release")] /// Create a release build. Enable optimizations and disable debug info. pub release: bool, - #[arg(long = "profiling")] + #[structopt(long = "profiling")] /// Create a profiling build. Enable optimizations and debug info. pub profiling: bool, - #[arg(long = "out-dir", short = 'd', default_value = "pkg")] + #[structopt(long = "out-dir", short = "d", default_value = "pkg")] /// Sets the output directory with a relative path. pub out_dir: String, - #[arg(long = "out-name")] + #[structopt(long = "out-name")] /// Sets the output file names. Defaults to package name. pub out_name: Option, - #[arg(long = "no-pack", alias = "no-package")] + #[structopt(long = "no-pack", alias = "no-package")] /// Option to not generate a package.json pub no_pack: bool, - #[structopt(allow_hyphen_values = true, trailing_var_arg = true)] + #[structopt(allow_hyphen_values = true)] /// List of extra options to pass to `cargo build` pub extra_options: Vec, } diff --git a/src/command/mod.rs b/src/command/mod.rs index 3090e8b9..631eca71 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -22,60 +22,62 @@ use log::info; use std::path::PathBuf; /// The various kinds of commands that `wasm-pack` can execute. -#[derive(Debug, Subcommand)] +#[derive(Debug, StructOpt)] pub enum Command { /// 🏗️ build your npm package! - #[command(name = "build", alias = "init")] + #[structopt(name = "build", alias = "init")] Build(BuildOptions), - #[command(name = "pack")] + #[structopt(name = "pack")] /// 🍱 create a tar of your npm package but don't publish! Pack { /// The path to the Rust crate. If not set, searches up the path from the current directory. + #[structopt(parse(from_os_str))] path: Option, }, - #[command(name = "new")] + #[structopt(name = "new")] /// 🐑 create a new project with a template Generate { /// The name of the project name: String, /// The URL to the template - #[arg( + #[structopt( long = "template", - short = 't', + short = "temp", default_value = "https://github.com/rustwasm/wasm-pack-template" )] template: String, - #[arg(long = "mode", short = 'm', default_value = "normal")] + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Should we install or check the presence of binary tools. [possible values: no-install, normal, force] mode: InstallMode, }, - #[command(name = "publish")] + #[structopt(name = "publish")] /// 🎆 pack up your npm package and publish! Publish { - #[arg(long = "target", short = 't', default_value = "bundler")] + #[structopt(long = "target", short = "t", default_value = "bundler")] /// Sets the target environment. [possible values: bundler, nodejs, web, no-modules] target: String, /// The access level for the package to be published - #[arg(long = "access", short = 'a')] + #[structopt(long = "access", short = "a")] access: Option, /// The distribution tag being used for publishing. /// See https://docs.npmjs.com/cli/dist-tag - #[arg(long = "tag")] + #[structopt(long = "tag")] tag: Option, /// The path to the Rust crate. If not set, searches up the path from the current directory. + #[structopt(parse(from_os_str))] path: Option, }, - #[command(name = "login", alias = "adduser", alias = "add-user")] + #[structopt(name = "login", alias = "adduser", alias = "add-user")] /// 👤 Add an npm registry user account! (aliases: adduser, add-user) Login { - #[arg(long = "registry", short = 'r')] + #[structopt(long = "registry", short = "r")] /// Default: 'https://registry.npmjs.org/'. /// The base URL of the npm package registry. If scope is also /// specified, this registry will only be used for packages with that @@ -83,13 +85,13 @@ pub enum Command { /// currently in, if any. registry: Option, - #[arg(long = "scope", short = 's')] + #[structopt(long = "scope", short = "s")] /// Default: none. /// If specified, the user and login credentials given will be /// associated with the specified scope. scope: Option, - #[arg(long = "auth-type", short = 't')] + #[structopt(long = "auth-type", short = "t")] /// Default: 'legacy'. /// Type: 'legacy', 'sso', 'saml', 'oauth'. /// What authentication strategy to use with adduser/login. Some npm @@ -98,7 +100,7 @@ pub enum Command { auth_type: Option, }, - #[command(name = "test")] + #[structopt(name = "test")] /// 👩‍🔬 test your wasm! Test(TestOptions), } diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index 6ae572ca..6b374b4c 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -3,7 +3,7 @@ use std::fmt; use std::str::FromStr; /// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`. -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum Access { /// Access is granted to all. All unscoped packages *must* be public. Public, diff --git a/src/command/test.rs b/src/command/test.rs index aa6ea6a1..0a5cff9b 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -13,64 +13,68 @@ use log::info; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; +use structopt::clap::AppSettings; -#[derive(Debug, Default, Parser)] -#[command( +#[derive(Debug, Default, StructOpt)] +#[structopt( // Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`. - allow_hyphen_values = true, + setting = AppSettings::AllowLeadingHyphen, + + // Allows `--` to be parsed as an argument, so we can forward it to `cargo`. + setting = AppSettings::TrailingVarArg, )] /// Everything required to configure the `wasm-pack test` command. pub struct TestOptions { - #[arg(long = "node")] + #[structopt(long = "node")] /// Run the tests in Node.js. pub node: bool, - #[arg(long = "firefox")] + #[structopt(long = "firefox")] /// Run the tests in Firefox. This machine must have a Firefox installation. /// If the `geckodriver` WebDriver client is not on the `$PATH`, and not /// specified with `--geckodriver`, then `wasm-pack` will download a local /// copy. pub firefox: bool, - #[arg(long = "geckodriver")] + #[structopt(long = "geckodriver", parse(from_os_str))] /// The path to the `geckodriver` WebDriver client for testing in /// Firefox. Implies `--firefox`. pub geckodriver: Option, - #[arg(long = "chrome")] + #[structopt(long = "chrome")] /// Run the tests in Chrome. This machine must have a Chrome installation. /// If the `chromedriver` WebDriver client is not on the `$PATH`, and not /// specified with `--chromedriver`, then `wasm-pack` will download a local /// copy. pub chrome: bool, - #[arg(long = "chromedriver")] + #[structopt(long = "chromedriver", parse(from_os_str))] /// The path to the `chromedriver` WebDriver client for testing in /// Chrome. Implies `--chrome`. pub chromedriver: Option, - #[arg(long = "safari")] + #[structopt(long = "safari")] /// Run the tests in Safari. This machine must have a Safari installation, /// and the `safaridriver` WebDriver client must either be on the `$PATH` or /// specified explicitly with the `--safaridriver` flag. `wasm-pack` cannot /// download the `safaridriver` WebDriver client for you. pub safari: bool, - #[arg(long = "safaridriver")] + #[structopt(long = "safaridriver", parse(from_os_str))] /// The path to the `safaridriver` WebDriver client for testing in /// Safari. Implies `--safari`. pub safaridriver: Option, - #[arg(long = "headless")] + #[structopt(long = "headless")] /// When running browser tests, run the browser in headless mode without any /// UI or windows. pub headless: bool, - #[arg(long = "mode", short = 'm', default_value = "normal")] + #[structopt(long = "mode", short = "m", default_value = "normal")] /// Sets steps to be run. [possible values: no-install, normal] pub mode: InstallMode, - #[arg(long = "release", short = 'r')] + #[structopt(long = "release", short = "r")] /// Build with the release profile. pub release: bool, @@ -80,7 +84,7 @@ pub struct TestOptions { /// /// This is a workaround to allow wasm pack to provide the same command line interface as `cargo`. /// See for more information. - #[structopt(allow_hyphen_values = true, trailing_var_arg = true)] + #[structopt(allow_hyphen_values = true)] pub path_and_extra_options: Vec, } diff --git a/src/lib.rs b/src/lib.rs index 563dc7c7..1f5c5085 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ extern crate serde_derive; extern crate serde_ignored; extern crate serde_json; #[macro_use] -extern crate clap; +extern crate structopt; extern crate binary_install; extern crate chrono; extern crate dialoguer; @@ -49,21 +49,21 @@ use crate::progressbar::{LogLevel, ProgressOutput}; pub static PBAR: ProgressOutput = ProgressOutput::new(); /// 📦 ✨ pack and publish your wasm! -#[derive(Debug, Parser)] +#[derive(Debug, StructOpt)] pub struct Cli { /// The subcommand to run. #[structopt(subcommand)] // Note that we mark a field as a subcommand pub cmd: command::Command, /// Log verbosity is based off the number of v used - #[arg(long = "verbose", short = 'v', action = clap::ArgAction::Count)] + #[structopt(long = "verbose", short = "v", parse(from_occurrences))] pub verbosity: u8, - #[arg(long = "quiet", short = 'q')] + #[structopt(long = "quiet", short = "q")] /// No output printed to stdout pub quiet: bool, - #[arg(long = "log-level", default_value = "info")] + #[structopt(long = "log-level", default_value = "info")] /// The maximum level of messages that should be logged by wasm-pack. [possible values: info, warn, error] pub log_level: LogLevel, } diff --git a/src/main.rs b/src/main.rs index a02c4e3b..7075eb6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,19 @@ extern crate anyhow; extern crate atty; -extern crate clap; extern crate env_logger; extern crate human_panic; extern crate log; +extern crate structopt; extern crate wasm_pack; extern crate which; use anyhow::Result; -use clap::Parser; use std::env; use std::panic; use std::sync::mpsc; use std::thread; +use structopt::StructOpt; use wasm_pack::{ build::{self, WasmPackVersion}, command::run_wasm_pack, @@ -86,7 +86,7 @@ fn run() -> Result<()> { } } - let args = Cli::parse(); + let args = Cli::from_args(); PBAR.set_log_level(args.log_level); diff --git a/tests/all/main.rs b/tests/all/main.rs index a7cdb8bf..c99a871c 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -8,7 +8,7 @@ extern crate binary_install; extern crate serde_json; #[macro_use] extern crate serial_test; -extern crate clap; +extern crate structopt; extern crate tempfile; extern crate wasm_pack; From 9fa1f804d2d701e0739a2a290f228de3377106d3 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:27:12 +0000 Subject: [PATCH 81/85] Refactor --- src/build/wasm_target.rs | 5 +---- src/command/build.rs | 7 +++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/build/wasm_target.rs b/src/build/wasm_target.rs index e31d3909..14bb050d 100644 --- a/src/build/wasm_target.rs +++ b/src/build/wasm_target.rs @@ -57,10 +57,7 @@ pub fn check_for_wasm32_target() -> Result<()> { PBAR.info(&msg); // Check if wasm32 target is present, otherwise bail. - match check_wasm32_target() { - Ok(()) => Ok(()), - Err(err) => Err(err), - } + check_wasm32_target() } /// Get rustc's sysroot as a PathBuf diff --git a/src/command/build.rs b/src/command/build.rs index b6430757..d800d56d 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -296,7 +296,7 @@ impl Build { match &mode { InstallMode::Force => {} _ => { - steps.extend(steps![step_run_checks,]); + steps.extend(steps![step_check_rustc, step_check_crate_config,]); } } @@ -319,8 +319,7 @@ impl Build { steps } - fn step_run_checks(&mut self) -> Result<()> { - self.step_check_crate_config()?; + fn step_check_rustc(&mut self) -> Result<()> { std::thread::scope(|s| { for handle in [ s.spawn(|| self.step_check_rustc_version()), @@ -340,7 +339,7 @@ impl Build { Ok(()) } - fn step_check_crate_config(&self) -> Result<()> { + fn step_check_crate_config(&mut self) -> Result<()> { info!("Checking crate configuration..."); self.crate_data.check_crate_config()?; info!("Crate is correctly configured."); From 13e3c63891395c34b0ac22b5b50341d99af3a23f Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:34:01 +0000 Subject: [PATCH 82/85] Revert "Move FixtureBuilder::new to Fixture::new" This reverts commit 7cd74e9cf185ada9ef0a8b49f6892909e78ce3be. --- tests/all/build.rs | 10 ++--- tests/all/lockfile.rs | 4 +- tests/all/log_level.rs | 8 ++-- tests/all/manifest.rs | 12 +++--- tests/all/readme.rs | 4 +- tests/all/test.rs | 10 ++--- tests/all/utils/fixture.rs | 76 +++++++++++++++++++------------------- tests/all/wasm_opt.rs | 12 +++--- 8 files changed, 68 insertions(+), 68 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index c4e2a67d..25e01239 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -39,7 +39,7 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() { #[test] fn it_should_build_crates_in_a_workspace() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" @@ -87,7 +87,7 @@ fn it_should_build_crates_in_a_workspace() { #[test] fn renamed_crate_name_works() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -122,7 +122,7 @@ fn renamed_crate_name_works() { #[test] fn dash_dash_web_target_has_error_on_old_bindgen() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -201,7 +201,7 @@ fn build_different_profiles() { #[test] fn build_with_and_without_wasm_bindgen_debug() { for debug in [true, false].iter().cloned() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -327,7 +327,7 @@ fn build_from_new() { #[test] fn build_crates_with_same_names() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "somename1/Cargo.toml", diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index b01382d8..d8318834 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -22,7 +22,7 @@ fn it_gets_wasm_bindgen_test_version() { #[test] fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" @@ -67,7 +67,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[test] fn it_gets_wasm_bindgen_version_from_dependencies() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .file( "Cargo.toml", r#" diff --git a/tests/all/log_level.rs b/tests/all/log_level.rs index ca6cd6b5..f58f304d 100644 --- a/tests/all/log_level.rs +++ b/tests/all/log_level.rs @@ -28,7 +28,7 @@ fn matches_cargo() -> impl Predicate + PredicateReflection { #[test] fn quiet() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -43,7 +43,7 @@ fn quiet() { #[test] fn log_level_info() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -59,7 +59,7 @@ fn log_level_info() { #[test] fn log_level_warn() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() @@ -79,7 +79,7 @@ fn log_level_warn() { #[test] fn log_level_error() { - utils::fixture::Fixture::new() + utils::fixture::FixtureBuilder::new() .cargo_toml("js-hello-world") .hello_world_src_lib() .build() diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index cc8d81b2..97cce656 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -375,7 +375,7 @@ fn it_errors_when_wasm_bindgen_is_not_declared() { #[test] fn it_sets_homepage_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -432,7 +432,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { #[test] fn it_sets_keywords_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -499,7 +499,7 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { #[test] fn configure_wasm_bindgen_debug_incorrectly_is_error() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .hello_world_src_lib() .file( @@ -537,7 +537,7 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { #[test] fn parse_crate_data_returns_unused_keys_in_cargo_toml() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -608,7 +608,7 @@ fn it_lists_license_files_in_files_field_of_package_json() { #[test] fn it_recurses_up_the_path_to_find_cargo_toml() { - let fixture = utils::fixture::Fixture::new(); + let fixture = utils::fixture::FixtureBuilder::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" @@ -630,7 +630,7 @@ fn it_recurses_up_the_path_to_find_cargo_toml() { #[test] fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { - let fixture = utils::fixture::Fixture::new(); + let fixture = utils::fixture::FixtureBuilder::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" diff --git a/tests/all/readme.rs b/tests/all/readme.rs index cc298a1b..1c76fd88 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -36,7 +36,7 @@ fn it_copies_a_readme_default_path() { #[test] fn it_copies_a_readme_provided_path() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -97,7 +97,7 @@ fn it_copies_a_readme_provided_path() { #[test] fn it_ignores_a_disabled_readme() { - fixture::Fixture::new() + fixture::FixtureBuilder::new() .hello_world_src_lib() .file( "Cargo.toml", diff --git a/tests/all/test.rs b/tests/all/test.rs index b37f64f6..8e33d6ad 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -163,7 +163,7 @@ fn the_headless_flag_requires_a_browser() { #[test] fn complains_about_missing_wasm_bindgen_test_dependency() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -205,7 +205,7 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { #[test] fn renamed_crate_name_works() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -249,7 +249,7 @@ fn renamed_crate_name_works() { #[test] fn cdylib_not_required() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -297,7 +297,7 @@ fn cdylib_not_required() { #[test] fn test_output_is_printed_once_in_both_stdout_and_failures() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .readme() .cargo_toml("test-output-printed-once") .hello_world_src_lib() @@ -343,7 +343,7 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { #[test] fn extra_options_is_passed_to_cargo_when_building_tests() { - let fixture = fixture::Fixture::new() + let fixture = fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 5a9c39b3..3973197a 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -29,6 +29,31 @@ pub struct FixtureBuilder { } impl FixtureBuilder { + /// Create a new test fixture in a temporary directory. + pub fn new() -> FixtureBuilder { + // Make sure that all fixtures end up sharing a target dir, and we don't + // recompile wasm-bindgen and friends many times over. + static SET_TARGET_DIR: Once = Once::new(); + let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); + SET_TARGET_DIR.call_once(|| { + env::set_var("CARGO_TARGET_DIR", &target_dir); + }); + + let root = target_dir.join("t"); + fs::create_dir_all(&root).unwrap(); + let dir = TempDir::new_in(&root).unwrap(); + let path = dir.path().join("wasm-pack"); + eprintln!("Created fixture at {}", path.display()); + let fixture = Fixture { + dir: ManuallyDrop::new(dir), + path, + }; + FixtureBuilder { + fixture, + pending_writes: Arc::new(AtomicI8::new(0)), + } + } + /// Create a file within this fixture. /// /// `path` should be a relative path to the file (relative within this @@ -219,31 +244,6 @@ impl FixtureBuilder { } impl Fixture { - /// Create a new test fixture in a temporary directory. - pub fn new() -> FixtureBuilder { - // Make sure that all fixtures end up sharing a target dir, and we don't - // recompile wasm-bindgen and friends many times over. - static SET_TARGET_DIR: Once = Once::new(); - let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); - SET_TARGET_DIR.call_once(|| { - env::set_var("CARGO_TARGET_DIR", &target_dir); - }); - - let root = target_dir.join("t"); - fs::create_dir_all(&root).unwrap(); - let dir = TempDir::new_in(&root).unwrap(); - let path = dir.path().join("wasm-pack"); - eprintln!("Created fixture at {}", path.display()); - let fixture = Fixture { - dir: ManuallyDrop::new(dir), - path, - }; - FixtureBuilder { - fixture, - pending_writes: Arc::new(AtomicI8::new(0)), - } - } - /// Install a local wasm-bindgen for this fixture. /// /// Takes care not to re-install for every fixture, but only the one time @@ -409,7 +409,7 @@ impl Drop for Fixture { } pub fn bad_cargo_toml() -> FixtureBuilder { - Fixture::new().readme().hello_world_src_lib().file( + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -427,14 +427,14 @@ pub fn bad_cargo_toml() -> FixtureBuilder { } pub fn js_hello_world() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("js-hello-world") .hello_world_src_lib() } pub fn no_cdylib() -> FixtureBuilder { - Fixture::new().readme().hello_world_src_lib().file( + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -458,11 +458,11 @@ pub fn no_cdylib() -> FixtureBuilder { } pub fn not_a_crate() -> FixtureBuilder { - Fixture::new().file("README.md", "This is not a Rust crate!") + FixtureBuilder::new().file("README.md", "This is not a Rust crate!") } pub fn serde_feature() -> FixtureBuilder { - Fixture::new().readme().hello_world_src_lib().file( + FixtureBuilder::new().readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -481,7 +481,7 @@ pub fn serde_feature() -> FixtureBuilder { } pub fn wbg_test_diff_versions() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -531,7 +531,7 @@ pub fn wbg_test_diff_versions() -> FixtureBuilder { } pub fn wbg_test_browser() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-browser") .hello_world_src_lib() @@ -552,7 +552,7 @@ pub fn wbg_test_browser() -> FixtureBuilder { } pub fn wbg_test_fail() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-fail") .hello_world_src_lib() @@ -571,7 +571,7 @@ pub fn wbg_test_fail() -> FixtureBuilder { } pub fn wbg_test_node() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("wbg-test-node") .hello_world_src_lib() @@ -590,7 +590,7 @@ pub fn wbg_test_node() -> FixtureBuilder { } pub fn transitive_dependencies() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() // main .file(PathBuf::from("main/README"), "# Main Fixture\n") .file( @@ -733,7 +733,7 @@ pub fn transitive_dependencies() -> FixtureBuilder { } pub fn single_license() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("single_license") .license() @@ -741,7 +741,7 @@ pub fn single_license() -> FixtureBuilder { } pub fn dual_license() -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml("dual_license") .wtfpl_license() @@ -750,7 +750,7 @@ pub fn dual_license() -> FixtureBuilder { } pub fn non_standard_license(license_file: &str) -> FixtureBuilder { - Fixture::new() + FixtureBuilder::new() .readme() .cargo_toml_with_license_file("dual_license", license_file) .file(license_file, "license file for test") diff --git a/tests/all/wasm_opt.rs b/tests/all/wasm_opt.rs index 27b91c34..42ab9a6b 100644 --- a/tests/all/wasm_opt.rs +++ b/tests/all/wasm_opt.rs @@ -4,7 +4,7 @@ use predicates::prelude::*; #[test] fn off_in_dev() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .cargo_toml("foo") .file("src/lib.rs", "") @@ -23,7 +23,7 @@ fn off_in_dev() { #[test] fn on_in_release() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .cargo_toml("foo") .file("src/lib.rs", "") @@ -41,7 +41,7 @@ fn on_in_release() { #[test] fn disable_in_release() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -79,7 +79,7 @@ fn disable_in_release() { #[test] fn enable_in_dev() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -120,7 +120,7 @@ fn enable_in_dev() { #[test] fn custom_args() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", @@ -158,7 +158,7 @@ fn custom_args() { #[test] fn misconfigured() { - let fixture = utils::fixture::Fixture::new() + let fixture = utils::fixture::FixtureBuilder::new() .readme() .file( "Cargo.toml", From cf4961a9e2f13ed4adf852909a8d16fa5ec7e4a0 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:37:53 +0000 Subject: [PATCH 83/85] Revert "Add FixtureBuilder for parallel file writes" This reverts commit 32c624801bd99daa05c32b94eb0d459513a61862. --- tests/all/build.rs | 48 ++++---- tests/all/generate.rs | 4 +- tests/all/license.rs | 10 +- tests/all/lockfile.rs | 16 +-- tests/all/log_level.rs | 12 +- tests/all/manifest.rs | 85 +++++++-------- tests/all/readme.rs | 11 +- tests/all/test.rs | 45 ++++---- tests/all/utils/fixture.rs | 217 +++++++++++++++++++------------------ tests/all/wasm_opt.rs | 38 +++---- tests/all/webdriver.rs | 4 +- 11 files changed, 237 insertions(+), 253 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index 25e01239..4b87e4fb 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -5,7 +5,7 @@ use std::path::Path; #[test] fn build_in_non_crate_directory_doesnt_panic() { - let fixture = utils::fixture::not_a_crate().build(); + let fixture = utils::fixture::not_a_crate(); fixture .wasm_pack() .arg("build") @@ -17,13 +17,13 @@ fn build_in_non_crate_directory_doesnt_panic() { #[test] fn it_should_build_js_hello_world_example() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture.wasm_pack().arg("build").assert().success(); } #[test] fn it_should_not_make_a_pkg_json_if_passed_no_pack() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture .wasm_pack() .arg("build") @@ -39,7 +39,8 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() { #[test] fn it_should_build_crates_in_a_workspace() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .file( "Cargo.toml", r#" @@ -75,8 +76,7 @@ fn it_should_build_crates_in_a_workspace() { pub fn hello() -> u32 { 42 } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); fixture .wasm_pack() .current_dir(&fixture.path.join("blah")) @@ -87,7 +87,8 @@ fn it_should_build_crates_in_a_workspace() { #[test] fn renamed_crate_name_works() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -115,14 +116,14 @@ fn renamed_crate_name_works() { pub fn one() -> u32 { 1 } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); fixture.wasm_pack().arg("build").assert().success(); } #[test] fn dash_dash_web_target_has_error_on_old_bindgen() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -150,8 +151,7 @@ fn dash_dash_web_target_has_error_on_old_bindgen() { pub fn one() -> u32 { 1 } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); let cmd = fixture .wasm_pack() .arg("build") @@ -170,7 +170,7 @@ fn dash_dash_web_target_has_error_on_old_bindgen() { #[test] fn it_should_build_nested_project_with_transitive_dependencies() { - let fixture = utils::fixture::transitive_dependencies().build(); + let fixture = utils::fixture::transitive_dependencies(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -182,7 +182,7 @@ fn it_should_build_nested_project_with_transitive_dependencies() { #[test] fn build_different_profiles() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture.install_local_wasm_bindgen(); for profile in ["--dev", "--debug", "--profiling", "--release"] @@ -201,7 +201,8 @@ fn build_different_profiles() { #[test] fn build_with_and_without_wasm_bindgen_debug() { for debug in [true, false].iter().cloned() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -250,8 +251,7 @@ fn build_with_and_without_wasm_bindgen_debug() { } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); fixture .wasm_pack() @@ -275,7 +275,7 @@ fn build_with_and_without_wasm_bindgen_debug() { #[test] fn build_with_arbitrary_cargo_options() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -287,7 +287,7 @@ fn build_with_arbitrary_cargo_options() { #[test] fn build_no_install() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -300,7 +300,7 @@ fn build_no_install() { #[test] fn build_force() { - let fixture = utils::fixture::js_hello_world().build(); + let fixture = utils::fixture::js_hello_world(); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() @@ -313,7 +313,7 @@ fn build_force() { #[test] fn build_from_new() { - let fixture = utils::fixture::not_a_crate().build(); + let fixture = utils::fixture::not_a_crate(); let name = "generated-project"; fixture.wasm_pack().arg("new").arg(name).assert().success(); let project_location = fixture.path.join(&name); @@ -327,7 +327,8 @@ fn build_from_new() { #[test] fn build_crates_with_same_names() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "somename1/Cargo.toml", @@ -381,8 +382,7 @@ fn build_crates_with_same_names() { 0 } "#, - ) - .build(); + ); fixture.install_local_wasm_bindgen(); fixture .wasm_pack() diff --git a/tests/all/generate.rs b/tests/all/generate.rs index 32b1dd9b..b2f695e1 100644 --- a/tests/all/generate.rs +++ b/tests/all/generate.rs @@ -3,14 +3,14 @@ use assert_cmd::prelude::*; #[test] fn new_with_no_name_errors() { - let fixture = utils::fixture::not_a_crate().build(); + let fixture = utils::fixture::not_a_crate(); fixture.install_local_cargo_generate(); fixture.wasm_pack().arg("new").assert().failure(); } #[test] fn new_with_name_succeeds() { - let fixture = utils::fixture::not_a_crate().build(); + let fixture = utils::fixture::not_a_crate(); fixture.install_local_cargo_generate(); fixture .wasm_pack() diff --git a/tests/all/license.rs b/tests/all/license.rs index bb4b612a..ae0a6a7e 100644 --- a/tests/all/license.rs +++ b/tests/all/license.rs @@ -9,7 +9,7 @@ use wasm_pack::manifest::CrateData; #[test] fn it_copies_a_license_default_path() { - let fixture = fixture::single_license().build(); + let fixture = fixture::single_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -34,7 +34,7 @@ fn it_copies_a_license_default_path() { #[test] fn it_copies_a_license_provided_path() { - let fixture = fixture::single_license().build(); + let fixture = fixture::single_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -57,7 +57,7 @@ fn it_copies_a_license_provided_path() { #[test] fn it_copies_all_licenses_default_path() { - let fixture = fixture::dual_license().build(); + let fixture = fixture::dual_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -92,7 +92,7 @@ fn it_copies_all_licenses_default_path() { #[test] fn it_copies_all_licenses_provided_path() { - let fixture = fixture::dual_license().build(); + let fixture = fixture::dual_license(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); @@ -128,7 +128,7 @@ fn it_copies_all_licenses_provided_path() { #[test] fn it_copies_a_non_standard_license_provided_path() { let license_file = "NON-STANDARD-LICENSE"; - let fixture = fixture::non_standard_license(license_file).build(); + let fixture = fixture::non_standard_license(license_file); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None); diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index d8318834..d0cef299 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -4,7 +4,7 @@ use wasm_pack::manifest::CrateData; #[test] fn it_gets_wasm_bindgen_version() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); @@ -13,7 +13,7 @@ fn it_gets_wasm_bindgen_version() { #[test] fn it_gets_wasm_bindgen_test_version() { - let fixture = fixture::wbg_test_node().build(); + let fixture = fixture::wbg_test_node(); fixture.cargo_check(); let data = CrateData::new(&fixture.path, None).unwrap(); let [package] = lockfile::Package::get(&data, ["wasm-bindgen-test"]).unwrap(); @@ -22,7 +22,8 @@ fn it_gets_wasm_bindgen_test_version() { #[test] fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .file( "Cargo.toml", r#" @@ -57,8 +58,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[wasm_bindgen] pub fn hello() -> u32 { 42 } "#, - ) - .build(); + ); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("blah"), None).unwrap(); let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); @@ -67,7 +67,8 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { #[test] fn it_gets_wasm_bindgen_version_from_dependencies() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .file( "Cargo.toml", r#" @@ -125,8 +126,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { extern crate child; pub use child::*; "#, - ) - .build(); + ); fixture.cargo_check(); let data = CrateData::new(&fixture.path.join("parent"), None).unwrap(); let [package] = lockfile::Package::get(&data, ["wasm-bindgen"]).unwrap(); diff --git a/tests/all/log_level.rs b/tests/all/log_level.rs index f58f304d..ec95378a 100644 --- a/tests/all/log_level.rs +++ b/tests/all/log_level.rs @@ -28,10 +28,9 @@ fn matches_cargo() -> impl Predicate + PredicateReflection { #[test] fn quiet() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() - .build() .wasm_pack() .arg("--quiet") .arg("build") @@ -43,10 +42,9 @@ fn quiet() { #[test] fn log_level_info() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() - .build() .wasm_pack() .arg("--log-level") .arg("info") @@ -59,10 +57,9 @@ fn log_level_info() { #[test] fn log_level_warn() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() - .build() .wasm_pack() .arg("--log-level") .arg("warn") @@ -79,10 +76,9 @@ fn log_level_warn() { #[test] fn log_level_error() { - utils::fixture::FixtureBuilder::new() + utils::fixture::Fixture::new() .cargo_toml("js-hello-world") .hello_world_src_lib() - .build() .wasm_pack() .arg("--log-level") .arg("error") diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 97cce656..abf0e759 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -17,7 +17,7 @@ fn it_gets_the_crate_name_default_path() { #[test] fn it_gets_the_crate_name_provided_path() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert_eq!(crate_data.crate_name(), "js_hello_world"); } @@ -40,7 +40,7 @@ fn it_gets_the_name_prefix_passed_from_cli() { #[test] fn it_checks_has_cdylib_default_path() { - let fixture = fixture::no_cdylib().build(); + let fixture = fixture::no_cdylib(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -49,7 +49,7 @@ fn it_checks_has_cdylib_default_path() { #[test] fn it_checks_has_cdylib_provided_path() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -58,14 +58,14 @@ fn it_checks_has_cdylib_provided_path() { #[test] fn it_checks_has_cdylib_wrong_crate_type() { - let fixture = fixture::bad_cargo_toml().build(); + let fixture = fixture::bad_cargo_toml(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert!(crate_data.check_crate_config().is_err()); } #[test] fn it_recognizes_a_map_during_depcheck() { - let fixture = fixture::serde_feature().build(); + let fixture = fixture::serde_feature(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -74,7 +74,7 @@ fn it_recognizes_a_map_during_depcheck() { #[test] fn it_creates_a_package_json_default_path() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -113,7 +113,7 @@ fn it_creates_a_package_json_default_path() { #[test] fn it_creates_a_package_json_provided_path() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -142,7 +142,7 @@ fn it_creates_a_package_json_provided_path() { #[test] fn it_creates_a_package_json_provided_path_with_scope() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -171,7 +171,7 @@ fn it_creates_a_package_json_provided_path_with_scope() { #[test] fn it_creates_a_pkg_json_with_correct_files_on_node() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -205,7 +205,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { #[test] fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -239,7 +239,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { #[test] fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, Some("index".to_owned())).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -271,7 +271,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() { #[test] fn it_creates_a_pkg_json_in_out_dir() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("./custom/out"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -286,7 +286,7 @@ fn it_creates_a_pkg_json_in_out_dir() { #[test] fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -319,7 +319,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { #[test] fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); @@ -367,7 +367,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() { #[test] fn it_errors_when_wasm_bindgen_is_not_declared() { - let fixture = fixture::bad_cargo_toml().build(); + let fixture = fixture::bad_cargo_toml(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); assert!(crate_data.check_crate_config().is_err()); } @@ -375,11 +375,10 @@ fn it_errors_when_wasm_bindgen_is_not_declared() { #[test] fn it_sets_homepage_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::FixtureBuilder::new() - .hello_world_src_lib() - .file( - "Cargo.toml", - r#" + let fixture = utils::fixture::Fixture::new(); + fixture.hello_world_src_lib().file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -398,8 +397,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { [dev-dependencies] wasm-bindgen-test = "=0.2" "#, - ) - .build(); + ); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -416,7 +414,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { ); // When 'homepage' is unavailable - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -432,11 +430,10 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { #[test] fn it_sets_keywords_field_if_available_in_cargo_toml() { // When 'homepage' is available - let fixture = utils::fixture::FixtureBuilder::new() - .hello_world_src_lib() - .file( - "Cargo.toml", - r#" + let fixture = utils::fixture::Fixture::new(); + fixture.hello_world_src_lib().file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -455,8 +452,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { [dev-dependencies] wasm-bindgen-test = "=0.2" "#, - ) - .build(); + ); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -475,7 +471,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { ); // When 'keywords' is unavailable - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -490,7 +486,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() { #[test] fn it_does_not_error_when_wasm_bindgen_is_declared() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -499,12 +495,10 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { #[test] fn configure_wasm_bindgen_debug_incorrectly_is_error() { - let fixture = utils::fixture::FixtureBuilder::new() - .readme() - .hello_world_src_lib() - .file( - "Cargo.toml", - r#" + let fixture = utils::fixture::Fixture::new(); + fixture.readme().hello_world_src_lib().file( + "Cargo.toml", + r#" [package] authors = ["The wasm-pack developers"] description = "so awesome rust+wasm package" @@ -522,8 +516,7 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { [package.metadata.wasm-pack.profile.dev.wasm-bindgen] debug-js-glue = "not a boolean" "#, - ) - .build(); + ); fixture .wasm_pack() .arg("build") @@ -537,7 +530,8 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() { #[test] fn parse_crate_data_returns_unused_keys_in_cargo_toml() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -562,8 +556,7 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { "#, ) .hello_world_src_lib() - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); fixture .wasm_pack() .arg("build") @@ -578,7 +571,7 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { #[test] fn it_lists_license_files_in_files_field_of_package_json() { - let fixture = fixture::dual_license().build(); + let fixture = fixture::dual_license(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap(); @@ -608,7 +601,7 @@ fn it_lists_license_files_in_files_field_of_package_json() { #[test] fn it_recurses_up_the_path_to_find_cargo_toml() { - let fixture = utils::fixture::FixtureBuilder::new(); + let fixture = utils::fixture::Fixture::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" @@ -630,7 +623,7 @@ fn it_recurses_up_the_path_to_find_cargo_toml() { #[test] fn it_doesnt_recurse_up_the_path_to_find_cargo_toml_when_default() { - let fixture = utils::fixture::FixtureBuilder::new(); + let fixture = utils::fixture::Fixture::new(); fixture.hello_world_src_lib().file( "Cargo.toml", r#" diff --git a/tests/all/readme.rs b/tests/all/readme.rs index 1c76fd88..4b233067 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -11,7 +11,7 @@ use wasm_pack::readme; #[test] fn it_copies_a_readme_default_path() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path, None).unwrap(); @@ -36,7 +36,8 @@ fn it_copies_a_readme_default_path() { #[test] fn it_copies_a_readme_provided_path() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .hello_world_src_lib() .file( "Cargo.toml", @@ -71,8 +72,7 @@ fn it_copies_a_readme_provided_path() { # Fixture! > an example rust -> wasm project "#, - ) - .build(); + ); let crate_docs_dir = fixture.path.join("docs"); let out_dir = fixture.path.join("pkg"); @@ -97,7 +97,7 @@ fn it_copies_a_readme_provided_path() { #[test] fn it_ignores_a_disabled_readme() { - fixture::FixtureBuilder::new() + fixture::Fixture::new() .hello_world_src_lib() .file( "Cargo.toml", @@ -126,7 +126,6 @@ fn it_ignores_a_disabled_readme() { "#, ) .license() - .build() .wasm_pack() .arg("build") .assert() diff --git a/tests/all/test.rs b/tests/all/test.rs index 8e33d6ad..c5bba4e6 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -5,7 +5,7 @@ use std::env; #[test] fn it_can_run_node_tests() { - let fixture = fixture::wbg_test_node().build(); + let fixture = fixture::wbg_test_node(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -18,7 +18,7 @@ fn it_can_run_node_tests() { #[test] fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { - let fixture = fixture::wbg_test_diff_versions().build(); + let fixture = fixture::wbg_test_diff_versions(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -38,7 +38,7 @@ fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { all(target_os = "windows", target_arch = "x86_64") ))] fn it_can_run_browser_tests() { - let fixture = fixture::wbg_test_browser().build(); + let fixture = fixture::wbg_test_browser(); fixture.install_local_wasm_bindgen(); let firefox = cfg!(any( @@ -87,7 +87,7 @@ fn it_can_run_browser_tests() { #[test] fn it_can_run_failing_tests() { - let fixture = fixture::wbg_test_fail().build(); + let fixture = fixture::wbg_test_fail(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -111,7 +111,7 @@ fn it_can_run_failing_tests() { all(target_os = "windows", target_arch = "x86_64") ))] fn it_can_find_a_webdriver_on_path() { - let fixture = fixture::wbg_test_browser().build(); + let fixture = fixture::wbg_test_browser(); let local_geckodriver = fixture.install_local_geckodriver(); let local_wasm_bindgen = fixture.install_local_wasm_bindgen(); @@ -135,7 +135,7 @@ fn it_can_find_a_webdriver_on_path() { #[test] fn it_requires_node_or_a_browser() { - let fixture = fixture::wbg_test_node().build(); + let fixture = fixture::wbg_test_node(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -148,7 +148,7 @@ fn it_requires_node_or_a_browser() { #[test] fn the_headless_flag_requires_a_browser() { - let fixture = fixture::wbg_test_node().build(); + let fixture = fixture::wbg_test_node(); fixture.install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture @@ -163,7 +163,8 @@ fn the_headless_flag_requires_a_browser() { #[test] fn complains_about_missing_wasm_bindgen_test_dependency() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -187,8 +188,7 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { "#, ) .hello_world_src_lib() - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -205,7 +205,8 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { #[test] fn renamed_crate_name_works() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -236,8 +237,7 @@ fn renamed_crate_name_works() { pub fn one() -> u32 { 1 } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -249,7 +249,8 @@ fn renamed_crate_name_works() { #[test] fn cdylib_not_required() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -284,8 +285,7 @@ fn cdylib_not_required() { } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() @@ -297,7 +297,8 @@ fn cdylib_not_required() { #[test] fn test_output_is_printed_once_in_both_stdout_and_failures() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .readme() .cargo_toml("test-output-printed-once") .hello_world_src_lib() @@ -322,8 +323,7 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { } "#, ) - .build(); - fixture.install_local_wasm_bindgen(); + .install_local_wasm_bindgen(); let _lock = fixture.lock(); // there will be only one log in stdout, and only one log in failures @@ -343,7 +343,8 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { #[test] fn extra_options_is_passed_to_cargo_when_building_tests() { - let fixture = fixture::FixtureBuilder::new() + let fixture = fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -388,8 +389,8 @@ fn extra_options_is_passed_to_cargo_when_building_tests() { panic!("This should be filtered from test execution."); } "#, - ).build(); - fixture.install_local_wasm_bindgen(); + ) + .install_local_wasm_bindgen(); let _lock = fixture.lock(); fixture .wasm_pack() diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 3973197a..188a460a 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -5,8 +5,6 @@ use std::fs; use std::mem::ManuallyDrop; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::sync::atomic::{AtomicI8, Ordering}; -use std::sync::Arc; use std::sync::{MutexGuard, Once}; use std::thread; use tempfile::TempDir; @@ -22,15 +20,9 @@ pub struct Fixture { pub path: PathBuf, } -/// A builder for `Fixture'. -pub struct FixtureBuilder { - fixture: Fixture, - pending_writes: Arc, -} - -impl FixtureBuilder { +impl Fixture { /// Create a new test fixture in a temporary directory. - pub fn new() -> FixtureBuilder { + pub fn new() -> Fixture { // Make sure that all fixtures end up sharing a target dir, and we don't // recompile wasm-bindgen and friends many times over. static SET_TARGET_DIR: Once = Once::new(); @@ -44,13 +36,9 @@ impl FixtureBuilder { let dir = TempDir::new_in(&root).unwrap(); let path = dir.path().join("wasm-pack"); eprintln!("Created fixture at {}", path.display()); - let fixture = Fixture { + Fixture { dir: ManuallyDrop::new(dir), path, - }; - FixtureBuilder { - fixture, - pending_writes: Arc::new(AtomicI8::new(0)), } } @@ -60,31 +48,18 @@ impl FixtureBuilder { /// fixture's path). /// /// The `contents` are written to the file. - pub fn file, C: AsRef<[u8]> + Send + 'static>( - self, - path: P, - contents: C, - ) -> Self { + pub fn file, C: AsRef<[u8]>>(&self, path: P, contents: C) -> &Self { assert!(path.as_ref().is_relative()); - let path = self.fixture.path.join(path); - self.pending_writes - .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |n| n.checked_add(1)) - .unwrap(); - let pending_writes = Arc::clone(&self.pending_writes); - std::thread::spawn(move || { - if let Some(parent) = path.parent() { - fs::create_dir_all(parent).unwrap(); - } - fs::write(path, contents).unwrap(); - pending_writes - .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |n| n.checked_sub(1)) - .unwrap(); - }); + let path = self.path.join(path); + if let Some(parent) = path.parent() { + fs::create_dir_all(parent).unwrap(); + } + fs::write(path, contents).unwrap(); self } /// Add a generic `README.md` file to the fixture. - pub fn readme(self) -> Self { + pub fn readme(&self) -> &Self { self.file( "README.md", r#" @@ -95,7 +70,7 @@ impl FixtureBuilder { } /// Add `LICENSE` file to the fixture. - pub fn license(self) -> Self { + pub fn license(&self) -> &Self { self.file( "LICENSE", r#" @@ -105,7 +80,7 @@ impl FixtureBuilder { } /// Add `WTFPL LICENSE` file to the fixture. - pub fn wtfpl_license(self) -> Self { + pub fn wtfpl_license(&self) -> &Self { self.file( "LICENSE-WTFPL", r#" @@ -127,7 +102,7 @@ impl FixtureBuilder { } /// Add `MIT LICENSE` file to the fixture. - pub fn mit_license(self) -> Self { + pub fn mit_license(&self) -> &Self { self.file( "LICENSE-MIT", r#" @@ -147,10 +122,10 @@ impl FixtureBuilder { /// ["cdylib"]`. /// /// `name` is the crate's name. - pub fn cargo_toml(self, name: &str) -> Self { + pub fn cargo_toml(&self, name: &str) -> &Self { self.file( "Cargo.toml", - format!( + &format!( r#" [package] authors = ["The wasm-pack developers"] @@ -185,10 +160,10 @@ impl FixtureBuilder { /// /// `name` is the crate's name. /// `license_file` is license file path - pub fn cargo_toml_with_license_file(self, name: &str, license_file: &str) -> Self { + pub fn cargo_toml_with_license_file(&self, name: &str, license_file: &str) -> &Self { self.file( "Cargo.toml", - format!( + &format!( r#" [package] authors = ["The wasm-pack developers"] @@ -213,7 +188,7 @@ impl FixtureBuilder { } /// Add a `src/lib.rs` file that contains a "hello world" program. - pub fn hello_world_src_lib(self) -> Self { + pub fn hello_world_src_lib(&self) -> &Self { self.file( "src/lib.rs", r#" @@ -236,14 +211,6 @@ impl FixtureBuilder { ) } - /// Wait for files to be written, then return the fixture. - pub fn build(self) -> Fixture { - while self.pending_writes.load(Ordering::SeqCst) != 0 {} - self.fixture - } -} - -impl Fixture { /// Install a local wasm-bindgen for this fixture. /// /// Takes care not to re-install for every fixture, but only the one time @@ -408,8 +375,9 @@ impl Drop for Fixture { } } -pub fn bad_cargo_toml() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( +pub fn bad_cargo_toml() -> Fixture { + let fixture = Fixture::new(); + fixture.readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -423,18 +391,22 @@ pub fn bad_cargo_toml() -> FixtureBuilder { [dependencies] # Note: no wasm-bindgen dependency! "#, - ) + ); + fixture } -pub fn js_hello_world() -> FixtureBuilder { - FixtureBuilder::new() +pub fn js_hello_world() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("js-hello-world") - .hello_world_src_lib() + .hello_world_src_lib(); + fixture } -pub fn no_cdylib() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( +pub fn no_cdylib() -> Fixture { + let fixture = Fixture::new(); + fixture.readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -454,15 +426,19 @@ pub fn no_cdylib() -> FixtureBuilder { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ) + ); + fixture } -pub fn not_a_crate() -> FixtureBuilder { - FixtureBuilder::new().file("README.md", "This is not a Rust crate!") +pub fn not_a_crate() -> Fixture { + let fixture = Fixture::new(); + fixture.file("README.md", "This is not a Rust crate!"); + fixture } -pub fn serde_feature() -> FixtureBuilder { - FixtureBuilder::new().readme().hello_world_src_lib().file( +pub fn serde_feature() -> Fixture { + let fixture = Fixture::new(); + fixture.readme().hello_world_src_lib().file( "Cargo.toml", r#" [package] @@ -477,11 +453,13 @@ pub fn serde_feature() -> FixtureBuilder { version = "^0.2" features = ["serde-serialize"] "#, - ) + ); + fixture } -pub fn wbg_test_diff_versions() -> FixtureBuilder { - FixtureBuilder::new() +pub fn wbg_test_diff_versions() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -527,11 +505,13 @@ pub fn wbg_test_diff_versions() -> FixtureBuilder { assert_eq!(wbg_test_diff_versions::one(), 1); } "#, - ) + ); + fixture } -pub fn wbg_test_browser() -> FixtureBuilder { - FixtureBuilder::new() +pub fn wbg_test_browser() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("wbg-test-browser") .hello_world_src_lib() @@ -548,11 +528,13 @@ pub fn wbg_test_browser() -> FixtureBuilder { assert_eq!(1, 1); } "#, - ) + ); + fixture } -pub fn wbg_test_fail() -> FixtureBuilder { - FixtureBuilder::new() +pub fn wbg_test_fail() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("wbg-test-fail") .hello_world_src_lib() @@ -567,11 +549,13 @@ pub fn wbg_test_fail() -> FixtureBuilder { assert_eq!(1, 2); } "#, - ) + ); + fixture } -pub fn wbg_test_node() -> FixtureBuilder { - FixtureBuilder::new() +pub fn wbg_test_node() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("wbg-test-node") .hello_world_src_lib() @@ -586,14 +570,14 @@ pub fn wbg_test_node() -> FixtureBuilder { assert_eq!(1, 1); } "#, - ) + ); + fixture } -pub fn transitive_dependencies() -> FixtureBuilder { - FixtureBuilder::new() - // main - .file(PathBuf::from("main/README"), "# Main Fixture\n") - .file( +pub fn transitive_dependencies() -> Fixture { + fn project_main_fixture(fixture: &mut Fixture) { + fixture.file(PathBuf::from("main/README"), "# Main Fixture\n"); + fixture.file( PathBuf::from("main/Cargo.toml"), r#" [package] @@ -615,8 +599,8 @@ pub fn transitive_dependencies() -> FixtureBuilder { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ) - .file( + ); + fixture.file( PathBuf::from("main/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -635,13 +619,15 @@ pub fn transitive_dependencies() -> FixtureBuilder { alert(&format!("Hello, {}!", name)); } "#, - ) - // a - .file( + ); + } + + fn project_a_fixture(fixture: &mut Fixture) { + fixture.file( PathBuf::from("project_a/README"), "# Project Alpha Fixture\n", - ) - .file( + ); + fixture.file( PathBuf::from("project_a/Cargo.toml"), r#" [package] @@ -662,8 +648,8 @@ pub fn transitive_dependencies() -> FixtureBuilder { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ) - .file( + ); + fixture.file( PathBuf::from("project_a/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -683,13 +669,15 @@ pub fn transitive_dependencies() -> FixtureBuilder { alert(&format!("Hello, {}!", name)); } "#, - ) - // b - .file( + ); + } + + fn project_b_fixture(fixture: &mut Fixture) { + fixture.file( PathBuf::from("project_b/README"), "# Project Beta Fixture\n", - ) - .file( + ); + fixture.file( PathBuf::from("project_b/Cargo.toml"), r#" [package] @@ -709,8 +697,8 @@ pub fn transitive_dependencies() -> FixtureBuilder { [dev-dependencies] wasm-bindgen-test = "0.3" "#, - ) - .file( + ); + fixture.file( PathBuf::from("project_b/src/lib.rs"), r#" extern crate wasm_bindgen; @@ -729,30 +717,43 @@ pub fn transitive_dependencies() -> FixtureBuilder { alert(&format!("Hello, {}!", name)); } "#, - ) + ); + } + + let mut fixture = Fixture::new(); + project_b_fixture(&mut fixture); + project_a_fixture(&mut fixture); + project_main_fixture(&mut fixture); + fixture } -pub fn single_license() -> FixtureBuilder { - FixtureBuilder::new() +pub fn single_license() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("single_license") .license() - .hello_world_src_lib() + .hello_world_src_lib(); + fixture } -pub fn dual_license() -> FixtureBuilder { - FixtureBuilder::new() +pub fn dual_license() -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml("dual_license") .wtfpl_license() .mit_license() - .hello_world_src_lib() + .hello_world_src_lib(); + fixture } -pub fn non_standard_license(license_file: &str) -> FixtureBuilder { - FixtureBuilder::new() +pub fn non_standard_license(license_file: &str) -> Fixture { + let fixture = Fixture::new(); + fixture .readme() .cargo_toml_with_license_file("dual_license", license_file) .file(license_file, "license file for test") - .hello_world_src_lib() + .hello_world_src_lib(); + fixture } diff --git a/tests/all/wasm_opt.rs b/tests/all/wasm_opt.rs index 42ab9a6b..68c0dc9b 100644 --- a/tests/all/wasm_opt.rs +++ b/tests/all/wasm_opt.rs @@ -4,11 +4,8 @@ use predicates::prelude::*; #[test] fn off_in_dev() { - let fixture = utils::fixture::FixtureBuilder::new() - .readme() - .cargo_toml("foo") - .file("src/lib.rs", "") - .build(); + let fixture = utils::fixture::Fixture::new(); + fixture.readme().cargo_toml("foo").file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -23,11 +20,8 @@ fn off_in_dev() { #[test] fn on_in_release() { - let fixture = utils::fixture::FixtureBuilder::new() - .readme() - .cargo_toml("foo") - .file("src/lib.rs", "") - .build(); + let fixture = utils::fixture::Fixture::new(); + fixture.readme().cargo_toml("foo").file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -41,7 +35,8 @@ fn on_in_release() { #[test] fn disable_in_release() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -64,8 +59,7 @@ fn disable_in_release() { wasm-opt = false "#, ) - .file("src/lib.rs", "") - .build(); + .file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -79,7 +73,8 @@ fn disable_in_release() { #[test] fn enable_in_dev() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -102,8 +97,7 @@ fn enable_in_dev() { wasm-opt = true "#, ) - .file("src/lib.rs", "") - .build(); + .file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -120,7 +114,8 @@ fn enable_in_dev() { #[test] fn custom_args() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -143,8 +138,7 @@ fn custom_args() { wasm-opt = ['--not-accepted-argument'] "#, ) - .file("src/lib.rs", "") - .build(); + .file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); @@ -158,7 +152,8 @@ fn custom_args() { #[test] fn misconfigured() { - let fixture = utils::fixture::FixtureBuilder::new() + let fixture = utils::fixture::Fixture::new(); + fixture .readme() .file( "Cargo.toml", @@ -181,8 +176,7 @@ fn misconfigured() { wasm-opt = 32 "#, ) - .file("src/lib.rs", "") - .build(); + .file("src/lib.rs", ""); fixture.install_local_wasm_bindgen(); fixture.install_wasm_opt(); diff --git a/tests/all/webdriver.rs b/tests/all/webdriver.rs index eb5d0740..3cd93c94 100644 --- a/tests/all/webdriver.rs +++ b/tests/all/webdriver.rs @@ -10,7 +10,7 @@ use wasm_pack::test::webdriver; all(target_os = "windows", target_arch = "x86_64") ))] fn can_install_chromedriver() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let cache = Cache::at(&fixture.path); assert!(webdriver::install_chromedriver(&cache, true).is_ok()); } @@ -25,7 +25,7 @@ fn can_install_chromedriver() { all(target_os = "windows", target_arch = "x86_64") ))] fn can_install_geckodriver() { - let fixture = fixture::js_hello_world().build(); + let fixture = fixture::js_hello_world(); let cache = Cache::at(&fixture.path); assert!(webdriver::install_geckodriver(&cache, true).is_ok()); } From d493270bbce6877cf81ca29f73e40e259cbb19d1 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:51:29 +0000 Subject: [PATCH 84/85] Reduce use statement diff --- src/lockfile.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lockfile.rs b/src/lockfile.rs index 053eba23..d81a9757 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -2,8 +2,9 @@ #![allow(clippy::new_ret_no_self)] +use std::borrow::Cow; +use std::fs; use std::path::PathBuf; -use std::{borrow::Cow, fs}; use crate::manifest::CrateData; use anyhow::{anyhow, bail, Context, Result}; From 406ef375636de095d543ad913e7a5ee8d0cc4f8d Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 17 Jun 2023 02:55:56 +0000 Subject: [PATCH 85/85] Fix my botched merge conflict resolution --- tests/all/readme.rs | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/tests/all/readme.rs b/tests/all/readme.rs index 1778b2b5..cefb01f0 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -51,41 +51,3 @@ fn it_copies_a_readme_provided_path() { let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap(); assert_eq!(crate_readme, pkg_readme); } - -#[test] -fn it_ignores_a_disabled_readme() { - fixture::Fixture::new() - .hello_world_src_lib() - .file( - "Cargo.toml", - r#" - [package] - authors = ["The wasm-pack developers"] - description = "so awesome rust+wasm package" - name = "js-hello-world" - readme = false - repository = "https://github.com/rustwasm/wasm-pack.git" - version = "0.1.0" - - [lib] - crate-type = ["cdylib"] - - [dependencies] - # Note that this uses and `=` dependency because there are - # various tests which assert that the version of wasm - # bindgen downloaded is what we expect, and if `=` is - # removed then it will download whatever the newest version - # of wasm-bindgen is which may not be what's listed here. - wasm-bindgen = "=0.2.74" - - [dev-dependencies] - wasm-bindgen-test = "0.3" - "#, - ) - .license() - .wasm_pack() - .arg("build") - .assert() - .success() - .stderr(predicates::str::contains("origin crate has no README").not()); -} \ No newline at end of file