Drop7 Research
approaches/fair-expectimax/rust-engine/build.shShell59 lines · 2.3 KB
#!/usr/bin/env bash
# Builds the Rust engine (cargo, std-only) and the C++ reference emitters used
# by the parity gates.
#
# Modifies no existing repository file.  C++ objects go to the namespaced
# build directory build/rust-engine/; cargo uses its own target/ directory
# under this approach.
#
# clang++ only, matching the repository's fast-engine build (g++ trips a
# false-positive -Werror=array-bounds in public-behavior.hpp).
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
HERE="${ROOT}/approaches/fair-expectimax/rust-engine"
OUT="${ROOT}/build/rust-engine"
CXX="${CXX_OVERRIDE:-clang++}"

mkdir -p "${OUT}"

export RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}"
export CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
export PATH="${CARGO_HOME}/bin:${PATH}"

echo "building rust crate (release)..."
# target-cpu=native enables single-instruction PEXT/PDEP on BMI2 hosts; the
# crate falls back to a bit-identical portable loop without it.
RUSTFLAGS="-C target-cpu=native" cargo build --release --manifest-path "${HERE}/Cargo.toml"

FLAGS=(-O3 -std=c++20 -pthread -Wall -Wextra -Werror -I "${ROOT}")

echo "compiling trace emitter..."
"${CXX}" "${FLAGS[@]}" -o "${OUT}/trace" "${HERE}/cpp/trace.cpp"

echo "compiling leaf emitter..."
"${CXX}" "${FLAGS[@]}" -o "${OUT}/leaf-trace" "${HERE}/cpp/leaf_trace.cpp"

echo "compiling search emitter..."
"${CXX}" "${FLAGS[@]}" -o "${OUT}/search-trace" "${HERE}/cpp/search_trace.cpp"

echo "compiling moves benchmark..."
"${CXX}" "${FLAGS[@]}" -o "${OUT}/bench-moves" "${HERE}/cpp/bench_moves.cpp"

echo "compiling leaf microbenchmark..."
"${CXX}" "${FLAGS[@]}" -o "${OUT}/leaf-micro" "${HERE}/cpp/leaf_micro.cpp"

# The search benchmark links the variant-search driver, which includes the
# renamed-entrypoint copy of the frozen reference generated by the fast-engine
# build.  Generate it here if the fast-engine build has not run.
if [ ! -f "${ROOT}/build/fast-engine/fair-only-depth4-noentry.cpp" ]; then
  echo "generating the renamed-entrypoint reference copy..."
  bash "${ROOT}/approaches/lifetime-objective/fast-engine/build.sh" gate-search
fi

echo "compiling search benchmark..."
"${CXX}" "${FLAGS[@]}" -I "${ROOT}/build/fast-engine" \
  -I "${ROOT}/approaches/fair-expectimax/reference" \
  -o "${OUT}/search-bench" "${HERE}/cpp/search_bench.cpp"

echo "built into ${OUT}"