diff --git a/.github/scripts/build-example-gba-files.sh b/.github/scripts/build-example-gba-files.sh deleted file mode 100755 index beee0401..00000000 --- a/.github/scripts/build-example-gba-files.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -e # Fail if any command fails -set -x # print every command before it runs - -# Requires gbafix and arm-none-eabi-objcopy to already be installed - -function build_rom() { - local GAME_FOLDER="$1" - local INTERNAL_NAME="$2" - - local GAME_NAME - GAME_NAME="$(basename "$GAME_FOLDER")" - - local TARGET_FOLDER="${CARGO_TARGET_DIR:-$GAME_FOLDER/target}" - local GBA_FILE="$TARGET_FOLDER/$GAME_NAME.gba" - - (cd "$GAME_FOLDER" && cargo build --release --verbose --target thumbv4t-none-eabi) - - mkdir -p examples/target/examples - - arm-none-eabi-objcopy -O binary "$TARGET_FOLDER/thumbv4t-none-eabi/release/$GAME_NAME" "$GBA_FILE" - gbafix -p "-t${INTERNAL_NAME:0:12}" "-c${INTERNAL_NAME:0:4}" -mGC "$GBA_FILE" - - cp -v "$GBA_FILE" "examples/target/examples/$GAME_NAME.gba" -} - -mkdir -p examples/target - -build_rom "examples/the-purple-night" "PURPLENIGHT" -build_rom "examples/the-hat-chooses-the-wizard" "HATWIZARD" - -build_rom "book/games/pong" "PONG" - -(cd examples/target && zip examples.zip examples/*.gba) \ No newline at end of file diff --git a/.github/scripts/run-branch-build.sh b/.github/scripts/run-branch-build.sh deleted file mode 100644 index 45a5a8c4..00000000 --- a/.github/scripts/run-branch-build.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -e # Fail if any command fails - -CARGO_PROJECT_FILES=( agb-*/Cargo.toml agb/Cargo.toml examples/*/Cargo.toml book/games/*/Cargo.toml ) - -for CARGO_PROJECT_FILE in "${CARGO_PROJECT_FILES[@]}"; do - PROJECT_DIR=$(dirname "$CARGO_PROJECT_FILE") - - echo "Checking project $PROJECT_DIR" - (cd "$PROJECT_DIR" && cargo build) - - if echo "$PROJECT_DIR" | grep -qE '^agb'; then - echo "Running clippy on $PROJECT_DIR" - (cd "$PROJECT_DIR" && cargo clippy) - - echo "Testing $PROJECT_DIR in debug mode" - (cd "$PROJECT_DIR" && cargo test) - - echo "Testing $PROJECT_DIR in release mode" - (cd "$PROJECT_DIR" && cargo test --release) - fi -done diff --git a/.github/scripts/update-lockfiles.sh b/.github/scripts/update-lockfiles.sh index 11ae32dc..e79e76a9 100755 --- a/.github/scripts/update-lockfiles.sh +++ b/.github/scripts/update-lockfiles.sh @@ -1,9 +1,7 @@ #!/usr/bin/env bash function update_lockfiles() { - for toml in **/Cargo.toml; do - (cd "$(dirname "$toml")" && cargo generate-lockfile) - done + find . -name Cargo.lock -execdir cargo update \; } update_lockfiles diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 8cb69deb..8c385284 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -32,7 +32,6 @@ jobs: run: echo "CARGO_TARGET_DIR=$HOME/target" >> $GITHUB_ENV - name: Install gbafix run: cargo install gbafix + - uses: extractions/setup-just@v1 - name: Build and test all crates - run: bash .github/scripts/run-branch-build.sh - - name: Build example projects - run: bash .github/scripts/build-example-gba-files.sh \ No newline at end of file + run: just ci \ No newline at end of file diff --git a/.github/workflows/publish-agb.yml b/.github/workflows/publish-agb.yml index df3b5c1b..f7f30457 100644 --- a/.github/workflows/publish-agb.yml +++ b/.github/workflows/publish-agb.yml @@ -26,8 +26,9 @@ jobs: API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} run: bash .github/scripts/update-template-repo.sh + - uses: extractions/setup-just@v1 - name: Build the examples - run: bash .github/scripts/build-example-gba-files.sh + run: just build-roms - name: Upload examples to the release uses: svenstaro/upload-release-action@v2 with: @@ -40,8 +41,7 @@ jobs: - name: Install mdbook run: cargo install mdbook - name: Build the book - run: mdbook build - working-directory: book + run: just build-book - name: Deploy the book uses: JamesIves/github-pages-deploy-action@v4.2.5 with: diff --git a/.github/workflows/update-lockfiles.yml b/.github/workflows/update-lockfiles.yml index c77b5d42..aca05925 100644 --- a/.github/workflows/update-lockfiles.yml +++ b/.github/workflows/update-lockfiles.yml @@ -18,4 +18,5 @@ jobs: - name: Check out repository uses: actions/checkout@v2 - name: Update lock files - run: bash .github/scripts/update-lockfiles.sh \ No newline at end of file + uses: extractions/setup-just@v1 + run: just update-lockfiles \ No newline at end of file diff --git a/justfile b/justfile new file mode 100644 index 00000000..0229f453 --- /dev/null +++ b/justfile @@ -0,0 +1,86 @@ +export CARGO_TARGET_DIR := env_var_or_default('CARGO_TARGET_DIR', justfile_directory() + "/target") + +build: build-roms + +test: + just _all-crates _test-debug + +clean: + just _all-crates _clean + +run-example example: + just _build-example "{{example}}" + mgba-qt "$CARGO_TARGET_DIR/thumbv4t-none-eabi/debug/examples/{{example}}" + +run-example-release example: + just _build-example-release "{{example}}" + mgba-qt "$CARGO_TARGET_DIR/thumbv4t-none-eabi/release/examples/{{example}}" + +run-game game: + (cd "examples/{{game}}" && cargo run --release) + +run-game-debug game: + (cd "examples/{{game}}" && cargo run) + +ci: && build-roms + just _all-crates _build + just _all-crates _test-debug + just _all-crates _test-release + just _all-crates _clippy + +build-roms: + just _build-rom "examples/the-purple-night" "PURPLENIGHT" + just _build-rom "examples/the-hat-chooses-the-wizard" "HATWIZARD" + + just _build-rom "book/games/pong" "PONG" + + (cd examples/target && zip examples.zip examples/*.gba) + +build-book: + (cd book && mdbook build) + +update-lockfiles: + bash .github/scripts/update-lockfiles.sh + +_build-rom folder name: + #!/usr/bin/env bash + set -euxo pipefail + + GAME_FOLDER="{{folder}}" + INTERNAL_NAME="{{name}}" + + GAME_NAME="$(basename "$GAME_FOLDER")" + + TARGET_FOLDER="${CARGO_TARGET_DIR:-$GAME_FOLDER/target}" + GBA_FILE="$TARGET_FOLDER/$GAME_NAME.gba" + + (cd "$GAME_FOLDER" && cargo build --release --target thumbv4t-none-eabi) + + mkdir -p examples/target/examples + + arm-none-eabi-objcopy -O binary "$TARGET_FOLDER/thumbv4t-none-eabi/release/$GAME_NAME" "$GBA_FILE" + gbafix -p "-t${INTERNAL_NAME:0:12}" "-c${INTERNAL_NAME:0:4}" -mGC "$GBA_FILE" + + cp -v "$GBA_FILE" "examples/target/examples/$GAME_NAME.gba" + +_all-crates target: + for CARGO_PROJECT_FILE in agb-*/Cargo.toml agb/Cargo.toml examples/*/Cargo.toml book/games/*/Cargo.toml; do \ + PROJECT_DIR=$(dirname "$CARGO_PROJECT_FILE"); \ + just "{{target}}" "$PROJECT_DIR"; \ + done + +_build crate: + (cd "{{crate}}" && cargo build) +_test-release crate: + if echo "{{crate}}" | grep -qE '^agb'; then (cd "{{crate}}" && cargo test --release); fi +_test-debug crate: + if echo "{{crate}}" | grep -qE '^agb'; then (cd "{{crate}}" && cargo test); fi +_clippy crate: + if echo "{{crate}}" | grep -qE '^agb'; then (cd "{{crate}}" && cargo clippy); fi +_clean crate: + (cd "{{crate}}" && cargo clean) + +_build-example example: + (cd agb && cargo build "--example={{example}}") +_build-example-release example: + (cd agb && cargo build "--example={{example}}" --release) \ No newline at end of file