Skip to content

Commit 3700cf9

Browse files
authored
Build script improvements (#749)
1 parent 3cdbb19 commit 3700cf9

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

ci/build.sh

Lines changed: 38 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
@@ -186,12 +205,13 @@ CMAKE_OPTIONS="
186205
-DBUILD_TESTS=${BUILD_TESTS} \
187206
-DBUILD_EXAMPLES=${BUILD_EXAMPLES} \
188207
-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \
208+
${CMAKE_ARGS[*]}
189209
"
190210

191-
echo "========================================"
192-
echo "-- START: $(date)"
193-
echo "-- GIT_SHA: $(git rev-parse HEAD 2>/dev/null || echo 'Not a repository')"
194-
echo "-- PWD: $(pwd)"
211+
echo "[INFO]=============================================="
212+
echo "-- TIMESTAMP: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
213+
echo "-- GIT_SHA: $(git rev-parse HEAD 2>/dev/null || echo 'N/A')"
214+
echo "-- SRC_DIR: ${REPO_ROOT}"
195215
echo "-- BUILD_DIR: ${BUILD_DIR}"
196216
echo "-- BUILD_TYPE: ${BUILD_TYPE}"
197217
echo "-- PARALLEL_LEVEL: ${PARALLEL_LEVEL}"
@@ -200,21 +220,29 @@ echo "-- BUILD_TESTS: ${BUILD_TESTS}"
200220
echo "-- BUILD_EXAMPLES: ${BUILD_EXAMPLES}"
201221
echo "-- BUILD_BENCHMARKS: ${BUILD_BENCHMARKS}"
202222

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

207233
if command -v sccache >/dev/null; then
208234
source "./sccache_stats.sh" start
235+
else
236+
echo "sccache stats: N/A"
209237
fi
210238

211239
#build
240+
echo "[BUILD]============================================"
212241
cmake --build $BUILD_DIR --parallel $PARALLEL_LEVEL
213-
echo "========================================"
214242
echo "Build complete"
215243

216244
if command -v sccache >/dev/null; then
217245
source "./sccache_stats.sh" end
218246
else
219247
echo "sccache stats: N/A"
220-
fi
248+
fi

0 commit comments

Comments
 (0)