From d6ef9e154bfafb186d6ab2acbd17b6f9e0849f47 Mon Sep 17 00:00:00 2001 From: gak Date: Mon, 7 Oct 2024 06:54:15 +1100 Subject: [PATCH] Add wasm32 build to ci (#636), bevy_egui -> 0.29 (#637) * Fixes a wasm build problem with bevy_egui too! Co-authored-by: Alice Cecile --- .cargo/config.toml | 2 ++ .github/workflows/ci.yml | 5 +++-- Cargo.toml | 2 +- tools/ci/src/main.rs | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..f5d91204 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +rustflags = ["--cfg=web_sys_unstable_apis"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c25e5e18..47667104 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: - name: Cache Cargo build files uses: Leafwing-Studios/cargo-cache@v2.4.0 - name: Install alsa and udev - run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev - name: Build & run tests # See tools/ci/src/main.rs for the commands this runs run: cargo run -p ci -- test @@ -50,10 +50,11 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: stable + targets: wasm32-unknown-unknown - name: Cache Cargo build files uses: Leafwing-Studios/cargo-cache@v2.4.0 - name: Install alsa and udev - run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev - name: Check Compile # See tools/ci/src/main.rs for the commands this runs run: cargo run -p ci -- compile diff --git a/Cargo.toml b/Cargo.toml index 488d02d2..dbc774df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ leafwing_input_manager_macros = { path = "macros", version = "0.15.1" } bevy = { version = "0.14.0-rc.3", default-features = false, features = [ "serialize", ] } -bevy_egui = { version = "0.28", optional = true } +bevy_egui = { version = "0.29", optional = true } derive_more = { version = "0.99", default-features = false, features = [ "display", diff --git a/tools/ci/src/main.rs b/tools/ci/src/main.rs index 271fa2a7..57bdb4f0 100644 --- a/tools/ci/src/main.rs +++ b/tools/ci/src/main.rs @@ -23,6 +23,8 @@ const CLIPPY_FLAGS: [&str; 3] = [ "-Dwarnings", ]; +const COMPILE_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]; + fn main() { // When run locally, results may differ from actual CI runs triggered by // .github/workflows/ci.yml @@ -71,7 +73,7 @@ fn main() { std::env::set_var("RUSTDOCFLAGS", "-D warnings"); cmd!( sh, - "cargo doc --workspace --all-features --no-deps --document-private-items" + "cargo doc --workspace --all-features --features bevy/wayland --no-deps --document-private-items" ) .run() .expect("Please fix doc warnings in output above."); @@ -84,6 +86,13 @@ fn main() { // and convert them into '--features=' let lib_features_options = (1..lib_features.len()) .flat_map(|combination_length| lib_features.iter().combinations(combination_length)) + .map(|mut combination| { + // bevy_egui 0.29 uses the bevy winit feature, which requires a renderer. + if combination.contains(&&"egui") { + combination.push(&"bevy/wayland"); + } + combination + }) .map(|combination| String::from("--features=") + &combination.iter().join(",")); let default_feature_options = ["--no-default-features", "--all-features"]; @@ -94,13 +103,19 @@ fn main() { .collect::>(); for feature_option in all_features_options { + let extra = if feature_option == "--all-features" { + &vec!["--features", "bevy/wayland"] + } else { + &vec![] + }; + if what_to_run.contains(Check::CLIPPY) { // See if clippy has any complaints. // --all-targets was removed because Emergence currently has no special targets; // please add them back as necessary cmd!( sh, - "cargo clippy --workspace {feature_option} -- {CLIPPY_FLAGS...}" + "cargo clippy --workspace {feature_option} {extra...} -- {CLIPPY_FLAGS...}" ) .run() .expect("Please fix clippy errors in output above."); @@ -110,7 +125,7 @@ fn main() { // Run tests (except doc tests and without building examples) cmd!( sh, - "cargo test --workspace {feature_option} --lib --bins --tests --benches" + "cargo test --workspace {feature_option} {extra...} --lib --bins --tests --benches" ) .run() .expect("Please fix failing tests in output above."); @@ -125,15 +140,23 @@ fn main() { } // Run doc tests - cmd!(sh, "cargo test --workspace {feature_option} --doc") - .run() - .expect("Please fix failing doc-tests in output above."); + cmd!( + sh, + "cargo test --workspace {feature_option} {extra...} --doc" + ) + .run() + .expect("Please fix failing doc-tests in output above."); } if what_to_run.contains(Check::COMPILE_CHECK) { - cmd!(sh, "cargo check --workspace {feature_option}") + for target in COMPILE_TARGETS { + cmd!( + sh, + "cargo check --workspace {feature_option} {extra...} --target {target}" + ) .run() .expect("Please fix compiler errors in above output."); + } } } }