Skip to content

Commit fd1b04e

Browse files
authored
use dx run for playwright tests, properly abort if error occurs, don't ddos github releases, split apt-cache by os/target in matrix (#4315)
* properly emit errors * fix error propagate * install glib * fix playwright for dx run ssg * add execute install scripts (for arm linux) * use verbose playwright * wip: unwrap playwright download error * use alternative wasm-opt install * log wasm-opt download * use hardcoded endpoint for wasm-opt download * disambiguate cache * clean up impl
1 parent e477e0b commit fd1b04e

File tree

6 files changed

+113
-62
lines changed

6 files changed

+113
-62
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
uses: ./.github/actions/free-disk-space
7474
- uses: awalsh128/cache-apt-pkgs-action@latest
7575
with:
76-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
76+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
7777
version: 1.0
7878
- uses: dtolnay/[email protected]
7979
with:
@@ -94,7 +94,7 @@ jobs:
9494
uses: ./.github/actions/free-disk-space
9595
- uses: awalsh128/cache-apt-pkgs-action@latest
9696
with:
97-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
97+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
9898
version: 1.0
9999
- uses: dtolnay/[email protected]
100100
with:
@@ -127,7 +127,7 @@ jobs:
127127
- uses: actions/checkout@v4
128128
- uses: awalsh128/cache-apt-pkgs-action@latest
129129
with:
130-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
130+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
131131
version: 1.0
132132
- name: Install Rust ${{ env.rust_nightly }}
133133
uses: dtolnay/rust-toolchain@nightly
@@ -150,7 +150,7 @@ jobs:
150150
- uses: actions/checkout@v4
151151
- uses: awalsh128/cache-apt-pkgs-action@latest
152152
with:
153-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
153+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
154154
version: 1.0
155155
- uses: dtolnay/[email protected]
156156
- uses: Swatinem/rust-cache@v2
@@ -166,7 +166,7 @@ jobs:
166166
- uses: actions/checkout@v4
167167
- uses: awalsh128/cache-apt-pkgs-action@latest
168168
with:
169-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
169+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
170170
version: 1.0
171171
- uses: dtolnay/[email protected]
172172
with:
@@ -309,8 +309,8 @@ jobs:
309309
- uses: awalsh128/cache-apt-pkgs-action@latest
310310
if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
311311
with:
312-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
313-
version: 1.0
312+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
313+
version: ${{ matrix.platform.target }}-${{ matrix.platform.os }} # disambiguate since we're in a matrix and this caching action doesn't factor in these variables
314314

315315
- name: Install cross
316316
if: ${{ matrix.platform.cross == true }}

.github/workflows/merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
steps:
4141
- uses: actions/checkout@v4
4242
- run: sudo apt-get update
43-
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
43+
- run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
4444
- uses: dtolnay/rust-toolchain@nightly
4545
with:
4646
toolchain: nightly-2024-02-01

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- uses: awalsh128/cache-apt-pkgs-action@latest
8181
if: ${{ matrix.platform.os == 'ubuntu-24.04' || matrix.platform.os == 'ubuntu-24.04-arm' }}
8282
with:
83-
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
83+
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
8484
version: 1.0
8585

8686
- name: Install stable
@@ -127,7 +127,7 @@ jobs:
127127
# - uses: actions/checkout@v4
128128
# ref: ${{ github.event.inputs.channel }}
129129
# - run: sudo apt-get update
130-
# - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev
130+
# - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
131131
# - uses: dtolnay/rust-toolchain@nightly
132132
# with:
133133
# toolchain: nightly-2024-02-01

packages/cli/src/cli/run.rs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use super::*;
22
use crate::{
33
serve::{AppServer, ServeUpdate, WebServer},
4-
BuilderUpdate, Platform, Result,
4+
BuilderUpdate, Error, Platform, Result,
55
};
66
use dioxus_dx_wire_format::BuildStage;
77

88
/// Run the project with the given arguments
99
///
1010
/// This is a shorthand for `dx serve` with interactive mode and hot-reload disabled.
11+
///
12+
/// Unlike `dx serve`, errors during build and run will cascade out as an error, rather than being
13+
/// handled by the TUI, making it more suitable for scripting, automation, or CI/CD pipelines.
1114
#[derive(Clone, Debug, Parser)]
1215
pub(crate) struct RunArgs {
1316
/// Information about the target to build
@@ -36,15 +39,15 @@ impl RunArgs {
3639
};
3740

3841
match msg {
39-
// Wait for logs from the build engine
40-
// These will cause us to update the screen
41-
// We also can check the status of the builds here in case we have multiple ongoing builds
4242
ServeUpdate::BuilderUpdate { id, update } => {
4343
let platform = builder.get_build(id).unwrap().build.platform;
4444

4545
// And then update the websocketed clients with the new build status in case they want it
4646
devserver.new_build_update(&update).await;
4747

48+
// Finally, we also want to update the builder with the new update
49+
builder.new_build_update(&update, &devserver).await;
50+
4851
// And then open the app if it's ready
4952
match update {
5053
BuilderUpdate::BuildReady { bundle } => {
@@ -72,7 +75,9 @@ impl RunArgs {
7275
total,
7376
krate,
7477
} => {
75-
tracing::info!("[{platform}] Compiling {krate} ({current}/{total})",)
78+
tracing::debug!(
79+
"[{platform}] ({current}/{total}) Compiling {krate} ",
80+
)
7681
}
7782
BuildStage::RunningBindgen => {
7883
tracing::info!("[{platform}] Running WASM bindgen")
@@ -82,7 +87,7 @@ impl RunArgs {
8287
tracing::info!("[{platform}] Optimizing WASM with `wasm-opt`")
8388
}
8489
BuildStage::Linking => tracing::info!("Linking app"),
85-
BuildStage::Hotpatching => todo!(),
90+
BuildStage::Hotpatching => {}
8691
BuildStage::CopyingAssets {
8792
current,
8893
total,
@@ -96,17 +101,32 @@ impl RunArgs {
96101
tracing::info!("[{platform}] Running Gradle")
97102
}
98103
BuildStage::Success => {}
99-
BuildStage::Failed => {}
100-
BuildStage::Aborted => {}
101104
BuildStage::Restarting => {}
102105
BuildStage::CompressingAssets => {}
106+
BuildStage::ExtractingAssets => {}
107+
BuildStage::Prerendering => {
108+
tracing::info!("[{platform}] Prerendering app")
109+
}
110+
BuildStage::Failed => {
111+
tracing::error!("[{platform}] Build failed");
112+
return Err(Error::Cargo(format!(
113+
"Build failed for platform: {platform}"
114+
)));
115+
}
116+
BuildStage::Aborted => {
117+
tracing::error!("[{platform}] Build aborted");
118+
return Err(Error::Cargo(format!(
119+
"Build aborted for platform: {platform}"
120+
)));
121+
}
103122
_ => {}
104123
},
105124
BuilderUpdate::CompilerMessage { message } => {
106125
print!("{}", message);
107126
}
108127
BuilderUpdate::BuildFailed { err } => {
109128
tracing::error!("Build failed: {}", err);
129+
return Err(err);
110130
}
111131
BuilderUpdate::StdoutReceived { msg } => {
112132
tracing::info!("[{platform}] {msg}");
@@ -119,14 +139,28 @@ impl RunArgs {
119139
tracing::error!(
120140
"Application [{platform}] exited with error: {status}"
121141
);
142+
return Err(Error::Runtime(format!(
143+
"Application [{platform}] exited with error: {status}"
144+
)));
122145
}
123146

124147
break;
125148
}
126-
BuilderUpdate::ProcessWaitFailed { .. } => {}
149+
BuilderUpdate::ProcessWaitFailed { err } => {
150+
return Err(err.into());
151+
}
127152
}
128153
}
129-
_ => {}
154+
ServeUpdate::Exit { .. } => break,
155+
ServeUpdate::NewConnection { .. } => {}
156+
ServeUpdate::WsMessage { .. } => {}
157+
ServeUpdate::FilesChanged { .. } => {}
158+
ServeUpdate::OpenApp => {}
159+
ServeUpdate::RequestRebuild => {}
160+
ServeUpdate::ToggleShouldRebuild => {}
161+
ServeUpdate::OpenDebugger { .. } => {}
162+
ServeUpdate::Redraw => {}
163+
ServeUpdate::TracingLog { .. } => {}
130164
}
131165
}
132166

packages/cli/src/wasm_opt.rs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
use crate::config::WasmOptLevel;
2+
use crate::{CliSettings, Result, WasmOptConfig, Workspace};
13
use anyhow::{anyhow, Context};
24
use flate2::read::GzDecoder;
5+
use std::path::{Path, PathBuf};
36
use tar::Archive;
47
use tempfile::NamedTempFile;
5-
use tokio::fs;
6-
7-
use crate::config::WasmOptLevel;
8-
use crate::{CliSettings, Result, WasmOptConfig, Workspace};
9-
use std::path::{Path, PathBuf};
108

119
/// Write these wasm bytes with a particular set of optimizations
1210
pub async fn write_wasm(bytes: &[u8], output_path: &Path, cfg: &WasmOptConfig) -> Result<()> {
@@ -16,7 +14,9 @@ pub async fn write_wasm(bytes: &[u8], output_path: &Path, cfg: &WasmOptConfig) -
1614
}
1715

1816
pub async fn optimize(input_path: &Path, output_path: &Path, cfg: &WasmOptConfig) -> Result<()> {
19-
let wasm_opt = WasmOpt::new(input_path, output_path, cfg).await?;
17+
let wasm_opt = WasmOpt::new(input_path, output_path, cfg)
18+
.await
19+
.inspect_err(|err| tracing::error!("Failed to create wasm-opt instance: {}", err))?;
2020
wasm_opt.optimize().await?;
2121

2222
Ok(())
@@ -127,6 +127,20 @@ impl WasmOpt {
127127

128128
// Find the URL for the latest binaryen release that contains wasm-opt
129129
async fn find_latest_wasm_opt_download_url() -> anyhow::Result<String> {
130+
// Find the platform identifier based on the current OS and architecture
131+
// hardcoded for now to get around github api rate limits
132+
if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
133+
return Ok("https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-windows.tar.gz".to_string());
134+
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
135+
return Ok("https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-linux.tar.gz".to_string());
136+
} else if cfg!(all(target_os = "linux", target_arch = "aarch64")) {
137+
return Ok("https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-aarch64-linux.tar.gz".to_string());
138+
} else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
139+
return Ok("https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-macos.tar.gz".to_string());
140+
} else if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
141+
return Ok("https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-arm64-macos.tar.gz".to_string());
142+
};
143+
130144
let url = "https://api.github.com/repos/WebAssembly/binaryen/releases/latest";
131145
let client = reqwest::Client::new();
132146
let response = client
@@ -136,6 +150,9 @@ async fn find_latest_wasm_opt_download_url() -> anyhow::Result<String> {
136150
.await?
137151
.json::<serde_json::Value>()
138152
.await?;
153+
154+
tracing::trace!("Response from GitHub: {:#?}", response);
155+
139156
let assets = response
140157
.get("assets")
141158
.and_then(|assets| assets.as_array())
@@ -165,7 +182,7 @@ async fn find_latest_wasm_opt_download_url() -> anyhow::Result<String> {
165182
asset
166183
.get("name")
167184
.and_then(|name| name.as_str())
168-
.is_some_and(|name| name.contains(platform))
185+
.is_some_and(|name| name.contains(platform) && !name.ends_with("sha256"))
169186
})
170187
.ok_or_else(|| {
171188
anyhow::anyhow!(
@@ -185,31 +202,30 @@ async fn find_latest_wasm_opt_download_url() -> anyhow::Result<String> {
185202

186203
/// Get the path to the wasm-opt binary, downloading it if necessary
187204
async fn get_binary_path() -> anyhow::Result<PathBuf> {
188-
let existing_path = which::which("wasm-opt");
189-
190-
match existing_path {
191-
// If wasm-opt is already in the PATH, return its path
192-
Ok(path) => Ok(path),
193-
// If wasm-opt is not found in the path and we prefer no downloads, return an error
194-
Err(_) if CliSettings::prefer_no_downloads() => Err(anyhow!("Missing wasm-opt")),
195-
// Otherwise, try to install it
196-
Err(_) => {
197-
let install_dir = install_dir().await?;
198-
let install_path = installed_bin_path(&install_dir);
199-
if !install_path.exists() {
200-
tracing::info!("Installing wasm-opt");
201-
install_github(&install_dir).await?;
202-
tracing::info!("wasm-opt installed from Github");
203-
}
204-
Ok(install_path)
205+
let install_dir = install_dir();
206+
let install_path = installed_bin_path(&install_dir);
207+
208+
if install_path.exists() {
209+
return Ok(install_path);
210+
}
211+
212+
if CliSettings::prefer_no_downloads() {
213+
if let Ok(existing) = which::which("wasm-opt") {
214+
return Ok(existing);
215+
} else {
216+
return Err(anyhow!("Missing wasm-opt"));
205217
}
206218
}
219+
220+
tracing::info!("Installing wasm-opt");
221+
install_github(&install_dir).await?;
222+
tracing::info!("wasm-opt installed from Github");
223+
224+
Ok(install_path)
207225
}
208226

209-
async fn install_dir() -> anyhow::Result<PathBuf> {
210-
let bindgen_dir = Workspace::dioxus_home_dir().join("binaryen");
211-
fs::create_dir_all(&bindgen_dir).await?;
212-
Ok(bindgen_dir)
227+
fn install_dir() -> PathBuf {
228+
Workspace::dioxus_home_dir().join("binaryen")
213229
}
214230

215231
fn installed_bin_name() -> &'static str {
@@ -221,14 +237,15 @@ fn installed_bin_name() -> &'static str {
221237
}
222238

223239
fn installed_bin_path(install_dir: &Path) -> PathBuf {
224-
let bin_name = installed_bin_name();
225-
install_dir.join("bin").join(bin_name)
240+
install_dir.join("bin").join(installed_bin_name())
226241
}
227242

228243
/// Install wasm-opt from GitHub releases into the specified directory
229244
async fn install_github(install_dir: &Path) -> anyhow::Result<()> {
230245
tracing::trace!("Attempting to install wasm-opt from GitHub");
231246

247+
std::fs::create_dir_all(install_dir)?;
248+
232249
let url = find_latest_wasm_opt_download_url()
233250
.await
234251
.context("Failed to find latest wasm-opt download URL")?;

0 commit comments

Comments
 (0)