-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use libraries instead of locally installed binaries for Cargo Generate and Wasm Opt #429
base: main
Are you sure you want to change the base?
Changes from 7 commits
28e8dbd
aa78d85
e6f7cc5
6ed80ae
64b862c
3990eba
fa057df
1a5b295
b15cd29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,20 @@ use crate::ext::sync::{wait_interruptible, CommandResult}; | |
use crate::ext::{fs, PathBufExt}; | ||
use crate::signal::{Interrupt, Outcome, Product}; | ||
use crate::{ | ||
ext::{ | ||
anyhow::{Context, Result}, | ||
exe::Exe, | ||
}, | ||
ext::anyhow::{Context, Result}, | ||
logger::GRAY, | ||
}; | ||
use anyhow::Ok; | ||
use camino::Utf8Path; | ||
use std::sync::Arc; | ||
use swc::config::IsModule; | ||
use swc::JsMinifyExtras; | ||
use swc::{config::JsMinifyOptions, try_with_handler, BoolOrDataConfig}; | ||
use swc_common::{FileName, SourceMap, GLOBALS}; | ||
use tokio::process::Child; | ||
use tokio::{process::Command, sync::broadcast, task::JoinHandle}; | ||
use tokio::{process::Command, task::JoinHandle}; | ||
use wasm_bindgen_cli_support::Bindgen; | ||
use wasm_opt::OptimizationOptions; | ||
|
||
pub async fn front( | ||
proj: &Arc<Project>, | ||
|
@@ -106,7 +105,6 @@ pub fn build_cargo_front_cmd( | |
|
||
async fn bindgen(proj: &Project) -> Result<Outcome<Product>> { | ||
let wasm_file = &proj.lib.wasm_file; | ||
let interrupt = Interrupt::subscribe_any(); | ||
|
||
log::info!("Front generating JS/WASM with wasm-bindgen"); | ||
|
||
|
@@ -153,11 +151,7 @@ async fn bindgen(proj: &Project) -> Result<Outcome<Product>> { | |
.dot()?; | ||
|
||
if proj.release { | ||
match optimize(&wasm_file.dest, interrupt).await.dot()? { | ||
CommandResult::Interrupted => return Ok(Outcome::Stopped), | ||
CommandResult::Failure(_) => return Ok(Outcome::Failed), | ||
_ => {} | ||
} | ||
optimize(&wasm_file.dest)?; | ||
} | ||
|
||
let wasm_optimize_end_time = tokio::time::Instant::now(); | ||
|
@@ -193,18 +187,10 @@ async fn bindgen(proj: &Project) -> Result<Outcome<Product>> { | |
Ok(Outcome::Success(Product::Front)) | ||
} | ||
|
||
async fn optimize( | ||
file: &Utf8Path, | ||
interrupt: broadcast::Receiver<()>, | ||
) -> Result<CommandResult<()>> { | ||
let wasm_opt = Exe::WasmOpt.get().await.dot()?; | ||
|
||
let args = [file.as_str(), "-Oz", "-o", file.as_str()]; | ||
let process = Command::new(wasm_opt) | ||
.args(args) | ||
.spawn() | ||
.context("Could not spawn command")?; | ||
wait_interruptible("wasm-opt", process, interrupt).await | ||
fn optimize(file: &Utf8Path) -> Result<()> { | ||
OptimizationOptions::new_optimize_for_size_aggressively() | ||
.run(file, file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how to make this interruptable since |
||
.dot() | ||
} | ||
|
||
fn minify<JS: AsRef<str>>(js: JS) -> Result<String> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ pub async fn compile_tailwind(proj: &Project, tw_conf: &TailwindConfig) -> Resul | |
create_default_tailwind_config(tw_conf).await?; | ||
} | ||
|
||
let (line, process) = tailwind_process(&proj, "tailwindcss", tw_conf).await?; | ||
let (line, process) = tailwind_process(proj, "tailwindcss", tw_conf).await?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to fix a Clippy warning. |
||
|
||
match wait_piped_interruptible("Tailwind", process, Interrupt::subscribe_any()).await? { | ||
CommandResult::Success(output) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy was giving warnings that the earliest rust version to support
is_none_or
(which is used in this project) is 1.82.0.