Skip to content

Commit

Permalink
fix(ci): nasm on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed May 27, 2024
1 parent 11a305b commit 61d3d89
Show file tree
Hide file tree
Showing 61 changed files with 223 additions and 200 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ on:
push:
branches:
- main
- '[0-9]+.[0-9]+.x'
- "[0-9]+.[0-9]+.x"
schedule:
- cron: "0 2 * * *"
workflow_dispatch:

env:
CARGO_INCREMENTAL: 0
CARGO_NET_GIT_FETCH_WITH_CLI: true
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
CARGO_PROFILE_TEST_BUILD_OVERRIDE_DEBUG: true
RUST_BACKTRACE: 1
RUSTUP_MAX_RETRIES: 10
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

jobs:
test:
Expand All @@ -26,6 +33,9 @@ jobs:
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- if: runner.os == 'Windows'
name: Install NASM for aws-lc-rs on Windows
uses: ilammy/setup-nasm@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo test --workspace --verbose
Expand Down
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,22 @@ debug = false

[workspace.lints.rust]
unsafe_code = "forbid"
rust_2018_idioms = "warn"
# rust_2018_idioms = "warn"
single_use_lifetimes = "warn"
non_ascii_idents = "warn"
non_local_definitions = 'warn'
unreachable_pub = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"

[workspace.lints.clippy]
all = "deny"
pedantic = "deny"
missing_errors_doc = "warn"
needless_pass_by_value = "warn"
all = "warn" # Downgrade deny-by-default lints
pedantic = "warn"
missing_errors_doc = { level = "allow", priority = 1 }
module_name_repetitions = { level = "allow", priority = 1 }
too_many_lines = { level = "allow", priority = 1 }
type_complexity = { level = "allow", priority = 1 }
lint_groups_priority = { level = "allow", priority = 1 } # https://github.com/rust-lang/rust-clippy/issues/12270

[workspace.lints.rustdoc]
private_intra_doc_links = 'allow'
4 changes: 2 additions & 2 deletions viz-core/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sync_wrapper::SyncWrapper;
use crate::{BoxError, Error, HttpBody, Result};

/// A body state.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BodyState {
/// The body is inited.
Normal,
Expand Down Expand Up @@ -41,7 +41,7 @@ pub enum Body<D = Bytes> {
impl Body {
/// Creates an empty body.
#[must_use]
pub fn empty() -> Self {
pub const fn empty() -> Self {
Self::Empty
}

Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ pub trait HandlerExt<I>: Handler<I> {
}
}

impl<I, T: ?Sized> HandlerExt<I> for T where T: Handler<I> {}
impl<I, T> HandlerExt<I> for T where T: ?Sized + Handler<I> {}
2 changes: 1 addition & 1 deletion viz-core/src/handler/after.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct After<H, F> {
impl<H, F> After<H, F> {
/// Creates an [`After`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/and_then.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct AndThen<H, F> {
impl<H, F> AndThen<H, F> {
/// Creates an [`AndThen`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/around.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Around<H, F> {
impl<H, F> Around<H, F> {
/// Creates an [`Around`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/before.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Before<H, F> {
impl<H, F> Before<H, F> {
/// Creates a [`Before`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/catch_unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct CatchUnwind<H, F> {
impl<H, F> CatchUnwind<H, F> {
/// Creates an [`CatchUnwind`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 2 additions & 0 deletions viz-core/src/handler/cloneable.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::redundant_pub_crate)]

use super::Handler;

pub(crate) type BoxCloneable<Input, Output> = Box<dyn Cloneable<Input, Output = Output>>;
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Map<H, F> {
impl<H, F> Map<H, F> {
/// Creates a [`Map`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/map_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct MapErr<H, F> {
impl<H, F> MapErr<H, F> {
/// Creates a [`MapErr`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/map_into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct MapInToResponse<H>(pub(crate) H);
impl<H> MapInToResponse<H> {
/// Creates a [`MapInToResponse`] handler.
#[inline]
pub fn new(h: H) -> Self {
pub const fn new(h: H) -> Self {
Self(h)
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/or_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct OrElse<H, F> {
impl<H, F> OrElse<H, F> {
/// Creates an [`OrElse`] handler.
#[inline]
pub fn new(h: H, f: F) -> Self {
pub const fn new(h: H, f: F) -> Self {
Self { h, f }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/handler/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct ServiceHandler<S>(S);

impl<S> ServiceHandler<S> {
/// Creates a new [`ServiceHandler`].
pub fn new(s: S) -> Self {
pub const fn new(s: S) -> Self {
Self(s)
}
}
Expand Down
12 changes: 6 additions & 6 deletions viz-core/src/into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ impl IntoResponse for Response {
impl IntoResponse for Error {
fn into_response(self) -> Response {
match self {
Error::Boxed(error) => {
Self::Boxed(error) => {
let body = error.to_string();
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.header(CONTENT_LENGTH, body.len())
.body(Full::from(body).into())
.unwrap()
}
Error::Responder(resp) | Error::Report(_, resp) => resp,
Self::Responder(resp) | Self::Report(_, resp) => resp,
}
}
}
Expand Down Expand Up @@ -109,10 +109,10 @@ where
T: IntoResponse,
{
fn into_response(self) -> Response {
match self {
Some(r) => r.into_response(),
None => StatusCode::NOT_FOUND.into_response(),
}
self.map_or_else(
|| StatusCode::NOT_FOUND.into_response(),
IntoResponse::into_response,
)
}
}

Expand Down
12 changes: 6 additions & 6 deletions viz-core/src/middleware/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct Compress<T> {

impl<T> Compress<T> {
/// Creates a compressed response with the specified algorithm.
pub fn new(inner: T, algo: ContentCoding) -> Self {
pub const fn new(inner: T, algo: ContentCoding) -> Self {
Self { inner, algo }
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<T: IntoResponse> IntoResponse for Compress<T> {
/// [`ContentCoding`]
///
/// [`ContentCoding`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum ContentCoding {
/// gzip
Gzip,
Expand All @@ -117,13 +117,13 @@ impl FromStr for ContentCoding {

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.eq_ignore_ascii_case("deflate") {
Ok(ContentCoding::Deflate)
Ok(Self::Deflate)
} else if s.eq_ignore_ascii_case("gzip") {
Ok(ContentCoding::Gzip)
Ok(Self::Gzip)
} else if s.eq_ignore_ascii_case("br") {
Ok(ContentCoding::Brotli)
Ok(Self::Brotli)
} else if s == "*" {
Ok(ContentCoding::Any)
Ok(Self::Any)
} else {
Err(())
}
Expand Down
4 changes: 2 additions & 2 deletions viz-core/src/middleware/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Config {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
#[must_use]
pub fn max_age(mut self, max_age: usize) -> Self {
pub const fn max_age(mut self, max_age: usize) -> Self {
self.max_age = max_age;
self
}
Expand All @@ -46,7 +46,7 @@ impl Config {
///
/// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
#[must_use]
pub fn credentials(mut self, credentials: bool) -> Self {
pub const fn credentials(mut self, credentials: bool) -> Self {
self.credentials = credentials;
self
}
Expand Down
36 changes: 19 additions & 17 deletions viz-core/src/middleware/csrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ where
pub fn get(&self, req: &Request) -> Result<Option<Vec<u8>>> {
let inner = self.as_ref();
match inner.store {
Store::Cookie => {
match self
.get_cookie(&req.cookies()?)
.map(|c| c.value().to_string())
{
None => Ok(None),
Some(raw_token) => base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(raw_token)
.ok()
.filter(|b| b.len() == 64)
.map(unmask::<32>)
.map(Option::Some)
.ok_or_else(|| {
(StatusCode::INTERNAL_SERVER_ERROR, "Invalid csrf token").into_error()
}),
}
}
Store::Cookie => self
.get_cookie(&req.cookies()?)
.map(|c| c.value().to_string())
.map_or_else(
|| Ok(None),
|raw_token| {
base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(raw_token)
.ok()
.filter(|b| b.len() == 64)
.map(unmask::<32>)
.map(Option::Some)
.ok_or_else(|| {
(StatusCode::INTERNAL_SERVER_ERROR, "Invalid csrf token")
.into_error()
})
},
),
#[cfg(feature = "session")]
Store::Session => req.session().get(inner.cookie_options.name),
}
Expand Down Expand Up @@ -261,6 +262,7 @@ pub fn verify(secret: &[u8], raw_token: String) -> bool {
}

/// Retures masked token
#[allow(clippy::needless_collect)]
fn mask(secret: &[u8], mut otp: Vec<u8>) -> Vec<u8> {
otp.extend::<Vec<u8>>(
secret
Expand Down
8 changes: 4 additions & 4 deletions viz-core/src/middleware/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CookieOptions {

/// Creates new `CookieOptions` with `name`
#[must_use]
pub fn name(mut self, name: &'static str) -> Self {
pub const fn name(mut self, name: &'static str) -> Self {
self.name = name;
self
}
Expand All @@ -56,21 +56,21 @@ impl CookieOptions {

/// Creates new `CookieOptions` with `path`
#[must_use]
pub fn path(mut self, path: &'static str) -> Self {
pub const fn path(mut self, path: &'static str) -> Self {
self.path = path;
self
}

/// Creates new `CookieOptions` with `secure`
#[must_use]
pub fn secure(mut self, secure: bool) -> Self {
pub const fn secure(mut self, secure: bool) -> Self {
self.secure = secure;
self
}

/// Creates new `CookieOptions` with `http_only`
#[must_use]
pub fn http_only(mut self, http_only: bool) -> Self {
pub const fn http_only(mut self, http_only: bool) -> Self {
self.http_only = http_only;
self
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/middleware/otel/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Config {
.with_unit(Unit::new("By"))
.init();

Config {
Self {
active_requests,
duration,
request_size,
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/middleware/otel/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct RequestHeaderCarrier<'a> {
}

impl<'a> RequestHeaderCarrier<'a> {
fn new(headers: &'a HeaderMap) -> Self {
const fn new(headers: &'a HeaderMap) -> Self {
RequestHeaderCarrier { headers }
}
}
Expand Down
2 changes: 1 addition & 1 deletion viz-core/src/middleware/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ where
}
}

fn max_age() -> Duration {
const fn max_age() -> Duration {
Duration::from_secs(CookieOptions::MAX_AGE)
}
Loading

0 comments on commit 61d3d89

Please sign in to comment.