Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed build and packaging issues #246

Merged
merged 12 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{ps1,rtf}]
end_of_line = crlf

[*.ps1]
indent_style = tab

[{.gitignore,*.desktop}]
indent_size = 0

Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text eol=lf
.* text eol=lf

*.bmp binary
*.png binary
*.icns binary
*.ico binary
Expand Down
317 changes: 258 additions & 59 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,301 @@ name: Package

on:
workflow_dispatch:
push:
secrets:
NPCAP_OEM_URL:
4r7if3x marked this conversation as resolved.
Show resolved Hide resolved
required: true
workflow_call:
secrets:
NPCAP_OEM_URL:
required: true

jobs:

package:
runs-on: ${{ matrix.os }}
build:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu
arch: amd64
target: x86_64-unknown-linux-gnu
- os: ubuntu
arch: i386
target: i686-unknown-linux-gnu
- os: ubuntu
arch: arm64
target: aarch64-unknown-linux-gnu
- os: ubuntu
arch: armhf
target: armv7-unknown-linux-gnueabihf
- os: macos
arch: amd64
target: x86_64-apple-darwin
- os: macos
arch: arm64
target: aarch64-apple-darwin
- os: windows
arch: amd64
target: x86_64-pc-windows-msvc
- os: windows
arch: i386
target: i686-pc-windows-msvc

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
if: ${{ matrix.os == 'windows' }}
shell: powershell
run: .\resources\packaging\windows\scripts\npcap.ps1 -ARCH ${{ matrix.arch }} -OEM "${{ secrets.NPCAP_OEM_URL }}"

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt, clippy
default: true

- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install libpcap-dev libasound2-dev

- name: Install Windows dependency - npcap sdk
if: matrix.os == 'windows-latest'
- name: Add build targets
if: ${{ matrix.os == 'macos' }}
run: |
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "C:/npcap-sdk.zip"
Expand-Archive -LiteralPath C:/npcap-sdk.zip -DestinationPath C:/npcap-sdk
echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV
rustup target add \
x86_64-apple-darwin \
aarch64-apple-darwin

- name: Install Windows dependency - npcap dll
if: matrix.os == 'windows-latest'
- name: Add build targets
if: ${{ matrix.os == 'windows' }}
run: |
Invoke-WebRequest -Uri ${{secrets.NPCAP_OEM_URL}} -OutFile C:/npcap-oem.exe
C:/npcap-oem.exe /S
rustup target add `
x86_64-pc-windows-msvc `
i686-pc-windows-msvc

- name: Install Cross
if: ${{ matrix.os == 'ubuntu' }}
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Build
- name: Build binary
if: ${{ matrix.os == 'ubuntu' }}
run: cross build --release --target ${{ matrix.target }}

- name: Build binary
if: ${{ matrix.os == 'macos' || matrix.os == 'windows' }}
uses: actions-rs/cargo@v1
with:
command: build
args: --release
args: --release --target ${{ matrix.target }}

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build-${{ matrix.os }}
path: |
target/*/release/sniffnet
target/*/release/sniffnet.exe
if-no-files-found: error

deb:
runs-on: ubuntu-latest
container:
image: debian:latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: apt update -y && apt install -y curl build-essential

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true

- name: Install packaging tools
run: cargo install cargo-deb

- uses: actions/download-artifact@v3
with:
name: build-ubuntu
path: target/

- name: Package for Debian-based Linux distros
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
targets=(
x86_64-unknown-linux-gnu
i686-unknown-linux-gnu
aarch64-unknown-linux-gnu
armv7-unknown-linux-gnueabihf
)
mkdir artifacts
for target in "${targets[@]}"; do
cargo deb --no-build --no-strip --target $target
mv target/${target}/debian/*.deb artifacts/
done

- name: Upload package artifacts
uses: actions/upload-artifact@v3
with:
name: deb
path: artifacts/

rpm:
runs-on: ubuntu-latest
container:
image: fedora:latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
run: dnf update -y && dnf install -y @development-tools patchelf

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true

- name: Install packaging tools
run: cargo install cargo-generate-rpm

- uses: actions/download-artifact@v3
with:
name: build-ubuntu
path: target/

- name: Package for RPM-based Linux distros
shell: bash
run: |
cargo install cargo-deb
cargo deb
targets=(
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
)
mkdir artifacts
mv target/debian/*.deb artifacts/

# doesn't work properly on ubuntu-latest!
# - name: Package for RPM-based Linux distros
# if: matrix.os == 'ubuntu-latest'
# run: |
# cargo install cargo-generate-rpm
# cargo generate-rpm
# mv target/generate-rpm/*.rpm artifacts/

- name: Package DMG for macOS
if: matrix.os == 'macOS-latest'
for target in "${targets[@]}"; do
patchelf --replace-needed libpcap.so.0.8 libpcap.so target/${target}/release/sniffnet
cargo generate-rpm --target $target
mv target/${target}/generate-rpm/*.rpm artifacts/
done

- name: Upload package artifacts
uses: actions/upload-artifact@v3
with:
name: rpm
path: artifacts/

dmg:
runs-on: macos-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true

- name: Install packaging tools
run: |
cargo install cargo-bundle
cargo bundle --release
rm target/release/bundle/osx/sniffnet.app/Contents/Info.plist
cp resources/Info.plist target/release/bundle/osx/sniffnet.app/Contents/Info.plist
cp resources/wrapper.sh target/release/bundle/osx/sniffnet.app/Contents/MacOS/wrapper.sh
cargo install cargo-bundle toml-cli
brew install create-dmg
mkdir artifacts
create-dmg \
--volname "Sniffnet Installer" \
--background "resources/logos/bg_dmg.png" \
--window-pos 200 120 \
--window-size 900 450 \
--icon-size 100 \
--app-drop-link 620 240 \
--icon "Sniffnet.app" 300 240 \
--hide-extension "Sniffnet.app" \
"artifacts/sniffnet.dmg" \
"target/release/bundle/osx/"

- name: Package MSI for Windows
if: matrix.os == 'windows-latest'

- uses: actions/download-artifact@v3
with:
name: build-macos
path: target/

- name: Package for macOS
shell: bash
run: |
cargo install cargo-wix
cargo wix --nocapture
VERSION=$(toml get Cargo.toml package.version --raw)
sed -i'.bak' -e "s/0\.0\.0/${VERSION}/g" -e "s/fffffff/${GITHUB_SHA:0:7}/g" resources/packaging/macos/Info.plist
cargo bundle --release
targets=(
x86_64-apple-darwin
aarch64-apple-darwin
)
mkdir artifacts
mv target/wix/*.msi artifacts/
for target in "${targets[@]}"; do
cp -R target/release/bundle target/${target}/release
cp -f target/${target}/release/sniffnet \
target/${target}/release/bundle/osx/Sniffnet.app/Contents/MacOS/sniffnet
cp resources/packaging/macos/wrapper.sh \
target/${target}/release/bundle/osx/Sniffnet.app/Contents/MacOS/wrapper.sh
cp resources/packaging/macos/Info.plist \
target/${target}/release/bundle/osx/Sniffnet.app/Contents/Info.plist
create-dmg \
--volname "Sniffnet Installer" \
--background "resources/packaging/macos/graphics/dmg_bg.png" \
--window-pos 200 120 \
--window-size 900 450 \
--icon-size 100 \
--app-drop-link 620 240 \
--icon "Sniffnet.app" 300 240 \
--hide-extension "Sniffnet.app" \
"artifacts/sniffnet-${VERSION}-${target%%-*}.dmg" \
"target/${target}/release/bundle/osx/"
done

- name: Upload package artifacts
uses: actions/upload-artifact@v3
with:
name: dmg
path: artifacts/

msi:
runs-on: windows-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies
shell: powershell
run: .\resources\packaging\windows\scripts\wix.ps1

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
default: true

- name: Install packaging tools
run: cargo install cargo-wix

- uses: actions/download-artifact@v3
with:
name: build-windows
path: target/

- name: Package for Microsoft Windows
shell: powershell
run: |
$targets=@(
"x86_64-pc-windows-msvc",
"i686-pc-windows-msvc"
)
New-Item -ItemType Directory -Path artifacts
foreach ($target in $targets)
{
cargo wix --no-build --nocapture --target $target
Move-Item -Path target\wix\*.msi -Destination .\artifacts\
}

- name: Upload artifacts
- name: Upload package artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-artifacts
name: msi
path: artifacts/
Loading