Skip to content

Commit

Permalink
Add CI; pre-emptively bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Sep 10, 2024
1 parent b0a458a commit 9fc8ff0
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 11 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/full_ci.yaml
Original file line number Diff line number Diff line change
@@ -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
80 changes: 80 additions & 0 deletions ci/install-rust.sh
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions ci/style.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions pkts-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ name = "pkts-common"
authors = ["Nathaniel Bennett <me[at]nathanielbennett[dotcom]>"]
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

Expand Down
6 changes: 4 additions & 2 deletions pkts-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ name = "pkts-macros"
description = "procedural macros for deriving `pkts` library traits"
authors = ["Nathaniel Bennett <me[at]nathanielbennett[dotcom]>"]
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
Expand Down
15 changes: 9 additions & 6 deletions pkts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
name = "pkts"
authors = ["Nathaniel Bennett <me[at]nathanielbennett[dotcom]>"]
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"]
Expand All @@ -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" }
2 changes: 1 addition & 1 deletion pktspec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pktspec"
authors = ["Nathaniel Bennett <me[at]nathanielbennett[dotcom]>"]
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
Expand Down

0 comments on commit 9fc8ff0

Please sign in to comment.