From 3465ddefaadc3e835f0bc41004601780dd1e812b Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Tue, 12 Sep 2023 17:50:50 +0300 Subject: [PATCH] Migrate to the generic Linebender CI script. (#135) --- .github/workflows/ci.yml | 108 +++++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 40 ------------- Cargo.toml | 9 ++- README.md | 2 +- crates/xilem_core/Cargo.toml | 7 +++ crates/xilem_html/Cargo.toml | 7 +++ crates/xilem_svg/Cargo.toml | 7 +++ src/bloom.rs | 2 +- 8 files changed, 139 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..9b21ea448 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,108 @@ +env: + # We aim to always test with the latest stable Rust toolchain, however we pin to a specific + # version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still + # come automatically. If the version specified here is no longer the latest stable version, + # then please feel free to submit a PR that adjusts it along with the potential clippy fixes. + RUST_STABLE_VER: "1.72" # In quotes because otherwise 1.70 would be interpreted as 1.7 + +# Rationale +# +# We don't run clippy with --all-targets because then even --lib and --bins are compiled with +# dev dependencies enabled, which does not match how they would be compiled by users. +# A dev dependency might enable a feature of a regular dependency that we need, but testing +# with --all-targets would not catch that. Thus we split --lib & --bins into a separate step. + +name: CI + +on: + pull_request: + merge_group: + +jobs: + rustfmt: + runs-on: ubuntu-latest + name: cargo fmt + steps: + - uses: actions/checkout@v4 + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + components: rustfmt + + - name: cargo fmt + run: cargo fmt --all --check + + test-stable: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-latest] + name: cargo clippy + test + steps: + - uses: actions/checkout@v4 + + - name: install additional linux dependencies + run: | + sudo apt update + sudo apt install libwayland-dev libxkbcommon-x11-dev + if: contains(matrix.os, 'ubuntu') + + - name: install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_STABLE_VER }} + components: clippy + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: cargo clippy (no default features) + run: cargo clippy --workspace --lib --bins --no-default-features -- -D warnings + # No default features means no backend on Linux, so we won't run it + if: contains(matrix.os, 'ubuntu') == false + + - name: cargo clippy (no default features) (auxiliary) + run: cargo clippy --workspace --tests --benches --examples --no-default-features -- -D warnings + # No default features means no backend on Linux, so we won't run it + if: contains(matrix.os, 'ubuntu') == false + + - name: cargo clippy (default features) + run: cargo clippy --workspace --lib --bins -- -D warnings + + - name: cargo clippy (default features) (auxiliary) + run: cargo clippy --workspace --tests --benches --examples -- -D warnings + + - name: cargo clippy (all features) + run: cargo clippy --workspace --lib --bins --all-features -- -D warnings + + - name: cargo clippy (all features) (auxiliary) + run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings + + - name: cargo test + run: cargo test --workspace --all-features + + docs: + name: cargo doc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + + - name: install additional linux dependencies + run: | + sudo apt update + sudo apt install libwayland-dev libxkbcommon-x11-dev + if: contains(matrix.os, 'ubuntu') + + - name: install nightly toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: restore cache + uses: Swatinem/rust-cache@v2 + + - name: cargo doc + run: cargo doc --workspace --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index b0364cb76..000000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Rust - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - check: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [macOS-latest, windows-2019, ubuntu-latest] - steps: - - name: install libx11-dev - run: | - sudo apt update - sudo apt install libx11-dev libpango1.0-dev libxkbcommon-dev libxkbcommon-x11-dev - if: runner.os == 'Linux' - - uses: actions/checkout@v3 - - name: Rust Toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - # rustfmt is already in the default components, but this is how platform dependencies could be used conditionally - # components: ${{ runner.os == 'Linux' && 'rustfmt' || '' }} - - name: Restore Cache - uses: Swatinem/rust-cache@v2 - - name: Cargo Format - # We'll only run this on one platform. - run: cargo fmt --all -- --check - if: runner.os == 'Linux' - - name: Cargo Clippy - run: cargo clippy --workspace -- -D warnings - - name: Cargo Test - run: cargo test --no-fail-fast --workspace diff --git a/Cargo.toml b/Cargo.toml index bd1e03be4..7a813d401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [workspace] members = [ "crates/xilem_core", - "crates/xilem_svg", "crates/xilem_html", "crates/xilem_html/web_examples/counter", "crates/xilem_html/web_examples/counter_untyped", "crates/xilem_html/web_examples/todomvc", + "crates/xilem_svg", ] [workspace.package] @@ -31,6 +31,13 @@ edition.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +default-target = "x86_64-pc-windows-msvc" +# rustdoc-scrape-examples tracking issue https://github.com/rust-lang/rust/issues/88791 +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] + [features] default = ["x11"] diff --git a/README.md b/README.md index cb6ec93ef..1cb21356c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Xi Zulip](https://img.shields.io/badge/Xi%20Zulip-%23xilem-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/354396-xilem) [![dependency status](https://deps.rs/repo/github/linebender/xilem/status.svg)](https://deps.rs/repo/github/linebender/xilem) [![Apache 2.0](https://img.shields.io/badge/license-Apache-blue.svg)](#license) -[![Build Status](https://github.com/linebender/xilem/actions/workflows/rust.yml/badge.svg)](https://github.com/linebender/xilem/actions) +[![Build Status](https://github.com/linebender/xilem/actions/workflows/ci.yml/badge.svg)](https://github.com/linebender/xilem/actions) diff --git a/crates/xilem_core/Cargo.toml b/crates/xilem_core/Cargo.toml index 6fa26db8e..a44643da5 100644 --- a/crates/xilem_core/Cargo.toml +++ b/crates/xilem_core/Cargo.toml @@ -10,4 +10,11 @@ edition.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +default-target = "x86_64-pc-windows-msvc" +# rustdoc-scrape-examples tracking issue https://github.com/rust-lang/rust/issues/88791 +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] + [dependencies] diff --git a/crates/xilem_html/Cargo.toml b/crates/xilem_html/Cargo.toml index c0c42baf6..35fecb98f 100644 --- a/crates/xilem_html/Cargo.toml +++ b/crates/xilem_html/Cargo.toml @@ -10,6 +10,13 @@ edition.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +default-target = "x86_64-pc-windows-msvc" +# rustdoc-scrape-examples tracking issue https://github.com/rust-lang/rust/issues/88791 +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] + [features] default = ["typed"] typed = [ diff --git a/crates/xilem_svg/Cargo.toml b/crates/xilem_svg/Cargo.toml index 3d5f7a2a4..7e9e2a61f 100644 --- a/crates/xilem_svg/Cargo.toml +++ b/crates/xilem_svg/Cargo.toml @@ -10,6 +10,13 @@ edition.workspace = true homepage.workspace = true repository.workspace = true +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +default-target = "x86_64-pc-windows-msvc" +# rustdoc-scrape-examples tracking issue https://github.com/rust-lang/rust/issues/88791 +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] + [lib] crate-type = ["cdylib"] diff --git a/src/bloom.rs b/src/bloom.rs index 4c13ee9e0..1571ef330 100644 --- a/src/bloom.rs +++ b/src/bloom.rs @@ -42,7 +42,7 @@ impl Bloom { /// Does not count unique entries; this is just the number of times /// `add()` was called since the filter was created or last `clear()`ed. // it feels wrong to call this 'len'? - #[cfg(test)] + #[allow(dead_code)] pub fn entry_count(&self) -> usize { self.entry_count }