From c12b8d60efa9732d48343d80afe973f8f197cb91 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:29:33 +0000 Subject: [PATCH 01/12] Start the justfile --- justfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 justfile diff --git a/justfile b/justfile new file mode 100644 index 00000000..08e6b94f --- /dev/null +++ b/justfile @@ -0,0 +1,49 @@ +build: _build-roms + +ci: + 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-rom folder name: + #!/usr/bin/env bash + 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 From 432ea719663cf91a5607243ac5ac4a18b07e7d33 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:32:11 +0000 Subject: [PATCH 02/12] Migrate build-example-gba-files to just --- .github/scripts/build-example-gba-files.sh | 35 ---------------------- .github/scripts/run-branch-build.sh | 23 -------------- .github/workflows/build-and-test.yml | 5 ++-- justfile | 2 +- 4 files changed, 3 insertions(+), 62 deletions(-) delete mode 100755 .github/scripts/build-example-gba-files.sh delete mode 100644 .github/scripts/run-branch-build.sh 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/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/justfile b/justfile index 08e6b94f..561c5b95 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,6 @@ build: _build-roms -ci: +ci: && _build-roms just _all-crates _build just _all-crates _test-debug just _all-crates _test-release From c228910885ac5f5a6ddd0de02639f5afc9576348 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:35:02 +0000 Subject: [PATCH 03/12] Also ensure the release goes as intended --- .github/workflows/publish-agb.yml | 3 ++- justfile | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-agb.yml b/.github/workflows/publish-agb.yml index df3b5c1b..73618279 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: diff --git a/justfile b/justfile index 561c5b95..9f93aaff 100644 --- a/justfile +++ b/justfile @@ -1,12 +1,12 @@ -build: _build-roms +build: build-roms -ci: && _build-roms +ci: && build-roms just _all-crates _build just _all-crates _test-debug just _all-crates _test-release just _all-crates _clippy -_build-roms: +build-roms: just _build-rom "examples/the-purple-night" "PURPLENIGHT" just _build-rom "examples/the-hat-chooses-the-wizard" "HATWIZARD" @@ -16,6 +16,8 @@ _build-roms: _build-rom folder name: #!/usr/bin/env bash + set -euxo pipefail + GAME_FOLDER="{{folder}}" INTERNAL_NAME="{{name}}" From 553ba33c829828dd9c7725376f6b20e856193324 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:36:18 +0000 Subject: [PATCH 04/12] Move book building to just as well --- .github/workflows/publish-agb.yml | 3 +-- justfile | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-agb.yml b/.github/workflows/publish-agb.yml index 73618279..f7f30457 100644 --- a/.github/workflows/publish-agb.yml +++ b/.github/workflows/publish-agb.yml @@ -41,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/justfile b/justfile index 9f93aaff..8b292061 100644 --- a/justfile +++ b/justfile @@ -14,6 +14,9 @@ build-roms: (cd examples/target && zip examples.zip examples/*.gba) +build-book: + (cd book && mdbook build) + _build-rom folder name: #!/usr/bin/env bash set -euxo pipefail From a4dc5c0b73ecbbb9a6efad8abafd224b235606ec Mon Sep 17 00:00:00 2001 From: GBA bot Date: Thu, 24 Feb 2022 21:37:22 +0000 Subject: [PATCH 05/12] Update lockfiles in justfile too --- justfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile b/justfile index 8b292061..e9d162c0 100644 --- a/justfile +++ b/justfile @@ -17,6 +17,9 @@ build-roms: 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 From 67fbca07e4bce7f11f6129746af057f5b759c715 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:38:24 +0000 Subject: [PATCH 06/12] Use just in the action --- .github/workflows/update-lockfiles.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From b1b860edaf86fb1296f61c50c3fb6b941152c34c Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 21:54:16 +0000 Subject: [PATCH 07/12] add target for clean and test and have a cargo target dir --- justfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/justfile b/justfile index e9d162c0..c7d0f749 100644 --- a/justfile +++ b/justfile @@ -1,5 +1,13 @@ +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 + ci: && build-roms just _all-crates _build just _all-crates _test-debug @@ -55,3 +63,5 @@ _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) From 52a0f87e3c1066fc0a75eea12c9cf68c6444a3d0 Mon Sep 17 00:00:00 2001 From: GBA bot Date: Thu, 24 Feb 2022 21:56:29 +0000 Subject: [PATCH 08/12] Use cargo update rather than cargo generate-lockfile --- .github/scripts/update-lockfiles.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/update-lockfiles.sh b/.github/scripts/update-lockfiles.sh index 11ae32dc..b40e147c 100755 --- a/.github/scripts/update-lockfiles.sh +++ b/.github/scripts/update-lockfiles.sh @@ -2,7 +2,7 @@ function update_lockfiles() { for toml in **/Cargo.toml; do - (cd "$(dirname "$toml")" && cargo generate-lockfile) + (cd "$(dirname "$toml")" && cargo update) done } From fdaaa1fc7718b273ee18ef672c6970e35365c8f5 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 22:03:13 +0000 Subject: [PATCH 09/12] Use `-execdir` to update the lockfiles --- .github/scripts/update-lockfiles.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/scripts/update-lockfiles.sh b/.github/scripts/update-lockfiles.sh index b40e147c..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 update) - done + find . -name Cargo.lock -execdir cargo update \; } update_lockfiles From 28cc06159687d7a49b703f2d3c61642cf8ca9873 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 22:07:28 +0000 Subject: [PATCH 10/12] Add ability to just run an example --- justfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/justfile b/justfile index c7d0f749..55f76f3a 100644 --- a/justfile +++ b/justfile @@ -8,6 +8,10 @@ test: clean: just _all-crates _clean +run-example example: + just _build-example "{{example}}" + mgba-qt "$CARGO_TARGET_DIR/thumbv4t-none-eabi/debug/examples/{{example}}" + ci: && build-roms just _all-crates _build just _all-crates _test-debug @@ -65,3 +69,6 @@ _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}}") \ No newline at end of file From 83be1c7c229e638b1983e1b38608c45e35bcea1a Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 22:08:36 +0000 Subject: [PATCH 11/12] Add ability to run example in release mode --- justfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 55f76f3a..7fbe4ef4 100644 --- a/justfile +++ b/justfile @@ -12,6 +12,10 @@ 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}}" + ci: && build-roms just _all-crates _build just _all-crates _test-debug @@ -71,4 +75,6 @@ _clean crate: (cd "{{crate}}" && cargo clean) _build-example example: - (cd agb && cargo build "--example={{example}}") \ No newline at end of file + (cd agb && cargo build "--example={{example}}") +_build-example-release example: + (cd agb && cargo build "--example={{example}}" --release) \ No newline at end of file From 43f8e62631409ed4fd900852d763131f058952f7 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Thu, 24 Feb 2022 22:19:25 +0000 Subject: [PATCH 12/12] Add ability to run an example game --- justfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/justfile b/justfile index 7fbe4ef4..0229f453 100644 --- a/justfile +++ b/justfile @@ -16,6 +16,12 @@ 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