speed up incremental cli builds by making wasm-opt optional (#2720)
* speed up incremental builds by making wasm-opt optional
This commit is contained in:
1 parent
6558fd95a2
commit
8aa07b0a75
3 files changed
+53
-45
No files matched your search
@@ -98,7 +98,7 @@ jobs:
|
|||||||
checksum: sha256
|
checksum: sha256
|
||||||
manifest_path: packages/cli/Cargo.toml
|
manifest_path: packages/cli/Cargo.toml
|
||||||
ref: refs/tags/${{ env.RELEASE_POST }}
|
ref: refs/tags/${{ env.RELEASE_POST }}
|
||||||
|
features: wasm-opt
|
||||||
|
|
||||||
# todo: these things
|
# todo: these things
|
||||||
# Run benchmarks, which we'll use to display on the website
|
# Run benchmarks, which we'll use to display on the website
|
||||||
@@ -146,13 +146,12 @@ jobs:
|
|||||||
# # todo: actually just publish!
|
# # todo: actually just publish!
|
||||||
# # cargo workspaces publish -y ${{ github.event.inputs.semver }}
|
# # cargo workspaces publish -y ${{ github.event.inputs.semver }}
|
||||||
|
|
||||||
# this will be more useful when we publish the website with updated docs
|
# this will be more useful when we publish the website with updated docs
|
||||||
# Build the docs.rs docs and publish them to the website under the right folder
|
# Build the docs.rs docs and publish them to the website under the right folder
|
||||||
# v0.4.x -> docs/0.4
|
# v0.4.x -> docs/0.4
|
||||||
# v0.5.x -> docs/0.5 etc
|
# v0.5.x -> docs/0.5 etc
|
||||||
# main -> docs/nightly
|
# main -> docs/nightly
|
||||||
# strip the v from the channel, and the .x from the end, and replace main with nightly
|
# strip the v from the channel, and the .x from the end, and replace main with nightly
|
||||||
# - name: determine docs folder by channel
|
# - name: determine docs folder by channel
|
||||||
# id: determine_docs_folder
|
# id: determine_docs_folder
|
||||||
# run: echo "::set-output name=folder::$(echo ${{ github.event.inputs.channel }} | sed 's/v//g' | sed 's/\.x//g' | sed 's/main/nightly/g')"
|
# run: echo "::set-output name=folder::$(echo ${{ github.event.inputs.channel }} | sed 's/v//g' | sed 's/\.x//g' | sed 's/main/nightly/g')"
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ env_logger = "0.11.3"
|
|||||||
tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter"] }
|
||||||
console-subscriber = { version = "0.3.0", optional = true }
|
console-subscriber = { version = "0.3.0", optional = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
wasm-opt = "0.116.1"
|
wasm-opt = { version = "0.116.1", optional = true }
|
||||||
ratatui = { version = "0.27.0", features = ["crossterm", "unstable"] }
|
ratatui = { version = "0.27.0", features = ["crossterm", "unstable"] }
|
||||||
crossterm = { version = "0.27.0", features = ["event-stream"] }
|
crossterm = { version = "0.27.0", features = ["event-stream"] }
|
||||||
ansi-to-tui = "=5.0.0-rc.1"
|
ansi-to-tui = "=5.0.0-rc.1"
|
||||||
@@ -118,6 +118,9 @@ default = []
|
|||||||
plugin = []
|
plugin = []
|
||||||
tokio-console = ["dep:console-subscriber"]
|
tokio-console = ["dep:console-subscriber"]
|
||||||
|
|
||||||
|
# when releasing dioxus, we want to enable wasm-opt
|
||||||
|
wasm-opt = ["dep:wasm-opt"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
name = "dx"
|
name = "dx"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use crate::builder::progress::Stage;
|
|||||||
use crate::builder::progress::UpdateBuildProgress;
|
use crate::builder::progress::UpdateBuildProgress;
|
||||||
use crate::builder::progress::UpdateStage;
|
use crate::builder::progress::UpdateStage;
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use dioxus_cli_config::WasmOptLevel;
|
|
||||||
use futures_channel::mpsc::UnboundedSender;
|
use futures_channel::mpsc::UnboundedSender;
|
||||||
use manganis_cli_support::AssetManifest;
|
use manganis_cli_support::AssetManifest;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -130,38 +129,45 @@ impl BuildRequest {
|
|||||||
// Run wasm-bindgen
|
// Run wasm-bindgen
|
||||||
self.run_wasm_bindgen(&input_path, &bindgen_outdir).await?;
|
self.run_wasm_bindgen(&input_path, &bindgen_outdir).await?;
|
||||||
|
|
||||||
// Run wasm-opt if this is a release build
|
// Only run wasm-opt if the feature is enabled
|
||||||
if self.build_arguments.release {
|
// Wasm-opt has an expensive build script that makes it annoying to keep enabled for iterative dev
|
||||||
tracing::info!("Running optimization with wasm-opt...");
|
#[cfg(feature = "wasm-opt")]
|
||||||
let mut options = match self.dioxus_crate.dioxus_config.web.wasm_opt.level {
|
{
|
||||||
WasmOptLevel::Z => {
|
// Run wasm-opt if this is a release build
|
||||||
wasm_opt::OptimizationOptions::new_optimize_for_size_aggressively()
|
if self.build_arguments.release {
|
||||||
}
|
use dioxus_cli_config::WasmOptLevel;
|
||||||
WasmOptLevel::S => wasm_opt::OptimizationOptions::new_optimize_for_size(),
|
|
||||||
WasmOptLevel::Zero => wasm_opt::OptimizationOptions::new_opt_level_0(),
|
tracing::info!("Running optimization with wasm-opt...");
|
||||||
WasmOptLevel::One => wasm_opt::OptimizationOptions::new_opt_level_1(),
|
let mut options = match self.dioxus_crate.dioxus_config.web.wasm_opt.level {
|
||||||
WasmOptLevel::Two => wasm_opt::OptimizationOptions::new_opt_level_2(),
|
WasmOptLevel::Z => {
|
||||||
WasmOptLevel::Three => wasm_opt::OptimizationOptions::new_opt_level_3(),
|
wasm_opt::OptimizationOptions::new_optimize_for_size_aggressively()
|
||||||
WasmOptLevel::Four => wasm_opt::OptimizationOptions::new_opt_level_4(),
|
}
|
||||||
};
|
WasmOptLevel::S => wasm_opt::OptimizationOptions::new_optimize_for_size(),
|
||||||
let wasm_file = bindgen_outdir.join(format!(
|
WasmOptLevel::Zero => wasm_opt::OptimizationOptions::new_opt_level_0(),
|
||||||
"{}_bg.wasm",
|
WasmOptLevel::One => wasm_opt::OptimizationOptions::new_opt_level_1(),
|
||||||
self.dioxus_crate.dioxus_config.application.name
|
WasmOptLevel::Two => wasm_opt::OptimizationOptions::new_opt_level_2(),
|
||||||
));
|
WasmOptLevel::Three => wasm_opt::OptimizationOptions::new_opt_level_3(),
|
||||||
let old_size = wasm_file.metadata()?.len();
|
WasmOptLevel::Four => wasm_opt::OptimizationOptions::new_opt_level_4(),
|
||||||
options
|
};
|
||||||
// WASM bindgen relies on reference types
|
let wasm_file = bindgen_outdir.join(format!(
|
||||||
.enable_feature(wasm_opt::Feature::ReferenceTypes)
|
"{}_bg.wasm",
|
||||||
.debug_info(self.dioxus_crate.dioxus_config.web.wasm_opt.debug)
|
self.dioxus_crate.dioxus_config.application.name
|
||||||
.run(&wasm_file, &wasm_file)
|
));
|
||||||
.map_err(|err| Error::Other(anyhow::anyhow!(err)))?;
|
let old_size = wasm_file.metadata()?.len();
|
||||||
let new_size = wasm_file.metadata()?.len();
|
options
|
||||||
tracing::info!(
|
// WASM bindgen relies on reference types
|
||||||
"wasm-opt reduced WASM size from {} to {} ({:2}%)",
|
.enable_feature(wasm_opt::Feature::ReferenceTypes)
|
||||||
old_size,
|
.debug_info(self.dioxus_crate.dioxus_config.web.wasm_opt.debug)
|
||||||
new_size,
|
.run(&wasm_file, &wasm_file)
|
||||||
(new_size as f64 - old_size as f64) / old_size as f64 * 100.0
|
.map_err(|err| Error::Other(anyhow::anyhow!(err)))?;
|
||||||
);
|
let new_size = wasm_file.metadata()?.len();
|
||||||
|
tracing::info!(
|
||||||
|
"wasm-opt reduced WASM size from {} to {} ({:2}%)",
|
||||||
|
old_size,
|
||||||
|
new_size,
|
||||||
|
(new_size as f64 - old_size as f64) / old_size as f64 * 100.0
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If pre-compressing is enabled, we can pre_compress the wasm-bindgen output
|
// If pre-compressing is enabled, we can pre_compress the wasm-bindgen output
|
||||||
|
|||||||
Reference in new issue
Block a user