From 9ed18d92cfb85298f40db118271e8151ad055d42 Mon Sep 17 00:00:00 2001 From: Kai Jewson Date: Sun, 12 Dec 2021 14:19:30 +0000 Subject: [PATCH] Use `AtomicU32` in `RouteId` (#616) --- .github/workflows/CI.yml | 21 +++++++++++++++++++++ axum/Cargo.toml | 2 +- axum/src/routing/mod.rs | 13 +++++++++---- examples/jwt/src/main.rs | 2 +- examples/oauth/Cargo.toml | 3 ++- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 3654a094..18e6ab1f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -146,3 +146,24 @@ jobs: with: command: check ${{ matrix.checks }} arguments: --all-features --manifest-path axum/Cargo.toml + + armv5te-unknown-linux-musleabi: + needs: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: armv5te-unknown-linux-musleabi + override: true + profile: minimal + - uses: Swatinem/rust-cache@v1 + - name: Check + uses: actions-rs/cargo@v1 + env: + # Clang has native cross-compilation support + CC: clang + with: + command: check + args: --all --all-targets --all-features --target armv5te-unknown-linux-musleabi diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 095fc519..51651b7c 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -52,7 +52,7 @@ tokio-tungstenite = { optional = true, version = "0.16" } [dev-dependencies] futures = "0.3" -reqwest = { version = "0.11", features = ["json", "stream"] } +reqwest = { version = "0.11", default-features = false, features = ["json", "stream"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1.6.1", features = ["macros", "rt", "rt-multi-thread", "net"] } diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index 2fb937dd..f0bda4a4 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -48,13 +48,18 @@ pub use self::method_routing::{ }; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -struct RouteId(u64); +struct RouteId(u32); impl RouteId { fn next() -> Self { - use std::sync::atomic::{AtomicU64, Ordering}; - static ID: AtomicU64 = AtomicU64::new(0); - Self(ID.fetch_add(1, Ordering::SeqCst)) + use std::sync::atomic::{AtomicU32, Ordering}; + // `AtomicU64` isn't supported on all platforms + static ID: AtomicU32 = AtomicU32::new(0); + let id = ID.fetch_add(1, Ordering::Relaxed); + if id == u32::MAX { + panic!("Over `u32::MAX` routes created. If you need this, please file an issue."); + } + Self(id) } } diff --git a/examples/jwt/src/main.rs b/examples/jwt/src/main.rs index 6e3568b6..b13cedec 100644 --- a/examples/jwt/src/main.rs +++ b/examples/jwt/src/main.rs @@ -93,7 +93,7 @@ async fn authorize(Json(payload): Json) -> Result, A let claims = Claims { sub: "b@b.com".to_owned(), company: "ACME".to_owned(), - exp: 10000000000, + exp: 100000, }; // Create the authorization token let token = encode(&Header::default(), &claims, &KEYS.encoding) diff --git a/examples/oauth/Cargo.toml b/examples/oauth/Cargo.toml index 046f81e2..5b1d3c30 100644 --- a/examples/oauth/Cargo.toml +++ b/examples/oauth/Cargo.toml @@ -12,5 +12,6 @@ tracing-subscriber = { version="0.3", features = ["env-filter"] } oauth2 = "4.1" async-session = "3.0.0" serde = { version = "1.0", features = ["derive"] } -reqwest = { version = "0.11", features = ["json"] } +# Use Rustls because it makes it easier to cross-compile on CI +reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "json"] } headers = "0.3"