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:
1 parent
22e0682f10
commit
9027ffc278
6 files changed
+568
-420
No files matched your search
@@ -211,7 +211,7 @@ jobs:
|
||||
with:
|
||||
node-version: 16
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
uses: dtolnay/rust-toolchain@1.86.0
|
||||
with:
|
||||
toolchain: stable
|
||||
targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
|
||||
|
||||
Generated
+542
-407
File diff suppressed because it is too large.
Load diff
@@ -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(())
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Default for DioxusConfig {
|
||||
key_path: None,
|
||||
cert_path: None,
|
||||
},
|
||||
pre_compress: true,
|
||||
pre_compress: false,
|
||||
wasm_opt: Default::default(),
|
||||
},
|
||||
bundle: BundleConfig::default(),
|
||||
|
||||
@@ -562,10 +562,7 @@ fn build_serve_dir(runner: &AppServer) -> axum::routing::MethodRouter {
|
||||
let app = &runner.client;
|
||||
let cfg = &runner.client.build.config;
|
||||
|
||||
let out_dir = app
|
||||
.build
|
||||
.build_dir(Platform::Web, app.build.release)
|
||||
.join("public");
|
||||
let out_dir = app.build.root_dir();
|
||||
let index_on_404: bool = cfg.web.watcher.index_on_404;
|
||||
|
||||
get_service(
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::path::Path;
|
||||
|
||||
/// Write these wasm bytes with a particular set of optimizations
|
||||
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?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -32,6 +32,7 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
|
||||
"--enable-reference-types",
|
||||
"--enable-bulk-memory",
|
||||
"--enable-mutable-globals",
|
||||
"--enable-nontrapping-float-to-int",
|
||||
];
|
||||
|
||||
if cfg.memory_packing {
|
||||
@@ -60,7 +61,7 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
|
||||
WasmOptLevel::Four => "-O4",
|
||||
};
|
||||
|
||||
tokio::process::Command::new("wasm-opt")
|
||||
let res = tokio::process::Command::new("wasm-opt")
|
||||
.arg(input_path)
|
||||
.arg(level)
|
||||
.arg("-o")
|
||||
@@ -69,6 +70,11 @@ async fn run_locally(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig)
|
||||
.output()
|
||||
.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(())
|
||||
}
|
||||
|
||||
@@ -95,6 +101,7 @@ async fn run_from_lib(
|
||||
.enable_feature(wasm_opt::Feature::ReferenceTypes)
|
||||
.enable_feature(wasm_opt::Feature::BulkMemory)
|
||||
.enable_feature(wasm_opt::Feature::MutableGlobals)
|
||||
.enable_feature(wasm_opt::Feature::TruncSat)
|
||||
.add_pass(wasm_opt::Pass::MemoryPacking)
|
||||
.debug_info(options.debug);
|
||||
|
||||
|
||||
Reference in new issue
Block a user