diff --git a/.github/workflows/full_ci.yaml b/.github/workflows/full_ci.yaml new file mode 100644 index 0000000..0272101 --- /dev/null +++ b/.github/workflows/full_ci.yaml @@ -0,0 +1,36 @@ +name: full CI + +on: + merge_group: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + style_check: + name: Style check + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + run: sh ./ci/install-rust.sh + - name: Check style + run: sh ci/style.sh + + build_channels_linux: + name: Build Channels Linux + runs-on: ubuntu-22.04 + env: + OS: linux + strategy: + fail-fast: true + max-parallel: 2 + matrix: + toolchain: + - stable + - 1.66.0 + steps: + - uses: actions/checkout@v4 + - name: Setup Rust toolchain + run: TOOLCHAIN=${{ matrix.toolchain }} sh ./ci/install-rust.sh + - name: Execute run.sh + run: TOOLCHAIN=${{ matrix.toolchain }} sh ./ci/run.sh diff --git a/ci/install-rust.sh b/ci/install-rust.sh new file mode 100755 index 0000000..9b3b008 --- /dev/null +++ b/ci/install-rust.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env sh +# This is intended to be used in CI only. + +set -ex + +echo "Setup toolchain" +toolchain= +if [ -n "$TOOLCHAIN" ]; then + toolchain=$TOOLCHAIN +else + toolchain=stable +fi +if [ "$OS" = "windows" ]; then + : "${TARGET?The TARGET environment variable must be set.}" + rustup set profile minimal + rustup update --force "$toolchain-$TARGET" + rustup default "$toolchain-$TARGET" +else + rustup set profile minimal + rustup update --force "$toolchain" + rustup default "$toolchain" +fi + +if [ -n "$TARGET" ]; then + echo "Install target" + rustup target add "$TARGET" +fi + +if [ -n "$INSTALL_RUST_SRC" ]; then + echo "Install rust-src" + rustup component add rust-src +fi + +if [ "$OS" = "windows" ]; then + if [ "$ARCH_BITS" = "i686" ]; then + echo "Install MinGW32" + choco install mingw --x86 --force + fi + + echo "Find GCC libraries" + gcc -print-search-dirs + /usr/bin/find "C:\ProgramData\Chocolatey" -name "crt2*" + /usr/bin/find "C:\ProgramData\Chocolatey" -name "dllcrt2*" + /usr/bin/find "C:\ProgramData\Chocolatey" -name "libmsvcrt*" + + if [ -n "$ARCH_BITS" ]; then + echo "Fix MinGW" + for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do + cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw$ARCH_BITS/$ARCH-w64-mingw32/lib/$i" "$(rustc --print sysroot)/lib/rustlib/$TARGET/lib" + done + fi + + # Install Wintun + echo "Install Wintun" + curl.exe -o wintun.zip https://www.wintun.net/builds/wintun-0.14.1.zip + powershell.exe -NoP -NonI -Command "Expand-Archive './wintun.zip' './'" + cp -f "./wintun/bin/amd64/wintun.dll" "./" + rm -rf "./wintun" +fi + +echo "Query rust and cargo versions" +command -v rustc +command -v cargo +command -v rustup +rustc -Vv +cargo -V +rustup -Vv +rustup show + +echo "Generate lockfile" +N=5 +n=0 +until [ $n -ge $N ] +do + if cargo generate-lockfile; then + break + fi + n=$((n+1)) + sleep 1 +done \ No newline at end of file diff --git a/ci/run.sh b/ci/run.sh new file mode 100755 index 0000000..c332147 --- /dev/null +++ b/ci/run.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh + +# Builds and runs tests for a particular target passed as an argument to this +# script. + +set -ex + +: "${TOOLCHAIN?The TOOLCHAIN environment variable must be set.}" +: "${OS?The OS environment variable must be set.}" + +RUST=${TOOLCHAIN} + +echo "Testing Rust ${RUST} on ${OS}" + +# FIXME: rustup often fails to download some artifacts due to network +# issues, so we retry this N times. +N=5 +n=0 +until [ $n -ge $N ] +do + if rustup override set "${RUST}" ; then + break + fi + n=$((n+1)) + sleep 1 +done + +case "${OS}" in + windows*) + cargo test --features wintun + + cargo test --features wintun-runtime + + cargo test --features tapwin6 + + cargo test --features tapwin6-runtime + ;; + *) + # No extra features in any platform other than windows + + cargo test + ;; +esac diff --git a/ci/style.sh b/ci/style.sh new file mode 100755 index 0000000..f72357e --- /dev/null +++ b/ci/style.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -ex + +rustup toolchain install nightly -c rustfmt --allow-downgrade +rustup override set nightly +command -v rustfmt +rustfmt -V +cargo fmt --all -- --check + +if shellcheck --version ; then + # GHA's shellcheck is too old (0.4.6) and cannot handle SC2153 correctly. + shellcheck -e SC2103 -e SC2153 ci/*.sh +else + echo "shellcheck not found" + exit 1 +fi \ No newline at end of file diff --git a/pkts-common/Cargo.toml b/pkts-common/Cargo.toml index 6e7d3db..2d3b138 100644 --- a/pkts-common/Cargo.toml +++ b/pkts-common/Cargo.toml @@ -3,9 +3,11 @@ name = "pkts-common" authors = ["Nathaniel Bennett "] description = "helper library for shared types/utilities among rscap and pkts" license = "MIT OR Apache-2.0" -version = "0.1.0" +version = "0.2.0" edition = "2021" -repository = "https://github.com/pkts-rs/rscap" +repository = "https://github.com/pkts-rs/pkts" +keywords = ["packets", "network", "scapy", "parsing"] +categories = ["network-programming", "encoding", "parsing"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/pkts-macros/Cargo.toml b/pkts-macros/Cargo.toml index 850330c..9866d5a 100644 --- a/pkts-macros/Cargo.toml +++ b/pkts-macros/Cargo.toml @@ -3,9 +3,11 @@ name = "pkts-macros" description = "procedural macros for deriving `pkts` library traits" authors = ["Nathaniel Bennett "] license = "MIT OR Apache-2.0" -version = "0.1.3" +version = "0.2.0" edition = "2021" -repository = "https://github.com/pkts-rs/rscap" +repository = "https://github.com/pkts-rs/pkts" +keywords = ["packets", "network", "scapy", "parsing"] +categories = ["network-programming", "encoding", "parsing"] [lib] proc-macro = true diff --git a/pkts/Cargo.toml b/pkts/Cargo.toml index 52f4e1a..34cee3f 100644 --- a/pkts/Cargo.toml +++ b/pkts/Cargo.toml @@ -2,11 +2,14 @@ name = "pkts" authors = ["Nathaniel Bennett "] description = "tools for building, inspecting and modifying network protocol packets" -rust-version = "1.65" # GATs stabilized in this version; required for `Sequence` types +# GATs stabilized in this version; required for `Sequence` types +rust-version = "1.66" license = "MIT OR Apache-2.0" -version = "0.1.3" +version = "0.2.0" edition = "2021" -repository = "https://github.com/pkts-rs/rscap" +repository = "https://github.com/pkts-rs/pkts" +keywords = ["packets", "network", "scapy", "parsing"] +categories = ["network-programming", "encoding", "parsing"] [features] default = ["std", "custom_layer_selection", "error_string"] @@ -16,6 +19,6 @@ error_string = [] custom_layer_selection = ["pkts-macros/custom_layer_selection"] [dependencies] -bitflags = { version = "2.6" } -pkts-macros = { path = "../pkts-macros", version = "0.1.3" } -pkts-common = { path = "../pkts-common", version = "0.1.0" } +bitflags = { version = "2.6.0" } +pkts-macros = { path = "../pkts-macros", version = "0.2.0" } +pkts-common = { path = "../pkts-common", version = "0.2.0" } diff --git a/pktspec/Cargo.toml b/pktspec/Cargo.toml index 0b6dd99..dab9232 100644 --- a/pktspec/Cargo.toml +++ b/pktspec/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pktspec" authors = ["Nathaniel Bennett "] -version = "0.1.1" +version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html