Skip to content

Commit

Permalink
build: replace cargo-make with Just
Browse files Browse the repository at this point in the history
cargo-make was originally chosen so that bash would not be a requirement
for building, but now that msys2 is required on windows, bash will
always be present.

Just is a better choice here since rust is not the only language used.

The install scripts are also now independent bash scripts that are not
dependent on Just, so they can be used when building the flatpak.
  • Loading branch information
Oppzippy committed May 14, 2024
1 parent 05fc9ce commit ed986d8
Show file tree
Hide file tree
Showing 31 changed files with 319 additions and 481 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: |
apt-get update
apt-get upgrade -y
apt-get install -y git curl unzip clang gpg
apt-get install -y git curl unzip clang gpg just
- uses: actions/checkout@v4
with:
Expand All @@ -25,8 +25,6 @@ jobs:
- name: Install dependencies
run: |
apt-get install -y libdbus-1-dev pkg-config libgtk-4-dev libadwaita-1-dev gettext libfuse2
- name: Install cargo-make
run: cargo install cargo-make
- name: Install appimage-builder
run: |
curl --location -o appimage-builder https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
Expand Down Expand Up @@ -92,19 +90,10 @@ jobs:
rust:p
pkg-config:p
# cargo-make does not use the current shell to run "cargo build". It spawns a new shell, and on Windows, that's cmd.
# Rather than trying to get cargo-make to conditionally use the msys2 shell, we can just get anything that would
# interfere out of the path.
# We want to use the msys2 cargo and linker, so that means cargo and visual studio need to be removed from the path.
- name: Remove Visual Studio and cargo from path
run: |
Move-Item -Path "C:\Program Files\Microsoft Visual Studio" -Destination "C:\Program Files\_Microsoft Visual Studio"
Move-Item -Path "~\.cargo" -Destination "~\._cargo"
- name: Install cargo-make
- name: Install just
shell: msys2 {0}
run: |
cargo install cargo-make
cargo install just
- name: Build gui
shell: msys2 {0}
run: |
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,24 @@ on:
- push

jobs:
rustfmt:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install just
# todo switch to apt once ubuntu-24.04 is available
# sudo apt-get install -y just
run: snap install --edge --classic just
- uses: actions/setup-java@v4
with:
distribution: temurin # See 'Supported distributions' for available options
java-version: 17
- name: Install rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Install cargo-make
uses: davidB/rust-cargo-make@v1
- name: Check formatting
run: cargo make fmt-check
run: just format-check

ktlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: temurin # See 'Supported distributions' for available options
java-version: 17
- name: Run ktlint
run: |
cd android
./gradlew ktlintCheck
16 changes: 7 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install basic requirements
run: |
apt-get update
apt-get install -y git curl unzip clang
apt-get install -y git curl unzip clang just
- uses: actions/checkout@v4
with:
Expand All @@ -27,14 +27,12 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-make
uses: davidB/rust-cargo-make@v1
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2
- name: Run rust tests
run: xvfb-run --auto-servernum cargo make test-cov
run: xvfb-run --auto-servernum just test-cov
- name: Generate HTML test coverage report
run: cargo make test-cov-report-html
run: just test-cov-report-html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
Expand All @@ -48,14 +46,14 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install just
run: choco install just
- name: Install rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-make
uses: davidB/rust-cargo-make@v1
- name: Run rust tests
run: cargo make integration-test
- name: Run lib tests
run: just lib/ test

android_test:
runs-on: ubuntu-latest
Expand Down
100 changes: 0 additions & 100 deletions Makefile.toml

This file was deleted.

8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,4 @@ See [GitHub Releases](https://github.com/Oppzippy/OpenSCQ30/releases). All files

## Running Tests

### Rust

`cargo make test` will run all unit and integration tests for the Rust code.

### Web

`npm run test` will run unit tests, and `npm run e2etest` will run end to end tests.
`just test` will run all unit and integration tests. To run tests for a specific package, use `just gui/ test` for example.
7 changes: 0 additions & 7 deletions android/Makefile.toml

This file was deleted.

30 changes: 30 additions & 0 deletions android/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
build profile='dev':
#!/usr/bin/env bash
set -euo pipefail
case "{{profile}}" in
dev)
./gradlew assembleBluetoothDebug
;;
release)
./gradlew assembleBluetoothRelease
;;
*)
echo Invalid profile
exit 1
esac

test:
cargo test
./gradlew testBluetoothDebugUnitTest

test-cov:
cargo llvm-cov --no-report

format:
cargo fmt
./gradlew ktlintFormat

format-check:
cargo fmt --check
./gradlew ktlintCheck
66 changes: 0 additions & 66 deletions cli/Makefile.toml

This file was deleted.

24 changes: 24 additions & 0 deletions cli/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
build profile='dev':
cargo build --profile {{profile}}

test:
cargo test --bins
cargo test --no-default-features --features demo --test '*'

unit-test-cov:
cargo llvm-cov --no-report

integration-test-cov:
cargo llvm-cov --no-report --no-default-features --features demo --test '*'

install prefix:
./scripts/install.sh "{{prefix}}"

uninstall prefix:
./scripts/uninstall.sh "{{prefix}}"

format:
cargo fmt

format-check:
cargo fmt --check
22 changes: 22 additions & 0 deletions cli/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail

script_path="$(readlink -f -- "$0")"
script_dir="$(dirname -- "$script_path")"
cd "$script_dir/.."

install_prefix="$1"
case "$OSTYPE" in
msys | cygwin) bin_ext=".exe" ;;
*) bin_ext="" ;;
esac

echo Installing binary
install -Dm755 "../target/release/openscq30_cli$bin_ext" -t "$install_prefix/bin/"

if [[ -d "$install_prefix/share/bash-completions/completions" ]]; then
echo Installing bash completions
"../target/release/openscq30_cli$bin_ext" completions bash > "$install_prefix/share/bash-completions/completions/openscq30_cli"
else
echo Skipping bash completions
fi
Loading

0 comments on commit ed986d8

Please sign in to comment.