From f6539cfa9ee58e45f2462361f8810488c92a34cb Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 8 Apr 2024 11:07:07 +0100 Subject: [PATCH] [many] BUILD_ROOT environment var to minimise pollution in the source repo --- .github/workflows/pxd.yml | 2 +- .github/workflows/py.yml | 2 +- all.py | 4 ++++ c/build.sh | 2 +- c/build_debug.sh | 2 +- c/build_lto.sh | 2 +- cpp/build.sh | 2 +- cpp/build_debug.sh | 2 +- cpp/build_lto.sh | 2 +- pxd/build.sh | 29 ++++++++++++++++------------- pxd/format.sh | 2 -- pxd/py_env.sh | 2 +- py/py_env.sh | 2 +- rs/build.sh | 4 +++- rs/build_cranelift_debug.sh | 2 +- rs/build_debug.sh | 4 +++- rs/build_lto.sh | 4 +++- rs/src/cart.rs | 2 ++ rs/src/errors.rs | 7 ++++++- 19 files changed, 48 insertions(+), 30 deletions(-) diff --git a/.github/workflows/pxd.yml b/.github/workflows/pxd.yml index a5745c47..f627efa5 100644 --- a/.github/workflows/pxd.yml +++ b/.github/workflows/pxd.yml @@ -24,7 +24,7 @@ jobs: uses: ./.github/workflows/common.yml with: workdir: pxd - format-pkgs: python3.11-venv + format-pkgs: python3.11-venv black build-pkgs: python3.11-venv libsdl2-dev cache-paths: | pxd/venv diff --git a/.github/workflows/py.yml b/.github/workflows/py.yml index 5bed79fc..5d50af2b 100644 --- a/.github/workflows/py.yml +++ b/.github/workflows/py.yml @@ -24,7 +24,7 @@ jobs: uses: ./.github/workflows/common.yml with: workdir: py - format-pkgs: python3.11-venv + format-pkgs: python3.11-venv black build-pkgs: python3.11-venv cache-paths: | py/venv diff --git a/all.py b/all.py index 1d84b44e..13da3460 100755 --- a/all.py +++ b/all.py @@ -259,6 +259,8 @@ def main() -> int: sub = "release" if match := re.match("rosettaboy-(.*)", runner): sub = match.group(1) + if lang_runner.suffix == ".nimble": + continue # rosettaboy.nimble is detected as executable?? if not os.access(lang_runner, os.X_OK): continue if args.default and sub != "release": @@ -286,6 +288,8 @@ def main() -> int: sub = "release" if match := re.match("rosettaboy-(.*)", runner): sub = match.group(1) + if lang_runner.suffix == ".nimble": + continue # rosettaboy.nimble is detected as executable?? if not os.access(lang_runner, os.X_OK): continue if args.default and sub != "release": diff --git a/c/build.sh b/c/build.sh index 68c76e7c..848d8663 100755 --- a/c/build.sh +++ b/c/build.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/release/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Release -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-c ./rosettaboy-release diff --git a/c/build_debug.sh b/c/build_debug.sh index ba77e975..4961f983 100755 --- a/c/build_debug.sh +++ b/c/build_debug.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/debug/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Debug -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-c ./rosettaboy-debug diff --git a/c/build_lto.sh b/c/build_lto.sh index a4cb3558..6114bb20 100755 --- a/c/build_lto.sh +++ b/c/build_lto.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/lto/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_LTO=On -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-c ./rosettaboy-lto diff --git a/cpp/build.sh b/cpp/build.sh index 3cdce109..7c519291 100755 --- a/cpp/build.sh +++ b/cpp/build.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/release/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Release -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-cpp ./rosettaboy-release diff --git a/cpp/build_debug.sh b/cpp/build_debug.sh index 1913f3e7..9d871712 100755 --- a/cpp/build_debug.sh +++ b/cpp/build_debug.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/debug/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Debug -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-cpp ./rosettaboy-debug diff --git a/cpp/build_lto.sh b/cpp/build_lto.sh index 848aacf4..f5bcfa3a 100755 --- a/cpp/build_lto.sh +++ b/cpp/build_lto.sh @@ -2,7 +2,7 @@ set -eu cd $(dirname $0) -BUILDDIR=build/lto/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_LTO=On -B $BUILDDIR . cmake --build $BUILDDIR -j cp $BUILDDIR/rosettaboy-cpp ./rosettaboy-lto diff --git a/pxd/build.sh b/pxd/build.sh index 417bd7f7..96874dfe 100755 --- a/pxd/build.sh +++ b/pxd/build.sh @@ -3,24 +3,27 @@ set -eu cd $(dirname $0) -source py_env.sh +BUILDDIR=${BUILD_ROOT:-$(dirname $0)/build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-build +VENVDIR=${BUILD_ROOT:-$(dirname $0)/build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-venv -BUILD_DIR=build -CORES=$(python3 -c 'import os; print(os.cpu_count() or 0)') - -if [ -t "$CORES" ]; then - echo "Failed to find core count." 1>&2 - CORES=1 -else - echo "Found $CORES cores." 1>&2 +if [ ! -d $VENVDIR ]; then + python3 -m venv $VENVDIR + $VENVDIR/bin/pip install pysdl2 pysdl2-dll mypy black Cython==3.0.0a11 fi +source $VENVDIR/bin/activate -python3 setup.py build "$@" --build-base "$BUILD_DIR" --build-purelib "$BUILD_DIR" --build-lib "$BUILD_DIR" --build-scripts "$BUILD_DIR" --build-temp build_temp --parallel $CORES +python3 setup.py build "$@" \ + --build-base "$BUILDDIR/base" \ + --build-purelib "$BUILDDIR/purelib" \ + --build-lib "$BUILDDIR/lib" \ + --build-scripts "$BUILDDIR/scripts" \ + --build-temp "$BUILDDIR/temp" \ + --parallel 4 cat >rosettaboy-release <&2; echo $?) # Use existing libraries (E.G. from system, or from Nix) if found. if [ $PYIMPORT_EXIT -eq 0 ] ; then echo "Python packages found:" diff --git a/py/py_env.sh b/py/py_env.sh index dc827900..7dc3b453 100644 --- a/py/py_env.sh +++ b/py/py_env.sh @@ -1,6 +1,6 @@ # Instead of being run, this gets `source`d by `build.sh` and `format.sh`. -BUILDDIR=$(dirname $0)/venv/$(uname)-$(uname -m) +BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-venv # Use existing libraries (E.G. from system, or from Nix) if found. if python3 -c 'import sdl2, black, mypy' 2>/dev/null ; then diff --git a/rs/build.sh b/rs/build.sh index 9151b65c..dd85520d 100755 --- a/rs/build.sh +++ b/rs/build.sh @@ -2,5 +2,7 @@ set -eu cd $(dirname $0) +BUILDDIR=${BUILD_ROOT:-target}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) +export CARGO_TARGET_DIR=$BUILDDIR cargo build --release -cp ./target/release/rosettaboy-rs ./rosettaboy-release \ No newline at end of file +cp $BUILDDIR/release/rosettaboy-rs ./rosettaboy-release \ No newline at end of file diff --git a/rs/build_cranelift_debug.sh b/rs/build_cranelift_debug.sh index ca3463d4..eea4cbce 100755 --- a/rs/build_cranelift_debug.sh +++ b/rs/build_cranelift_debug.sh @@ -5,5 +5,5 @@ cd $(dirname $0) BUILDDIR=${BUILD_ROOT:-target}/$(basename $(pwd))-cranelift-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) export CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift export CARGO_TARGET_DIR=$BUILDDIR -cargo +nightly build -Zcodegen-backend --release +cargo +nightly build -Zcodegen-backend cp $BUILDDIR/debug/rosettaboy-rs ./rosettaboy-cranelift \ No newline at end of file diff --git a/rs/build_debug.sh b/rs/build_debug.sh index 079aafad..cc551630 100755 --- a/rs/build_debug.sh +++ b/rs/build_debug.sh @@ -2,5 +2,7 @@ set -eu cd $(dirname $0) +BUILDDIR=${BUILD_ROOT:-target}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) +export CARGO_TARGET_DIR=$BUILDDIR cargo build -cp ./target/debug/rosettaboy-rs ./rosettaboy-debug \ No newline at end of file +cp $BUILDDIR/debug/rosettaboy-rs ./rosettaboy-debug \ No newline at end of file diff --git a/rs/build_lto.sh b/rs/build_lto.sh index 50d24971..826484b9 100755 --- a/rs/build_lto.sh +++ b/rs/build_lto.sh @@ -2,5 +2,7 @@ set -eu cd $(dirname $0) +BUILDDIR=${BUILD_ROOT:-target}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m) +export CARGO_TARGET_DIR=$BUILDDIR cargo build --profile release-lto -cp ./target/release-lto/rosettaboy-rs ./rosettaboy-lto \ No newline at end of file +cp $BUILDDIR/release-lto/rosettaboy-rs ./rosettaboy-lto \ No newline at end of file diff --git a/rs/src/cart.rs b/rs/src/cart.rs index b87e52fc..b655f50b 100644 --- a/rs/src/cart.rs +++ b/rs/src/cart.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use crate::errors::UserException; use anyhow::{anyhow, Result}; use num_enum::TryFromPrimitive; diff --git a/rs/src/errors.rs b/rs/src/errors.rs index 939d6db7..285b7f24 100644 --- a/rs/src/errors.rs +++ b/rs/src/errors.rs @@ -50,7 +50,12 @@ impl std::fmt::Display for UserException { UserException::UnsupportedCart(cart_type) => { write!(f, "Unsupported cart type: {:?}", cart_type) } - _ => write!(f, "Unspecified user error: {:?}", self), + UserException::LogoChecksumFailed(bad_sum) => { + write!(f, "Logo checksum failed: {:?}", bad_sum) + } + UserException::HeaderChecksumFailed(bad_sum) => { + write!(f, "Header checksum failed: {:?}", bad_sum) + } } } }