Skip to content

Commit

Permalink
refactor: split trippy into multiple crates (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed May 18, 2024
1 parent 3645162 commit 04275b9
Show file tree
Hide file tree
Showing 126 changed files with 1,188 additions and 752 deletions.
388 changes: 202 additions & 186 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,193 +7,209 @@ on:
name: CI

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux-stable
- linux-musl-stable
- linux-beta
- linux-nightly
- macos-stable
- macos-stable-arm64
- windows-stable
include:
- build: linux-stable
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rust: stable
- build: linux-musl-stable
os: ubuntu-22.04
target: x86_64-unknown-linux-musl
rust: stable
- build: linux-beta
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rust: beta
- build: linux-nightly
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rust: nightly
- build: macos-stable
os: macos-13
target: x86_64-apple-darwin
rust: stable
- build: macos-stable-arm64
os: macos-14
target: aarch64-apple-darwin
rust: stable
- build: windows-stable
os: windows-2022
target: x86_64-pc-windows-msvc
rust: stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- run: cargo test --target ${{ matrix.target }}

build-cross:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [ netbsd, freebsd ]
include:
- build: netbsd
os: ubuntu-22.04
target: x86_64-unknown-netbsd
rust: stable
- build: freebsd
os: ubuntu-22.04
target: x86_64-unknown-freebsd
rust: stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Use Cross
shell: bash
run: |
cargo install cross --git https://github.com/cross-rs/cross
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
- name: cross build
run: cross build --target ${{ matrix.target }} --verbose
# test:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# build:
# - linux-stable
# - linux-musl-stable
# - linux-beta
# - linux-nightly
# - macos-stable
# - macos-stable-arm64
# - windows-stable
# include:
# - build: linux-stable
# os: ubuntu-22.04
# target: x86_64-unknown-linux-gnu
# rust: stable
# - build: linux-musl-stable
# os: ubuntu-22.04
# target: x86_64-unknown-linux-musl
# rust: stable
# - build: linux-beta
# os: ubuntu-22.04
# target: x86_64-unknown-linux-gnu
# rust: beta
# - build: linux-nightly
# os: ubuntu-22.04
# target: x86_64-unknown-linux-gnu
# rust: nightly
# - build: macos-stable
# os: macos-13
# target: x86_64-apple-darwin
# rust: stable
# - build: macos-stable-arm64
# os: macos-14
# target: aarch64-apple-darwin
# rust: stable
# - build: windows-stable
# os: windows-2022
# target: x86_64-pc-windows-msvc
# rust: stable
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# - uses: Swatinem/rust-cache@v2
# - run: cargo test --target ${{ matrix.target }}
#
# build-cross:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# build: [ netbsd, freebsd ]
# include:
# - build: netbsd
# os: ubuntu-22.04
# target: x86_64-unknown-netbsd
# rust: stable
# - build: freebsd
# os: ubuntu-22.04
# target: x86_64-unknown-freebsd
# rust: stable
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# - uses: Swatinem/rust-cache@v2
# - name: Use Cross
# shell: bash
# run: |
# cargo install cross --git https://github.com/cross-rs/cross
# - name: Show command used for Cargo
# run: |
# echo "cargo command is: ${{ env.CARGO }}"
# echo "target flag is: ${{ env.TARGET_FLAGS }}"
# - name: cross build
# run: cross build --target ${{ matrix.target }} --verbose
#
# sim-test:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# build:
# - linux-stable
# - macos-stable
# - windows-stable
# include:
# - build: linux-stable
# os: ubuntu-22.04
# target: x86_64-unknown-linux-gnu
# rust: stable
# - build: macos-stable
# os: macos-13
# target: x86_64-apple-darwin
# rust: stable
# - build: windows-stable
# os: windows-2022
# target: x86_64-pc-windows-msvc
# rust: stable
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: ${{ matrix.rust }}
# target: ${{ matrix.target }}
# - uses: Swatinem/rust-cache@v2
# - name: Copy wintun.dll to current dir
# if: startsWith(matrix.build, 'windows')
# shell: bash
# # The simulation tests run from the crates/trippy-core directory and so `wintun.dll` needs to be copied there
# run: |
# cp "crates/trippy-core/tests/resources/wintun.dll" "./crates/trippy-core/"
# - name: Allow ICMPv4 and ICMPv6 in Windows defender firewall
# if: startsWith(matrix.build, 'windows')
# shell: pwsh
# run: |
# New-NetFirewallRule -DisplayName "ICMPv4 Trippy Allow" -Name ICMPv4_TRIPPY_ALLOW -Protocol ICMPv4 -Action Allow
# New-NetFirewallRule -DisplayName "ICMPv6 Trippy Allow" -Name ICMPv6_TRIPPY_ALLOW -Protocol ICMPv6 -Action Allow
# - name: Build (without root)
# run: cargo build --target ${{ matrix.target }} --features sim-tests --test sim
# - name: Run simulation test on ${{ matrix.build }}
# if: ${{ ! startsWith(matrix.build, 'windows') }}
# run: sudo -E env "PATH=$PATH" cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
# - name: Run simulation test on ${{ matrix.build }}
# if: startsWith(matrix.build, 'windows')
# run: cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
#
# fmt:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: stable
# components: rustfmt
# - uses: Swatinem/rust-cache@v2
# - run: cargo fmt --all -- --check
#
# clippy:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# build:
# - linux-stable
# - macos-stable
# - windows-stable
# include:
# - build: linux-stable
# os: ubuntu-22.04
# target: x86_64-unknown-linux-gnu
# rust: stable
# - build: macos-stable
# os: macos-13
# target: x86_64-apple-darwin
# rust: stable
# - build: windows-stable
# os: windows-2022
# target: x86_64-pc-windows-msvc
# rust: stable
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# toolchain: ${{ matrix.rust }}
# components: clippy
# - uses: Swatinem/rust-cache@v2
# - run: cargo clippy --workspace --all-features --target ${{ matrix.target }} --tests -- -Dwarnings
#
# cargo-deny:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
# - uses: EmbarkStudios/cargo-deny-action@v1
# with:
# log-level: warn
# command: check
# arguments: --all-features
#
# cargo-msrv:
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
# - uses: Swatinem/rust-cache@v2
# - name: install cargo-msrv
# run: cargo install --git https://github.com/foresterre/cargo-msrv.git cargo-msrv
# - name: check msrv for trippy
# run: cargo msrv verify --output-format json --manifest-path crates/trippy/Cargo.toml -- cargo check
# - name: check msrv for trippy-core
# run: cargo msrv verify --output-format json --manifest-path crates/trippy-core/Cargo.toml -- cargo check
# - name: check msrv for trippy-dns
# run: cargo msrv verify --output-format json --manifest-path crates/trippy-dns/Cargo.toml -- cargo check
# - name: check msrv for trippy-privilege
# run: cargo msrv verify --output-format json --manifest-path crates/trippy-privilege/Cargo.toml -- cargo check

sim-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux-stable
- macos-stable
- windows-stable
include:
- build: linux-stable
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rust: stable
- build: macos-stable
os: macos-13
target: x86_64-apple-darwin
rust: stable
- build: windows-stable
os: windows-2022
target: x86_64-pc-windows-msvc
rust: stable
test-rpm:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Copy wintun.dll to current dir
if: startsWith(matrix.build, 'windows')
- name: Build RPM package
shell: bash
run: |
cp "tests/resources/wintun.dll" "."
- name: Allow ICMPv4 and ICMPv6 in Windows defender firewall
if: startsWith(matrix.build, 'windows')
shell: pwsh
run: |
New-NetFirewallRule -DisplayName "ICMPv4 Trippy Allow" -Name ICMPv4_TRIPPY_ALLOW -Protocol ICMPv4 -Action Allow
New-NetFirewallRule -DisplayName "ICMPv6 Trippy Allow" -Name ICMPv6_TRIPPY_ALLOW -Protocol ICMPv6 -Action Allow
- name: Build (without root)
run: cargo build --target ${{ matrix.target }} --features sim-tests --test sim
- name: Run simulation test on ${{ matrix.build }}
if: ${{ ! startsWith(matrix.build, 'windows') }}
run: sudo -E env "PATH=$PATH" cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture

fmt:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check

clippy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux-stable
- macos-stable
- windows-stable
include:
- build: linux-stable
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
rust: stable
- build: macos-stable
os: macos-13
target: x86_64-apple-darwin
rust: stable
- build: windows-stable
os: windows-2022
target: x86_64-pc-windows-msvc
rust: stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --workspace --all-features --target ${{ matrix.target }} --tests -- -Dwarnings

cargo-deny:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1
with:
log-level: warn
command: check
arguments: --all-features

cargo-msrv:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: install cargo-msrv
run: cargo install --git https://github.com/foresterre/cargo-msrv.git cargo-msrv
- name: check msrv
run: cargo msrv --output-format json verify -- cargo check
cargo install cargo-generate-rpm
cargo generate-rpm -p crates/trippy --target x86_64-unknown-linux-gnu -o target/x86_64-unknown-linux-gnu/generate-rpm/trippy-0.0.0-x86_64.rpm
Loading

0 comments on commit 04275b9

Please sign in to comment.