Skip to content

Commit 60888cf

Browse files
committed
Use CMAKE_ARGS in build script and other minor improvements
1 parent 3cdbb19 commit 60888cf

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

ci/build.sh

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ resolve_path() {
3737
# Ensure the script is being executed in its containing directory
3838
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
3939

40+
# Determine repo root as the parent of the `ci` directory
41+
REPO_ROOT="$(cd .. && pwd)"
42+
4043
# Script defaults
4144
BUILD_TESTS=${BUILD_TESTS:-OFF}
4245
BUILD_EXAMPLES=${BUILD_EXAMPLES:-OFF}
@@ -51,6 +54,13 @@ HOST_COMPILER=${CXX:-g++} # $CXX if set, otherwise `g++`
5154
CUDA_ARCHS=native # detect system's GPU architectures
5255
CXX_STANDARD=17
5356

57+
# Initialize CMAKE_ARGS from environment variable if available
58+
if [ -n "${CMAKE_ARGS:-}" ]; then
59+
read -ra CMAKE_ARGS <<< "$CMAKE_ARGS"
60+
else
61+
CMAKE_ARGS=()
62+
fi
63+
5464
function usage {
5565
echo "cuCollections build script"
5666
echo "Usage: $0 [OPTIONS]"
@@ -103,6 +113,16 @@ function usage {
103113
echo " Enables verbose mode for detailed output and builds with C++17 standard."
104114
echo " Build files will be written to <repo_root>/build/local and symlinked to <repo_root>/build/latest."
105115
echo
116+
echo " Using CMAKE_ARGS Environment Variable:"
117+
echo " $ CMAKE_ARGS=\"-DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_FEATURE=ON\" $0 -t"
118+
echo " $ export CMAKE_ARGS=\"-DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_FEATURE=ON\""
119+
echo " $ $0 -t"
120+
echo " Uses CMAKE_ARGS environment variable to pass additional CMake options."
121+
echo " Can be overridden by using -- followed by specific arguments."
122+
echo
123+
echo " Pass-through to CMake:"
124+
echo " -- [CMake args...] Anything after -- is forwarded to CMake (overrides CMAKE_ARGS env var)"
125+
echo
106126
exit 1
107127
}
108128

@@ -126,6 +146,7 @@ while [ "${#args[@]}" -ne 0 ]; do
126146
--arch) CUDA_ARCHS="${args[1]}"; args=("${args[@]:2}");;
127147
--std) CXX_STANDARD="${args[1]}"; args=("${args[@]:2}");;
128148
-v | -verbose | --verbose) VERBOSE=1; args=("${args[@]:1}");;
149+
--) CMAKE_ARGS=("${args[@]:1}"); break;;
129150
-h | -help | --help) usage ;;
130151
*) echo "Unrecognized option: ${args[0]}"; usage ;;
131152
esac
@@ -156,14 +177,12 @@ if [ "$BUILD_TESTS" == "OFF" ] && [ "$BUILD_EXAMPLES" == "OFF" ] && [ "$BUILD_BE
156177
BUILD_BENCHMARKS=ON
157178
fi
158179

180+
BUILD_DIR="$BUILD_PREFIX/$BUILD_INFIX"
159181
# Trigger clean (re-)build
160182
if [ "$CLEAN_BUILD" -eq 1 ]; then
161183
rm -rf BUILD_DIR
162184
fi
163-
164-
BUILD_DIR="$BUILD_PREFIX/$BUILD_INFIX"
165185
mkdir -p $BUILD_DIR
166-
export BUILD_DIR # TODO remove
167186

168187
# The most recent build will be symlinked to cuCollections/build/latest
169188
rm -f $BUILD_PREFIX/latest
@@ -188,10 +207,10 @@ CMAKE_OPTIONS="
188207
-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \
189208
"
190209

191-
echo "========================================"
192-
echo "-- START: $(date)"
210+
echo "[INFO]=============================================="
211+
echo "-- TIMESTAMP: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
193212
echo "-- GIT_SHA: $(git rev-parse HEAD 2>/dev/null || echo 'Not a repository')"
194-
echo "-- PWD: $(pwd)"
213+
echo "-- SRC_DIR: ${REPO_ROOT}"
195214
echo "-- BUILD_DIR: ${BUILD_DIR}"
196215
echo "-- BUILD_TYPE: ${BUILD_TYPE}"
197216
echo "-- PARALLEL_LEVEL: ${PARALLEL_LEVEL}"
@@ -200,21 +219,29 @@ echo "-- BUILD_TESTS: ${BUILD_TESTS}"
200219
echo "-- BUILD_EXAMPLES: ${BUILD_EXAMPLES}"
201220
echo "-- BUILD_BENCHMARKS: ${BUILD_BENCHMARKS}"
202221

222+
if [ ${#CMAKE_ARGS[@]} -gt 0 ]; then
223+
echo "-- CMAKE_ARGS: ${CMAKE_ARGS[*]}"
224+
else
225+
echo "-- CMAKE_ARGS: (none)"
226+
fi
227+
203228
# configure
204-
cmake -S .. -B $BUILD_DIR $CMAKE_OPTIONS
205-
echo "========================================"
229+
echo "[CONFIGURE]========================================"
230+
cmake -S .. -B $BUILD_DIR $CMAKE_OPTIONS "${CMAKE_ARGS[@]}"
206231

207232
if command -v sccache >/dev/null; then
208233
source "./sccache_stats.sh" start
234+
else
235+
echo "sccache stats: N/A"
209236
fi
210237

211238
#build
239+
echo "[BUILD]============================================"
212240
cmake --build $BUILD_DIR --parallel $PARALLEL_LEVEL
213-
echo "========================================"
214241
echo "Build complete"
215242

216243
if command -v sccache >/dev/null; then
217244
source "./sccache_stats.sh" end
218245
else
219246
echo "sccache stats: N/A"
220-
fi
247+
fi

0 commit comments

Comments
 (0)