diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6deb479..e3ddd75 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,10 +20,10 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Install Rust stable + - name: Install Rust beta run: | - rustup update --no-self-update stable - rustup default stable + rustup update --no-self-update beta + rustup default beta - name: Cache dependencies uses: Swatinem/rust-cache@v2 @@ -40,7 +40,7 @@ jobs: test: strategy: matrix: - rust: [stable] + rust: [stable, beta] name: Test ${{ matrix.rust }} runs-on: ubuntu-latest timeout-minutes: 15 @@ -48,11 +48,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Disable high-priority rust-toolchain.toml + run: rm rust-toolchain.toml + - name: Install Rust ${{ matrix.rust }} run: | rustup update --no-self-update ${{ matrix.rust }} rustup default ${{ matrix.rust }} + - name: Disable integration tests on stable rustc + if: matrix.rust == 'stable' + run: mv ./blahd/tests{,-disabled} + - name: Cache Dependencies uses: Swatinem/rust-cache@v2 diff --git a/Cargo.toml b/Cargo.toml index aea0622..26683d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ default-members = ["blahd"] [workspace.lints.clippy] -allow_attributes = "warn" +allow_attributes_without_reason = "warn" dbg_macro = "warn" print_stderr = "warn" print_stdout = "warn" diff --git a/blahd/src/lib.rs b/blahd/src/lib.rs index 606823a..abb32be 100644 --- a/blahd/src/lib.rs +++ b/blahd/src/lib.rs @@ -119,6 +119,10 @@ type RE = R; async fn handle_ws(State(st): ArcState, ws: WebSocketUpgrade) -> Response { ws.on_upgrade(move |mut socket| async move { match event::handle_ws(st, &mut socket).await { + #[allow( + unreachable_patterns, + reason = "compatibility before min_exhaustive_patterns" + )] Ok(never) => match never {}, Err(err) if err.is::() => {} Err(err) => { diff --git a/blahd/tests/basic.rs b/blahd/tests/basic.rs index c0aab5c..f5bfdd7 100644 --- a/blahd/tests/basic.rs +++ b/blahd/tests/basic.rs @@ -1,7 +1,7 @@ #![expect(clippy::unwrap_used, reason = "FIXME: random false positive")] #![expect(clippy::toplevel_ref_arg, reason = "easy to use for fixtures")] use std::fmt; -use std::future::IntoFuture; +use std::future::{Future, IntoFuture}; use std::sync::{Arc, LazyLock}; use anyhow::Result; @@ -144,7 +144,7 @@ async fn smoke(server: Server) { assert_eq!(got, exp); } -fn sign(key: &SigningKey, rng: &mut impl RngCore, payload: T) -> WithSig { +fn sign(key: &SigningKey, rng: &mut dyn RngCore, payload: T) -> WithSig { WithSig::sign(key, get_timestamp(), rng, payload).unwrap() } @@ -152,13 +152,13 @@ fn auth(key: &SigningKey, rng: &mut impl RngCore) -> String { serde_json::to_string(&sign(key, rng, AuthPayload {})).unwrap() } -async fn create_room( - server: &Server, +fn create_room<'s>( + server: &'s Server, key: &SigningKey, - rng: &mut impl RngCore, + rng: &mut dyn RngCore, attrs: RoomAttrs, - title: impl fmt::Display, -) -> Result { + title: &str, +) -> impl Future> + use<'s> { let req = sign( key, rng, @@ -171,10 +171,12 @@ async fn create_room( title: title.to_string(), }, ); - Ok(server - .request(Method::POST, "/room/create", None, Some(&req)) - .await? - .unwrap()) + async move { + Ok(server + .request(Method::POST, "/room/create", None, Some(&req)) + .await? + .unwrap()) + } } #[rstest] @@ -202,15 +204,9 @@ async fn room_create_get(server: Server, ref mut rng: impl RngCore, #[case] publ room_meta.rid = rid; // Bob has no permission. - create_room( - &server, - &BOB_PRIV, - rng, - room_meta.attrs, - room_meta.title.clone(), - ) - .await - .expect_api_err(StatusCode::FORBIDDEN, "permission_denied"); + create_room(&server, &BOB_PRIV, rng, room_meta.attrs, &room_meta.title) + .await + .expect_api_err(StatusCode::FORBIDDEN, "permission_denied"); // Alice can always access it. let got_meta = server diff --git a/flake.lock b/flake.lock index 51c9ceb..f5d3cbf 100644 --- a/flake.lock +++ b/flake.lock @@ -39,7 +39,28 @@ "root": { "inputs": { "naersk": "naersk", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1725935143, + "narHash": "sha256-mVtTVQMlXkydSXVwFClE0ckxHrOQ9nb2DrCjNwW5pUE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c3c175c74cd0e8c2c40a0e22bc6e3005c4d28d64", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 83ea914..678f28e 100644 --- a/flake.nix +++ b/flake.nix @@ -7,6 +7,10 @@ rec { url = "github:nix-community/naersk"; inputs.nixpkgs.follows = "nixpkgs"; }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = @@ -14,6 +18,7 @@ rec { self, nixpkgs, naersk, + rust-overlay, }: let inherit (nixpkgs) lib; @@ -26,7 +31,13 @@ rec { system: let pkgs = nixpkgs.legacyPackages.${system}; - naersk' = pkgs.callPackage naersk { }; + rustBin = rust-overlay.lib.mkRustBin { } pkgs; + toolchain = rustBin.fromRustupToolchainFile ./rust-toolchain.toml; + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + }; + mkPkg = { pkg-config, @@ -75,6 +86,21 @@ rec { } ); + devShells = eachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + nativeBuildInputs = [ pkgs.buildPackages.sqlite-interactive ]; + + env.RUST_LOG = "blahd=debug,blahctl=debug"; + }; + } + ); + nixosModules = rec { default = blahd; blahd = import ./contrib/module.nix { diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..d116724 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,7 @@ +# WAIT: Rust 1.82 release on 2024-10-17 +# Used features: +# - min_exhaustive_patterns: https://github.com/rust-lang/rust/issues/119612 +# - precise_capturing: https://github.com/rust-lang/rust/issues/123432 +[toolchain] +channel = "beta-2024-09-10" # 1.82.0-beta.3 +profile = "default" diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 8d8c70e..0000000 --- a/shell.nix +++ /dev/null @@ -1,7 +0,0 @@ -with import { }; -mkShell { - nativeBuildInputs = [ pkg-config sqlite-interactive ]; - buildInputs = [ openssl.dev sqlite.dev ]; - - env.RUST_LOG = "blahd=debug,blahctl=debug"; -}