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 6, 2024
1 parent d14fa19 commit 3772fd4
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 15 deletions.
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
14 changes: 10 additions & 4 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,18 @@ 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" \$*
PYTHONPATH="$BUILDDIR/" exec python3 "$BUILDDIR/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
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

0 comments on commit 3772fd4

Please sign in to comment.