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

+14 -5
View File
@@ -1047,11 +1047,11 @@ impl BuildRequest {
async fn write_frameworks(&self, _ctx: &BuildContext, direct_rustc: &RustcArgs) -> Result<()> {
let framework_dir = self.frameworks_folder();
_ = std::fs::create_dir_all(&framework_dir);
for arg in &direct_rustc.link_args {
// 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
if arg.ends_with(".dylib") | arg.ends_with(".so") {
let from = PathBuf::from(arg);
let to = framework_dir.join(from.file_name().unwrap());
@@ -1059,6 +1059,8 @@ impl BuildRequest {
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
// otherwise, just copy it (since in release you want to distribute the framework)
if cfg!(any(windows, unix)) && !self.release {
@@ -3185,6 +3187,7 @@ impl BuildRequest {
.expect("this should have been checked by tool verification");
// Prepare any work dirs
_ = std::fs::remove_dir_all(&bindgen_outdir);
std::fs::create_dir_all(&bindgen_outdir)?;
// Lift the internal functions to exports
@@ -3210,6 +3213,7 @@ impl BuildRequest {
|| 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 wasm_opt_options = WasmOptConfig {
memory_packing: self.wasm_split,
@@ -3334,7 +3338,7 @@ impl BuildRequest {
// Write the main wasm_bindgen file and register it with the asset system
// This will overwrite the file in place
// 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) {
@@ -3352,7 +3356,7 @@ impl BuildRequest {
// In release mode, we make the wasm and bindgen files into assets so they get bundled with max
// 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
let name = assets.register_asset(&post_bindgen_wasm, AssetOptions::Unknown)?;
format!("assets/{}", name.bundled_path())
@@ -3361,7 +3365,7 @@ impl BuildRequest {
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
let name = assets.register_asset(
&self.wasm_bindgen_js_output_file(),
@@ -3373,10 +3377,15 @@ impl BuildRequest {
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
std::fs::write(
self.root_dir().join("index.html"),
self.prepare_html(assets, &wasm_path, &js_path)?,
self.prepare_html(assets, &wasm_path, &js_path).unwrap(),
)?;
Ok(())