diff --git a/build.sh b/build.sh index 39f2502f..ce71b129 100755 --- a/build.sh +++ b/build.sh @@ -7,6 +7,7 @@ MODE=normal CLEAN=0 FULL=0 BUILD_GUI=1 +BUILD_INSTALLER=0 JOBS=4 MAKE_ARGS=() MAKE_SETTINGS=() @@ -15,18 +16,20 @@ STATE=.utun-build-state while [[ $# -gt 0 ]]; do case "$1" in -h|--help) - echo "Usage: ./build.sh [--clean] [--full] [--asan|--hardened] [--no-gui] [-jN] [make arguments]" + echo "Usage: ./build.sh [--clean] [--full] [--asan|--hardened] [--no-gui] [--installer] [-jN] [make arguments]" echo " --clean Rebuild objects without forcing configure" echo " --full Regenerate, configure and rebuild everything" echo " --asan AddressSanitizer; skip tests" echo " --hardened Enable compiler security hardening" echo " --no-gui Skip the separately configured ChatGUI" + echo " --installer Build Windows ChatGUI in Release and create its Inno Setup installer" echo " -jN, -j N Parallel jobs (default: 4)" echo " CC/CFLAGS/CPPFLAGS/LDFLAGS/LIBS assignments are passed to configure" exit 0 ;; --clean) CLEAN=1 ;; --full) FULL=1 ;; --no-gui) BUILD_GUI=0 ;; + --installer) BUILD_INSTALLER=1 ;; --asan|--hardened) selected_mode=${1#--} if [[ "$MODE" != normal && "$MODE" != "$selected_mode" ]]; then @@ -47,6 +50,10 @@ while [[ $# -gt 0 ]]; do shift done [[ "$JOBS" =~ ^[1-9][0-9]*$ ]] || { echo "ERROR: invalid job count: $JOBS" >&2; exit 1; } +if [[ "$BUILD_INSTALLER" = 1 ]]; then + [[ "$BUILD_GUI" = 1 && "$MODE" = normal ]] || { echo "ERROR: --installer requires GUI and normal build mode" >&2; exit 1; } + bash tools/chatgui/package_win.sh --check +fi PLATFORM=$(uname -s) MAKE_TOOL=${MAKE:-make} @@ -199,11 +206,13 @@ trap 'rm -f "$state_tmp"' EXIT printf '%s\n' "$GENERATION_INPUT" "$GENERATION_OUTPUT" "$CONFIG_REQUEST" "$CONFIG_OUTPUT" > "$state_tmp" mv -f "$state_tmp" "$STATE" -if [[ "$BUILD_GUI" = 1 && -f tools/chatgui/build/CMakeCache.txt ]]; then +if [[ "$BUILD_GUI" = 1 && ( "$BUILD_INSTALLER" = 1 || -f tools/chatgui/build/CMakeCache.txt ) ]]; then command -v cmake >/dev/null || { echo "ERROR: ChatGUI exists but cmake is not available" >&2; exit 1; } echo "INFO: building ChatGUI with its CMake configuration: jobs=$JOBS" if [[ "${MSYSTEM:-}" = UCRT64 ]]; then - (cd tools/chatgui && bash build.sh "-j$JOBS") || { echo "ERROR: ChatGUI build failed" >&2; exit 1; } + GUI_ARGS=("-j$JOBS") + [[ "$BUILD_INSTALLER" != 1 ]] || GUI_ARGS+=(--installer) + (cd tools/chatgui && bash build.sh "${GUI_ARGS[@]}") || { echo "ERROR: ChatGUI build failed" >&2; exit 1; } else cmake --build tools/chatgui/build --parallel "$JOBS" || { echo "ERROR: ChatGUI build failed" >&2; exit 1; } fi diff --git a/tools/chatgui/CMakeLists.txt b/tools/chatgui/CMakeLists.txt index 19783faa..b6b61ab5 100644 --- a/tools/chatgui/CMakeLists.txt +++ b/tools/chatgui/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.16) project(vibechat VERSION 0.1.0 LANGUAGES C CXX) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/chatgui_version.txt" "${PROJECT_VERSION}\n") set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/tools/chatgui/build.sh b/tools/chatgui/build.sh index 8b62d98e..d6d62827 100755 --- a/tools/chatgui/build.sh +++ b/tools/chatgui/build.sh @@ -15,8 +15,10 @@ SRC_DIR="$(cd "$(dirname "$0")" && pwd)" BUILD_DIR="$SRC_DIR/build" RUNTIME_PREFIX="${MSYSTEM_PREFIX:-/ucrt64}" JOBS=$(nproc 2>/dev/null || echo 4) +BUILD_INSTALLER=0 while [[ $# -gt 0 ]]; do case "$1" in + --installer) BUILD_INSTALLER=1 ;; -j) [[ $# -gt 1 ]] || { log "ERROR: -j requires a positive job count"; exit 1; } shift; JOBS=$1 ;; @@ -26,6 +28,11 @@ while [[ $# -gt 0 ]]; do shift done [[ "$JOBS" =~ ^[1-9][0-9]*$ ]] || { log "ERROR: invalid job count: $JOBS"; exit 1; } +CMAKE_ARGS=() +if [[ "$BUILD_INSTALLER" = 1 ]]; then + bash "$SRC_DIR/package_win.sh" --check 2>&1 | tee -a "$LOG_FILE" + CMAKE_ARGS+=(-DCMAKE_BUILD_TYPE=Release) +fi log "Source: $SRC_DIR" log "Build: $BUILD_DIR" @@ -55,7 +62,7 @@ if [ "${MSYSTEM:-}" = UCRT64 ]; then fi log "[1/4] Configuring CMake (generator: Ninja)..." -cmake -S "$SRC_DIR" -B "$BUILD_DIR" -G Ninja 2>&1 | tee -a "$LOG_FILE" +cmake -S "$SRC_DIR" -B "$BUILD_DIR" -G Ninja "${CMAKE_ARGS[@]}" 2>&1 | tee -a "$LOG_FILE" test ${PIPESTATUS[0]} -eq 0 || { log "CMake configure FAILED"; exit 1; } log "" @@ -239,6 +246,10 @@ EXE="$BUILD_DIR/vibechat.exe" if [ -f "$EXE" ]; then SIZE=$(du -h "$EXE" | cut -f1) log " OK: vibechat.exe ($SIZE)" + if [[ "$BUILD_INSTALLER" = 1 ]]; then + log "Creating Windows installer..." + bash "$SRC_DIR/package_win.sh" 2>&1 | tee -a "$LOG_FILE" + fi log "" log "================================" log "Build SUCCESS"