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 1339ce3
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 18 deletions.
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
18 changes: 13 additions & 5 deletions pxd/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd $(dirname $0)

source py_env.sh

BUILD_DIR=build
BUILDDIR=${BUILD_ROOT:-build}/$(basename $(pwd))-$(echo $(basename $0) | sed 's/build_*\(.*\).sh/\1/')-$(uname)-$(uname -m)-build
CORES=$(python3 -c 'import os; print(os.cpu_count() or 0)')

if [ -t "$CORES" ]; then
Expand All @@ -15,12 +15,20 @@ else
echo "Found $CORES cores." 1>&2
fi

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 $CORES

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" \$*
cd "\$(dirname \$0)"
source py_env.sh
cd -
PYTHONPATH="$BUILDDIR/lib/" exec python3 "$BUILDDIR/scripts/main.py" \$*
EOD
chmod +x rosettaboy-release
chmod +x rosettaboy-release
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 1339ce3

Please sign in to comment.