Skip to content

Commit bf31800

Browse files
committed
chore(ci): test against multiple platforms
1 parent 2da0d39 commit bf31800

11 files changed

Lines changed: 241 additions & 80 deletions

File tree

.github/workflows/ci.yml

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,99 @@
1-
name: CI Test
1+
name: CI
22

33
on:
44
push:
5-
paths: [ "src/**", "Cargo.toml"]
6-
workflow_dispatch: {}
5+
branches: ["main"]
6+
paths:
7+
- "src/**"
8+
- "Cargo.toml"
9+
- "Cargo.lock"
10+
- ".github/workflows/ci.yml"
11+
pull_request:
12+
paths:
13+
- "src/**"
14+
- "Cargo.toml"
15+
- "Cargo.lock"
16+
- ".github/workflows/ci.yml"
17+
merge_group:
18+
paths:
19+
- "src/**"
20+
- "Cargo.toml"
21+
- "Cargo.lock"
22+
- ".github/workflows/ci.yml"
23+
workflow_dispatch:
24+
25+
permissions:
26+
contents: read
727

828
env:
29+
RUSTFLAGS: -Dwarnings
30+
RUST_BACKTRACE: full
931
CARGO_TERM_COLOR: always
1032

1133
jobs:
1234
test:
13-
name: Build & Test
35+
name: Test (Rust ${{matrix.toolchain}}, ${{matrix.os}}, target ${{matrix.target}})
36+
runs-on: ${{matrix.os}}
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
toolchain: ["nightly", "beta", "stable", "1.83.0"]
41+
os: [ubuntu-latest, windows-latest, macos-latest]
42+
include:
43+
- os: ubuntu-latest
44+
target: x86_64-unknown-linux-gnu
45+
- os: windows-latest
46+
target: x86_64-pc-windows-msvc
47+
- os: macos-latest
48+
target: aarch64-apple-darwin
49+
timeout-minutes: 45
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
persist-credentials: false
54+
- uses: dtolnay/rust-toolchain@master
55+
with:
56+
toolchain: ${{matrix.toolchain}}
57+
components: llvm-tools, clippy, rust-src
58+
- uses: taiki-e/install-action@v2
59+
with:
60+
tool: just,cargo-llvm-cov,cargo-nextest
61+
- name: Enable type layout randomization
62+
if: matrix.toolchain == 'nightly'
63+
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
64+
- run: sudo apt-get update && sudo apt-get install -y musl-tools
65+
if: endsWith(matrix.target, 'musl')
66+
- run: rustup target add ${{matrix.target}}
67+
- run: just ci-test --target ${{matrix.target}}
68+
69+
docs:
70+
name: Documentation
71+
runs-on: ubuntu-latest
72+
timeout-minutes: 45
73+
env:
74+
RUSTDOCFLAGS: -Dwarnings
75+
steps:
76+
- uses: actions/checkout@v4
77+
with:
78+
persist-credentials: false
79+
- uses: dtolnay/rust-toolchain@nightly
80+
- uses: dtolnay/install@cargo-docs-rs
81+
- run: cargo docs-rs
82+
83+
clippy:
84+
name: Clippy
1485
runs-on: ubuntu-latest
86+
if: github.event_name != 'pull_request'
87+
timeout-minutes: 45
1588
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v4
89+
- uses: actions/checkout@v4
1890
with:
1991
persist-credentials: false
20-
- name: Read MSRV from Cargo.toml
21-
id: msrv
22-
run: |
23-
echo "MSRV=$(grep '^rust-version = ' Cargo.toml | cut -d'"' -f2)" >> $GITHUB_ENV
24-
- name: Setup Rust toolchain to MSRV
25-
uses: actions-rust-lang/setup-rust-toolchain@v1
92+
- uses: dtolnay/rust-toolchain@master
2693
with:
27-
toolchain: ${{ env.MSRV }}
28-
- name: Build
29-
run: cargo build --verbose
30-
# criterion breaks MSRV
31-
- name: Setup Rust toolchain to latest stable
32-
uses: actions-rust-lang/setup-rust-toolchain@v1
94+
toolchain: 1.83.0
95+
components: clippy
96+
- uses: taiki-e/install-action@v2
3397
with:
34-
toolchain: stable
35-
- name: Test
36-
run: cargo test --verbose
37-
env:
38-
RUST_BACKTRACE: 1
98+
tool: just
99+
- run: just clippy --all

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repository = "https://github.com/hanyu-dev/proxy-protocol-codec"
1717
crc32c = { version = "0.6.8", default-features = false, optional = true }
1818
slicur = { version = "0.3.0", optional = true }
1919
thiserror = { version = "2.0", optional = true }
20-
uni-addr = { version = "0.3.1", default-features = false, optional = true }
20+
uni-addr = { version = "0.3.4", default-features = false, optional = true }
2121
wrapper-lite = { version = "0.3.2", default-features = false }
2222

2323
[dev-dependencies]
@@ -65,9 +65,6 @@ feat-codec-v2-crc32c = ["feat-std", "dep:crc32c"]
6565
# Enable uni-addr support.
6666
feat-uni-addr = ["feat-std", "dep:uni-addr"]
6767

68-
# Deprecated features.
69-
feat-codec-v2-uni-addr = ["feat-uni-addr", "feat-std"]
70-
7168
[lints]
7269
clippy.allow_attributes_without_reason = "warn"
7370
clippy.assertions_on_result_states = "warn"

Justfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# just manual: https://github.com/casey/just#readme
2+
3+
_default:
4+
just --list
5+
6+
# Run all tests with nextest and cargo-llvm-cov
7+
ci-test *args:
8+
#!/bin/bash -eux
9+
cargo llvm-cov nextest {{args}} --locked --lcov --output-path coverage.lcov
10+
11+
# =========== LOCAL COMMANDS ===========
12+
13+
build *args:
14+
cargo build {{args}} --locked
15+
16+
b *args:
17+
just build {{args}}
18+
19+
# Show coverage locally
20+
cov *args:
21+
#!/bin/bash -eux
22+
cargo llvm-cov nextest {{args}} --locked --hide-instantiations --html --output-dir coverage
23+
24+
check *args:
25+
cargo check {{args}} --locked --all-features
26+
27+
c *args:
28+
just check {{args}}
29+
30+
clippy *args:
31+
cargo clippy {{args}} --locked --all-features -- -Dclippy::all -Dclippy::pedantic
32+
33+
example *args:
34+
cargo run --example {{args}}
35+
36+
e *args:
37+
just example {{args}}
38+
39+
msrv *args:
40+
cargo +1.83.0 clippy {{args}} --locked --all-features -- -Dclippy::all -Dclippy::pedantic
41+
42+
t *args:
43+
just test {{args}}
44+
45+
test *args:
46+
#!/bin/bash -eux
47+
export RUST_BACKTRACE=1
48+
cargo nextest run {{args}} --locked --all-features

src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
//! See [HAProxy](https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt) for the protocol specification.
44
55
#![no_std]
6-
#![cfg_attr(feature = "feat-nightly", feature(cold_path))]
7-
8-
#[cfg(feature = "feat-codec-v2-uni-addr")]
9-
compile_error!("The `feat-codec-v2-uni-addr` feature is deprecated. Please use the `feat-uni-addr` feature instead.");
6+
#![allow(clippy::must_use_candidate, reason = "XXX")]
7+
#![allow(clippy::return_self_not_must_use, reason = "XXX")]
108

119
#[cfg(feature = "feat-codec-v1")]
1210
pub mod v1;
@@ -35,7 +33,8 @@ impl Version {
3533
/// The magic bytes that indicate a PROXY Protocol v2 header.
3634
pub const MAGIC_V2: &'static [u8; 12] = b"\r\n\r\n\x00\r\nQUIT\n";
3735

38-
#[allow(clippy::result_unit_err)]
36+
#[allow(clippy::result_unit_err, reason = "XXX")]
37+
#[allow(clippy::missing_errors_doc, reason = "XXX")]
3938
#[inline]
4039
/// Peeks into the given buffer to determine if it contains a valid PROXY
4140
/// Protocol version magic.
@@ -45,18 +44,27 @@ impl Version {
4544
/// If the buffer is too short to determine the version, `Ok(None)` is
4645
/// returned. If the buffer contains a valid version magic,
4746
/// `Ok(Some(Version))` is returned. Otherwise, `Err(())` is returned.
47+
///
48+
/// ```
49+
/// # use proxy_protocol_codec::Version;
50+
/// let v1_magic = Version::MAGIC_V1.as_bytes();
51+
/// let v2_magic = Version::MAGIC_V2;
52+
/// assert_eq!(Version::peek(v1_magic), Ok(Some(Version::V1)));
53+
/// assert_eq!(Version::peek(&v1_magic[..3]), Ok(None));
54+
/// assert_eq!(Version::peek(v2_magic), Ok(Some(Version::V2)));
55+
/// assert_eq!(Version::peek(&v2_magic[..6]), Ok(None));
56+
/// # assert_eq!(Version::peek(&[0]), Err(()));
57+
/// ```
4858
pub fn peek(buf: &[u8]) -> Result<Option<Self>, ()> {
4959
const V1_MAGIC_LEN: usize = Version::MAGIC_V1.len();
5060
const V2_MAGIC_LEN: usize = Version::MAGIC_V2.len();
5161

52-
#[allow(overlapping_range_endpoints)]
53-
// Rust 1.77 doesn't support exclusive range endpoints in pattern matching.
5462
match buf.len() {
5563
0 => Ok(None),
5664
V2_MAGIC_LEN.. if buf.starts_with(Self::MAGIC_V2) => Ok(Some(Self::V2)),
65+
1..V2_MAGIC_LEN if Self::MAGIC_V2.starts_with(buf) => Ok(None),
5766
V1_MAGIC_LEN.. if buf.starts_with(Self::MAGIC_V1.as_bytes()) => Ok(Some(Self::V1)),
58-
1..=V2_MAGIC_LEN if Self::MAGIC_V2.starts_with(buf) => Ok(None),
59-
1..=V1_MAGIC_LEN if Self::MAGIC_V1.as_bytes().starts_with(buf) => Ok(None),
67+
1..V1_MAGIC_LEN if Self::MAGIC_V1.as_bytes().starts_with(buf) => Ok(None),
6068
_ => Err(()),
6169
}
6270
}

src/v1.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ impl Header {
105105
/// exceed the [`MAXIMUM_LENGTH`].
106106
///
107107
/// When any error is returned, the caller SHOULD reject the connection.
108+
///
109+
/// # Errors
110+
///
111+
/// See [`DecodeError`].
108112
pub fn decode(header_bytes: &[u8]) -> Result<Decoded, DecodeError> {
109113
// 1. Magic bytes flight check
110114
{

src/v1/model.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ impl AddressPair {
7373
#[cfg(feature = "feat-codec-v2")]
7474
#[inline]
7575
/// Converts a [`v2::AddressPair`] to an [`AddressPair`].
76+
///
77+
/// # Errors
78+
///
79+
/// See [`Unsupported`].
7680
pub const fn try_from_v2(value: v2::AddressPair) -> Result<Self, Unsupported> {
7781
match value {
7882
v2::AddressPair::Unspecified => Ok(Self::Unspecified),
@@ -104,6 +108,10 @@ impl AddressPair {
104108

105109
#[cfg(feature = "feat-uni-addr")]
106110
/// Returns the source address.
111+
///
112+
/// # Errors
113+
///
114+
/// This is infallible, but kept for API consistency.
107115
pub fn src_uni_addr(&self) -> io::Result<Option<uni_addr::UniAddr>> {
108116
use core::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
109117

@@ -120,6 +128,10 @@ impl AddressPair {
120128

121129
#[cfg(feature = "feat-uni-addr")]
122130
/// Returns the destination address.
131+
///
132+
/// # Errors
133+
///
134+
/// This is infallible, but kept for API consistency.
123135
pub fn dst_uni_addr(&self) -> io::Result<Option<uni_addr::UniAddr>> {
124136
use core::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
125137

src/v2.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ impl Header {
7676
#[cfg(feature = "feat-codec-decode")]
7777
#[inline]
7878
/// See [`HeaderDecoder::decode`].
79+
///
80+
/// # Errors
81+
///
82+
/// See [`DecodeError`].
7983
pub fn decode(encoded: &[u8]) -> Result<Decoded<'_>, DecodeError> {
8084
HeaderDecoder::decode(encoded)
8185
}

0 commit comments

Comments
 (0)