From 031fe890a5e8b2381896e4e2ac9682d6ceafde75 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 11 Aug 2024 15:47:29 +0200 Subject: [PATCH] Improve the CI runtime, take two (#4058) --- .github/workflows/main.yml | 223 ++++++++++++-------------- .gitignore | 1 + _package.json | 15 -- crates/example-tests/Cargo.toml | 12 +- crates/example-tests/tests/shell.rs | 8 + crates/example-tests/tests/webpack.rs | 2 + 6 files changed, 122 insertions(+), 139 deletions(-) delete mode 100644 _package.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fcc080ee31c..d3a57be9904 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -93,7 +93,18 @@ jobs: - run: for i in examples/*/; do cd "$i"; cargo +stable clippy --no-deps --all-features --target wasm32-unknown-unknown -- -D warnings || exit 1; cd ../..; done test_wasm_bindgen: - name: "Run wasm-bindgen crate tests (unix)" + strategy: + matrix: + runs: + - name: "wasm-bindgen" + run: | + cargo test --target wasm32-unknown-unknown + cargo test --target wasm32-unknown-unknown -p wasm-bindgen-futures + - name: "wasm-bindgen (serde-serialize)" + run: cargo test --target wasm32-unknown-unknown --features serde-serialize + - name: "wasm-bindgen (enable-interning)" + run: cargo test --target wasm32-unknown-unknown --features enable-interning + name: "Run wasm-bindgen crate tests (${{ matrix.runs.name }})" runs-on: ubuntu-latest env: WASM_BINDGEN_SPLIT_LINKED_MODULES: 1 @@ -105,24 +116,7 @@ jobs: with: node-version: '20' - uses: ./.github/actions/setup-geckodriver - - run: cargo test --target wasm32-unknown-unknown - - run: cargo test --target wasm32-unknown-unknown -p wasm-bindgen-futures - - test_wasm_bindgen_features: - name: "Run wasm-bindgen crate tests with different features" - runs-on: ubuntu-latest - env: - WASM_BINDGEN_SPLIT_LINKED_MODULES: 1 - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - uses: ./.github/actions/setup-geckodriver - - run: cargo test --target wasm32-unknown-unknown --features serde-serialize - - run: cargo test --target wasm32-unknown-unknown --features enable-interning + - run: ${{ matrix.runs.run }} test_wasm_bindgen_wasm: name: "Run wasm-bindgen wasm test" @@ -141,10 +135,21 @@ jobs: WASM_BINDGEN_NO_DEBUG: 1 test_wasm_bindgen_envs: - name: "Run wasm-bindgen crate tests with various environment variables" + strategy: + matrix: + envs: + - name: "externref" + env: + WASM_BINDGEN_EXTERNREF: 1 + - name: "multi-value" + env: + WASM_BINDGEN_MULTI_VALUE: 1 + name: "Run wasm-bindgen crate tests with ${{ matrix.envs.name }} feature" runs-on: ubuntu-latest env: WASM_BINDGEN_SPLIT_LINKED_MODULES: 1 + WASM_BINDGEN_EXTERNREF: ${{ matrix.envs.WASM_BINDGEN_EXTERNREF }} + WASM_BINDGEN_MULTI_VALUE: ${{ matrix.envs.WASM_BINDGEN_MULTI_VALUE }} steps: - uses: actions/checkout@v4 - run: rustup update --no-self-update stable && rustup default stable @@ -153,14 +158,9 @@ jobs: with: node-version: '20' - run: cargo test --target wasm32-unknown-unknown - env: - WASM_BINDGEN_EXTERNREF: 1 - - run: cargo test --target wasm32-unknown-unknown - env: - WASM_BINDGEN_MULTI_VALUE: 1 test_threads: - name: "Run wasm-bindgen crate tests with multithreading enabled" + name: "Run wasm-bindgen crate tests with multithreading" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -215,61 +215,44 @@ jobs: - run: cargo test -p wasm-bindgen-futures - run: cargo test -p wasm-bindgen-shared - test_web_sys: - name: "Run web-sys crate tests" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - uses: ./.github/actions/setup-geckodriver - - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown - - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Node - - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Element - - run: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Window - - test_web_sys_all_features: - name: "Run web-sys crate tests with all features" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - uses: ./.github/actions/setup-geckodriver - - run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features - - test_web_sys_all_features_unstable: - name: "Run web-sys crate tests with all features and unstable APIs" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - uses: ./.github/actions/setup-geckodriver - - run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features - env: - RUSTFLAGS: --cfg=web_sys_unstable_apis - - check_web_sys: - name: "Verify that web-sys is compiled correctly" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: cd crates/web-sys && cargo run --release --package wasm-bindgen-webidl -- webidls src/features ./Cargo.toml - - run: git diff --exit-code - - test_js_sys: - name: "Run js-sys crate tests" + test_with_geckodriver: + strategy: + matrix: + runs: + - name: "web-sys" + run: | + cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown + cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Node + cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Element + cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Window + - name: "web-sys (all features)" + run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features + - name: "web-sys (unstable, all features)" + run: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features + env: + RUSTFLAGS: --cfg=web_sys_unstable_apis + - name: "js-sys" + run: cargo test -p js-sys --target wasm32-unknown-unknown + - name: "js-sys (unstable)" + run: cargo test -p js-sys --target wasm32-unknown-unknown + env: + RUSTFLAGS: --cfg=js_sys_unstable_apis + - name: "wasm-bindgen-webidl" + run: cargo test -p wasm-bindgen-webidl + - name: "webidl-tests" + run: cargo test -p webidl-tests --target wasm32-unknown-unknown + env: + WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: 1 + - name: "webidl-tests (unstable)" + run: cargo test -p webidl-tests --target wasm32-unknown-unknown + env: + RUSTFLAGS: --cfg=web_sys_unstable_apis + - name: "typescript-tests" + run: cd crates/typescript-tests && ./run.sh + name: "Run ${{ matrix.runs.name }} tests (with geckodriver)" + env: + RUSTFLAGS: ${{ matrix.runs.env.RUSTFLAGS }} + WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: ${{ matrix.runs.env.WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -279,40 +262,7 @@ jobs: with: node-version: '20' - uses: ./.github/actions/setup-geckodriver - - run: cargo test -p js-sys --target wasm32-unknown-unknown - - run: cargo test -p js-sys --target wasm32-unknown-unknown - env: - RUSTFLAGS: --cfg=js_sys_unstable_apis - - test_webidl: - name: "Run wasm-bindgen-webidl crate tests" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - run: cargo test -p wasm-bindgen-webidl - - run: cargo test -p webidl-tests --target wasm32-unknown-unknown - env: - WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: 1 - - run: cargo test -p webidl-tests --target wasm32-unknown-unknown - env: - RUSTFLAGS: --cfg=web_sys_unstable_apis - - test_typescript_output: - name: "Test TypeScript output of wasm-bindgen" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update --no-self-update stable && rustup default stable - - run: rustup target add wasm32-unknown-unknown - - uses: actions/setup-node@v4 - with: - node-version: '20' - - run: cd crates/typescript-tests && ./run.sh + - run: ${{ matrix.runs.run }} test_deno: name: "Build and test the deno example" @@ -335,6 +285,15 @@ jobs: - run: cargo test -p wasm-bindgen-macro - run: cargo test -p wasm-bindgen-test-macro + build_webidl: + name: "Verify that web-sys is compiled correctly" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: rustup update --no-self-update stable && rustup default stable + - run: cd crates/web-sys && cargo run --release --package wasm-bindgen-webidl -- webidls src/features ./Cargo.toml + - run: git diff --exit-code + build_examples: runs-on: ubuntu-latest steps: @@ -349,14 +308,22 @@ jobs: - run: | cargo build -p wasm-bindgen-cli ln -snf `pwd`/target/debug/wasm-bindgen $(dirname `which cargo`)/wasm-bindgen - - run: mv _package.json package.json && npm install && rm package.json + # crete a workspace of all examples and install their dependencies at once + # sed is used to convert the literal "\n" to a newline character - run: | - for dir in `ls examples | grep -v README | grep -v raytrace | grep -v deno | grep -v wasm-audio-worklet`; do - (cd examples/$dir && - (npm run build -- --output-path ../../exbuild/$dir || - (./build.sh && mkdir -p ../../exbuild/$dir && cp -r ./* ../../exbuild/$dir && rm ../../exbuild/$dir/**/.gitignore)) + [ -f pnpm-workspace.yaml ] || (echo 'packages:\n - "examples/*"' > pnpm-workspace.yaml && sed -i -e 's/\\n/\n/g' pnpm-workspace.yaml) + - run: | + [ -f package.json ] || (echo '{}' > package.json) + - run: corepack pnpm install -r + - run: | + function build() { + (cd examples/$1 && + (corepack pnpm run build -- --output-path ../../exbuild/$1 || + (./build.sh && mkdir -p ../../exbuild/$1 && cp -r ./* ../../exbuild/$1 && rm ../../exbuild/$1/**/.gitignore)) ) || exit 1; - done + } + export -f build + ls examples | grep -v README | grep -v raytrace | grep -v deno | grep -v wasm-audio-worklet | parallel -j4 build env: RUSTFLAGS: --cfg=web_sys_unstable_apis - uses: actions/upload-artifact@v4 @@ -385,7 +352,6 @@ jobs: test_examples: needs: - build_examples - - build_nightly runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -393,12 +359,23 @@ jobs: with: name: examples1 path: exbuild + - run: rustup update --no-self-update stable && rustup default stable + - run: cargo test -p example-tests + env: + EXBUILD: ${{ github.workspace }}/exbuild + + test_nightly: + needs: + - build_nightly + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: name: examples2 path: exbuild - run: rustup update --no-self-update stable && rustup default stable - - run: cargo test -p example-tests + - run: cargo test -p example-tests --no-default-features --features nightly env: EXBUILD: ${{ github.workspace }}/exbuild diff --git a/.gitignore b/.gitignore index 57e7ac31a73..cb63ac51317 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Cargo.lock node_modules package-lock.json npm-shrinkwrap.json +pnpm-lock.yaml yarn.lock /publish /publish.exe diff --git a/_package.json b/_package.json deleted file mode 100644 index d347502d91f..00000000000 --- a/_package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "scripts": { - "build": "webpack", - "serve": "webpack serve" - }, - "devDependencies": { - "@wasm-tool/wasm-pack-plugin": "1.5.0", - "css-loader": "^7.1.2", - "html-webpack-plugin": "^5.6.0", - "mini-css-extract-plugin": "^2.9.0", - "webpack": "^5.93.0", - "webpack-cli": "^5.1.4", - "webpack-dev-server": "5.0.4" - } -} diff --git a/crates/example-tests/Cargo.toml b/crates/example-tests/Cargo.toml index 6f12da85a38..03fdfe5c43c 100644 --- a/crates/example-tests/Cargo.toml +++ b/crates/example-tests/Cargo.toml @@ -5,12 +5,22 @@ authors = ["The wasm-bindgen Developers"] edition = "2021" publish = false +[features] +default = ["stable"] +stable = [] +nightly = [] + [dependencies] anyhow = "1.0.75" futures-util = { version = "0.3.28", features = ["sink"] } http = "1" hyper = "1" -hyper-util = { version = "0.1.6", features = ["http1", "service", "server", "tokio"] } +hyper-util = { version = "0.1.6", features = [ + "http1", + "service", + "server", + "tokio", +] } mozprofile = "0.9" mozrunner = "0.15" serde = { version = "1.0", features = ["derive"] } diff --git a/crates/example-tests/tests/shell.rs b/crates/example-tests/tests/shell.rs index 19af0db4fec..f333e3a2058 100644 --- a/crates/example-tests/tests/shell.rs +++ b/crates/example-tests/tests/shell.rs @@ -34,14 +34,22 @@ macro_rules! shell_tests { } shell_tests! { + #[cfg(feature = "nightly")] #["RUSTUP_TOOLCHAIN" = "nightly"] raytrace_parallel = "raytrace-parallel", + #[cfg(feature = "stable")] synchronous_instantiation = "synchronous-instantiation", + #[cfg(feature = "stable")] wasm2js = "wasm2js", + #[cfg(feature = "nightly")] #["RUSTUP_TOOLCHAIN" = "nightly"] wasm_audio_worklet = "wasm-audio-worklet", + #[cfg(feature = "stable")] wasm_in_web_worker = "wasm-in-web-worker", + #[cfg(feature = "stable")] websockets = "websockets", + #[cfg(feature = "stable")] without_a_bundler = "without-a-bundler", + #[cfg(feature = "stable")] without_a_bundler_no_modules = "without-a-bundler-no-modules", } diff --git a/crates/example-tests/tests/webpack.rs b/crates/example-tests/tests/webpack.rs index d3927c2e6f9..8cc233283b3 100644 --- a/crates/example-tests/tests/webpack.rs +++ b/crates/example-tests/tests/webpack.rs @@ -48,6 +48,7 @@ async fn test_webpack_example(name: &str) -> anyhow::Result<()> { .await } +#[allow(unused_macros)] macro_rules! webpack_tests { ($( $(#[$attr:meta])* @@ -63,6 +64,7 @@ macro_rules! webpack_tests { }; } +#[cfg(feature = "stable")] webpack_tests! { add = "add", canvas = "canvas",