#!/bin/bash
# Build script for the agent's solver.
#
# Invoked at submission time as `./build.sh` from the tarball root.
# Must produce an executable at `./solver`.
#
# Two language paths ship in the scaffold; pick one:
#
#   Python:  edit `./solver` in place. build.sh just chmods it.
#   C++:     edit `solver.cpp`. build.sh compiles it with clang targeting
#            Intel Ice Lake (the GCP n2-highmem-2 worker CPU).
#
# If `solver.cpp` exists, it takes precedence and the compiled binary
# overwrites `./solver`. So once you've committed to one path, delete
# the other file to keep the build deterministic.
#
# !! DO NOT change the C++ -march / -mtune flags. They must match the
# !! worker CPU exactly — `-march=icelake-server` enables AVX-512 which
# !! older Intel chips (or the broker's build host) do not support, and
# !! `-march=native` would inherit whatever the broker happens to be,
# !! producing a binary that SIGILLs on the worker.

set -euo pipefail

if [[ -f solver.cpp ]]; then
    # DO NOT EDIT these flags.
    clang++ -std=c++20 -O3 -march=icelake-server -mtune=icelake-server \
            -DNDEBUG -pthread -o solver solver.cpp
else
    chmod +x ./solver
fi
