Merge pull request #173 from gwilymk/add-justfile

Add justfile
This commit is contained in:
Gwilym Kuiper 2022-02-24 22:26:38 +00:00 committed by GitHub
commit 4ee2fcf749
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 68 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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
run: just ci

View file

@ -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:

View file

@ -18,4 +18,5 @@ jobs:
- name: Check out repository
uses: actions/checkout@v2
- name: Update lock files
run: bash .github/scripts/update-lockfiles.sh
uses: extractions/setup-just@v1
run: just update-lockfiles

86
justfile Normal file
View file

@ -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)