Skip to content

Commit

Permalink
[many] BUILD_ROOT environment var to minimise pollution in the source…
Browse files Browse the repository at this point in the history
… repo
  • Loading branch information
shish committed Apr 8, 2024
1 parent 0c1a821 commit 98df6db
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion c/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion c/build_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion c/build_lto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cpp/build_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cpp/build_lto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 16 additions & 13 deletions pxd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ set -eu

cd $(dirname $0)

source py_env.sh
BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-build
VENVDIR=${BUILD_ROOT:-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 <<EOD
#!/usr/bin/env bash
set -eu
source "\$(dirname \$0)/py_env.sh"
PYTHONPATH="\$(dirname \$0)/build/" exec python3 "\$(dirname \$0)/build/main.py" \$*
source $VENVDIR/bin/activate
PYTHONPATH="$BUILDDIR/lib/" exec python3 "$BUILDDIR/scripts/main.py" \$*
EOD
chmod +x rosettaboy-release
chmod +x rosettaboy-release
2 changes: 0 additions & 2 deletions pxd/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ set -eu

cd $(dirname $0)

source py_env.sh

exec black src/*.py
2 changes: 1 addition & 1 deletion pxd/py_env.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instead of being run, this gets `source`d by `build.sh` and `format.sh`.

BUILDDIR=venv/$(uname)-$(uname -m)
BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-venv
PYIMPORT_EXIT=$(python3 -c 'import sdl2, black, mypy, cython' 1>&2; echo $?) # Use existing libraries (E.G. from system, or from Nix) if found.
if [ $PYIMPORT_EXIT -eq 0 ] ; then
echo "Python packages found:"
Expand Down
2 changes: 1 addition & 1 deletion py/py_env.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion rs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cp $BUILDDIR/release/rosettaboy-rs ./rosettaboy-release
2 changes: 1 addition & 1 deletion rs/build_cranelift_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion rs/build_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cp $BUILDDIR/debug/rosettaboy-rs ./rosettaboy-debug
4 changes: 3 additions & 1 deletion rs/build_lto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cp $BUILDDIR/release-lto/rosettaboy-rs ./rosettaboy-lto
2 changes: 2 additions & 0 deletions rs/src/cart.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use crate::errors::UserException;
use anyhow::{anyhow, Result};
use num_enum::TryFromPrimitive;
Expand Down
7 changes: 6 additions & 1 deletion rs/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}

0 comments on commit 98df6db

Please sign in to comment.