attempt to fix playwright (#4198)

* disable precompress by default

* go back to nuking wasm dir in some cases

* enable more wasm-opt flags, use stable

* add better logging for wasm-opt failure
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-05-25 18:51:40 +01:00
1 parent 22e0682f10
commit 9027ffc278
6 files changed
+568 -420

No files matched your search

+1 -1
View File
@@ -211,7 +211,7 @@ jobs:
with: with:
node-version: 16 node-version: 16
- name: Install Rust - name: Install Rust
uses: dtolnay/rust-toolchain@master uses: dtolnay/rust-toolchain@1.86.0
with: with:
toolchain: stable toolchain: stable
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
Generated
+542 -407
View File
File diff suppressed because it is too large. Load diff
+14 -5
View File
@@ -1047,11 +1047,11 @@ impl BuildRequest {
async fn write_frameworks(&self, _ctx: &BuildContext, direct_rustc: &RustcArgs) -> Result<()> { async fn write_frameworks(&self, _ctx: &BuildContext, direct_rustc: &RustcArgs) -> Result<()> {
let framework_dir = self.frameworks_folder(); let framework_dir = self.frameworks_folder();
_ = std::fs::create_dir_all(&framework_dir);
for arg in &direct_rustc.link_args { for arg in &direct_rustc.link_args {
// todo - how do we handle windows dlls? we don't want to bundle the system dlls // todo - how do we handle windows dlls? we don't want to bundle the system dlls
// for now, we don't do anything with dlls, and only use .dylibs and .so files // for now, we don't do anything with dlls, and only use .dylibs and .so files
if arg.ends_with(".dylib") | arg.ends_with(".so") { if arg.ends_with(".dylib") | arg.ends_with(".so") {
let from = PathBuf::from(arg); let from = PathBuf::from(arg);
let to = framework_dir.join(from.file_name().unwrap()); let to = framework_dir.join(from.file_name().unwrap());
@@ -1059,6 +1059,8 @@ impl BuildRequest {
tracing::debug!("Copying framework from {from:?} to {to:?}"); tracing::debug!("Copying framework from {from:?} to {to:?}");
_ = std::fs::create_dir_all(&framework_dir);
// in dev and on normal oses, we want to symlink the file // in dev and on normal oses, we want to symlink the file
// otherwise, just copy it (since in release you want to distribute the framework) // otherwise, just copy it (since in release you want to distribute the framework)
if cfg!(any(windows, unix)) && !self.release { if cfg!(any(windows, unix)) && !self.release {
@@ -3185,6 +3187,7 @@ impl BuildRequest {
.expect("this should have been checked by tool verification"); .expect("this should have been checked by tool verification");
// Prepare any work dirs // Prepare any work dirs
_ = std::fs::remove_dir_all(&bindgen_outdir);
std::fs::create_dir_all(&bindgen_outdir)?; std::fs::create_dir_all(&bindgen_outdir)?;
// Lift the internal functions to exports // Lift the internal functions to exports
@@ -3210,6 +3213,7 @@ impl BuildRequest {
|| will_wasm_opt || will_wasm_opt
|| ctx.mode == BuildMode::Fat; || ctx.mode == BuildMode::Fat;
let keep_names = will_wasm_opt || ctx.mode == BuildMode::Fat; let keep_names = will_wasm_opt || ctx.mode == BuildMode::Fat;
let package_to_asset = self.release && !should_bundle_split;
let demangle = false; let demangle = false;
let wasm_opt_options = WasmOptConfig { let wasm_opt_options = WasmOptConfig {
memory_packing: self.wasm_split, memory_packing: self.wasm_split,
@@ -3334,7 +3338,7 @@ impl BuildRequest {
// Write the main wasm_bindgen file and register it with the asset system // Write the main wasm_bindgen file and register it with the asset system
// This will overwrite the file in place // This will overwrite the file in place
// We will wasm-opt it in just a second... // We will wasm-opt it in just a second...
std::fs::write(&post_bindgen_wasm, modules.main.bytes)?; std::fs::write(&post_bindgen_wasm, modules.main.bytes).unwrap();
} }
if matches!(ctx.mode, BuildMode::Fat) { if matches!(ctx.mode, BuildMode::Fat) {
@@ -3352,7 +3356,7 @@ impl BuildRequest {
// In release mode, we make the wasm and bindgen files into assets so they get bundled with max // In release mode, we make the wasm and bindgen files into assets so they get bundled with max
// optimizations. // optimizations.
let wasm_path = if self.release && !should_bundle_split { let wasm_path = if package_to_asset {
// Make sure to register the main wasm file with the asset system // Make sure to register the main wasm file with the asset system
let name = assets.register_asset(&post_bindgen_wasm, AssetOptions::Unknown)?; let name = assets.register_asset(&post_bindgen_wasm, AssetOptions::Unknown)?;
format!("assets/{}", name.bundled_path()) format!("assets/{}", name.bundled_path())
@@ -3361,7 +3365,7 @@ impl BuildRequest {
format!("wasm/{}", asset.file_name().unwrap().to_str().unwrap()) format!("wasm/{}", asset.file_name().unwrap().to_str().unwrap())
}; };
let js_path = if self.release && !should_bundle_split { let js_path = if package_to_asset {
// Register the main.js with the asset system so it bundles in the snippets and optimizes // Register the main.js with the asset system so it bundles in the snippets and optimizes
let name = assets.register_asset( let name = assets.register_asset(
&self.wasm_bindgen_js_output_file(), &self.wasm_bindgen_js_output_file(),
@@ -3373,10 +3377,15 @@ impl BuildRequest {
format!("wasm/{}", asset.file_name().unwrap().to_str().unwrap()) format!("wasm/{}", asset.file_name().unwrap().to_str().unwrap())
}; };
// Remove the wasm dir if we packaged it to an "asset"-type app
if package_to_asset {
std::fs::remove_dir_all(&bindgen_outdir).context("Failed to remove bindgen outdir")?;
}
// Write the index.html file with the pre-configured contents we got from pre-rendering // Write the index.html file with the pre-configured contents we got from pre-rendering
std::fs::write( std::fs::write(
self.root_dir().join("index.html"), self.root_dir().join("index.html"),
self.prepare_html(assets, &wasm_path, &js_path)?, self.prepare_html(assets, &wasm_path, &js_path).unwrap(),
)?; )?;
Ok(()) Ok(())
+1 -1
View File
@@ -46,7 +46,7 @@ impl Default for DioxusConfig {
key_path: None, key_path: None,
cert_path: None, cert_path: None,
}, },
pre_compress: true, pre_compress: false,
wasm_opt: Default::default(), wasm_opt: Default::default(),
}, },
bundle: BundleConfig::default(), bundle: BundleConfig::default(),
+1 -4
View File
@@ -562,10 +562,7 @@ fn build_serve_dir(runner: &AppServer) -> axum::routing::MethodRouter {
let app = &runner.client; let app = &runner.client;
let cfg = &runner.client.build.config; let cfg = &runner.client.build.config;
let out_dir = app let out_dir = app.build.root_dir();
.build
.build_dir(Platform::Web, app.build.release)
.join("public");
let index_on_404: bool = cfg.web.watcher.index_on_404; let index_on_404: bool = cfg.web.watcher.index_on_404;
get_service( get_service(
+9 -2
View File
@@ -4,7 +4,7 @@ use std::path::Path;
/// Write these wasm bytes with a particular set of optimizations /// Write these wasm bytes with a particular set of optimizations
pub async fn write_wasm(bytes: &[u8], output_path: &Path, cfg: &WasmOptConfig) -> Result<()> { pub async fn write_wasm(bytes: &[u8], output_path: &Path, cfg: &WasmOptConfig) -> Result<()> {
tokio::fs::write(output_path, bytes).await?; std::fs::write(output_path, bytes)?;
optimize(output_path, output_path, cfg).await?; optimize(output_path, output_path, cfg).await?;
Ok(()) Ok(())
} }
@@ -32,6 +32,7 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
"--enable-reference-types", "--enable-reference-types",
"--enable-bulk-memory", "--enable-bulk-memory",
"--enable-mutable-globals", "--enable-mutable-globals",
"--enable-nontrapping-float-to-int",
]; ];
if cfg.memory_packing { if cfg.memory_packing {
@@ -60,7 +61,7 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
WasmOptLevel::Four => "-O4", WasmOptLevel::Four => "-O4",
}; };
tokio::process::Command::new("wasm-opt") let res = tokio::process::Command::new("wasm-opt")
.arg(input_path) .arg(input_path)
.arg(level) .arg(level)
.arg("-o") .arg("-o")
@@ -69,6 +70,11 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
.output() .output()
.await?; .await?;
if !res.status.success() {
let err = String::from_utf8_lossy(&res.stderr);
tracing::error!("wasm-opt failed with status code {}: {}", res.status, err);
}
Ok(()) Ok(())
} }
@@ -95,6 +101,7 @@ async fn run_from_lib(
.enable_feature(wasm_opt::Feature::ReferenceTypes) .enable_feature(wasm_opt::Feature::ReferenceTypes)
.enable_feature(wasm_opt::Feature::BulkMemory) .enable_feature(wasm_opt::Feature::BulkMemory)
.enable_feature(wasm_opt::Feature::MutableGlobals) .enable_feature(wasm_opt::Feature::MutableGlobals)
.enable_feature(wasm_opt::Feature::TruncSat)
.add_pass(wasm_opt::Pass::MemoryPacking) .add_pass(wasm_opt::Pass::MemoryPacking)
.debug_info(options.debug); .debug_info(options.debug);