From d6c739d72e6fc26f108864e188c758f6fee58956 Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Thu, 9 May 2024 21:08:28 +0800 Subject: [PATCH] update nt 5 build script (#416) --- BUILD.md | 20 ++--- BUILD_cn.md | 20 ++--- packages/msys/build-xp.sh | 177 ++++++++++++++++++++++---------------- 3 files changed, 119 insertions(+), 98 deletions(-) diff --git a/BUILD.md b/BUILD.md index 697a3986..9726affe 100644 --- a/BUILD.md +++ b/BUILD.md @@ -29,7 +29,7 @@ To setup development environment in Visual Studio Code: | ---------------------------- | --- | --- | ----- | | MSYS2 + GNU-based MinGW | ✔️ | ✔️ | ❌ | | MSYS2 + LLVM-based MinGW | ✔️ | ✔️ | ✔️ | -| [Windows XP](https://github.com/redpanda-cpp/qtbase-xp) + [MinGW UCRT](https://github.com/redpanda-cpp/mingw-lite) | ✔️ | ✔️ | ❌ | +| [Windows NT 5.x](https://github.com/redpanda-cpp/qtbase-xp) + [MinGW Lite](https://github.com/redpanda-cpp/mingw-lite) | ✔️ | ✔️ | ❌ | See also [more build instructions for Windows](./docs/detailed-build-win.md). @@ -77,20 +77,18 @@ Extra arguments for `build-mingw.sh`: - `--mingw`: alias for `--mingw32` (x86 app) or `--mingw64` (x64 app). - `--ucrt `: add UCRT runtime from Windows SDK to the package. e.g. `--ucrt 22621` for Windows 11 SDK 22H2. -## Windows XP Qt Library with MinGW UCRT Toolchain +## Windows NT 5.x Qt Library with MinGW Lite Toolchain -The script `build-xp.sh` is alike `build-mingw.sh`, but it will download a standalone MinGW UCRT toolchain to build Red Panda C++ for Windows XP, according to current MSYS2 environment: -- MINGW32/CLANG32: build x86 app; -- MINGW64/UCRT64/CLANG64: build x64 app. +The script `build-xp.sh` is alike `build-mingw.sh`, but it will download a standalone MinGW Lite toolchain to build Red Panda C++ for Windows NT 5.x. Prerequisites: 0. Windows 10 x64 or later. 1. Install MSYS2. -2. In selected environment, install required utils: +2. Install required utils: ```bash pacman -S \ - $MINGW_PACKAGE_PREFIX-{7zip,cmake} \ + mingw-w64-x86_64-{7zip,cmake} \ mingw-w64-i686-nsis \ git curl ``` @@ -100,26 +98,26 @@ Prerequisites: C: └─ Qt └─ 5.15.13 - ├─ mingw132_32-redpanda + ├─ mingw141_32-msvcrt-redpanda │ ├─ bin │ ├─ include │ ├─ lib │ └─ ... - └─ mingw132_64-redpanda + └─ mingw141_64-msvcrt-redpanda ├─ bin ├─ include ├─ lib └─ ... ``` - Or you can build from source and specify the path with `--qt` argument. -4. Install Windows 11 SDK 22H2 for UCRT runtime. To build, launch selected MSYS2 environment, run: ```bash -./packages/msys/build-xp.sh --ucrt 22621 +./packages/msys/build-xp.sh -p 32-msvcrt ``` This script accepts the same arguments as `build-mingw.sh`, plus: +- `-p|--profile `: (REQUIRED) the profile of MinGW Lite as well as Qt library. Available profiles are `64-ucrt`, `64-msvcrt`, `32-ucrt`, `32-msvcrt`, `32-win2000`. - `--qt `: set Qt directory. e.g. `--qt /d/myqt-32`. The directory structure should be like diff --git a/BUILD_cn.md b/BUILD_cn.md index e795ae85..37c896b8 100644 --- a/BUILD_cn.md +++ b/BUILD_cn.md @@ -29,7 +29,7 @@ | ------------------ | --- | --- | ----- | | MSYS2 + 基于 GNU 的 MinGW | ✔️ | ✔️ | ❌ | | MSYS2 + 基于 LLVM 的 MinGW | ✔️ | ✔️ | ✔️ | -| [Windows XP](https://github.com/redpanda-cpp/qtbase-xp) + [MinGW UCRT](https://github.com/redpanda-cpp/mingw-lite) | ✔️ | ✔️ | ❌ | +| [Windows NT 5.x](https://github.com/redpanda-cpp/qtbase-xp) + [MinGW Lite](https://github.com/redpanda-cpp/mingw-lite) | ✔️ | ✔️ | ❌ | 另请参阅[详细构建指南——Windows](./docs/detailed-build-win-cn.md)。 @@ -77,20 +77,18 @@ - `--mingw`:`--mingw32`(x86 程序)或 `--mingw64`(x64 程序)的别名。 - `--ucrt `:把 Windows SDK 附带的 UCRT 运行时添加到包中。例如 `--ucrt 22621` 表示 Windows 11 SDK 22H2。 -## 用于 Windows XP 的 Qt 库 + MinGW UCRT 工具链 +## 用于 Windows NT 5.x 的 Qt 库 + MinGW Lite 工具链 -`build-xp.sh` 脚本和 `build-mingw.sh` 类似,但是会根据当前 MSYS2 环境下载独立的 MinGW UCRT 工具链来构建用于 Windows XP 的小熊猫C++: -- MINGW32/CLANG32:构建 x86 程序; -- MINGW64/UCRT64/CLANG64:构建 x64 程序。 +`build-xp.sh` 脚本和 `build-mingw.sh` 类似,但是会下载独立的 MinGW Lite 工具链来构建用于 Windows NT 5.x 的小熊猫C++。 前置条件: 0. Windows 10 x64 或更高版本。 1. 安装 MSYS2。 -2. 在所选环境中安装所需工具: +2. 安装所需工具: ```bash pacman -S \ - $MINGW_PACKAGE_PREFIX-{7zip,cmake} \ + mingw-w64-x86_64-{7zip,cmake} \ mingw-w64-i686-nsis \ git curl ``` @@ -100,26 +98,26 @@ C: └─ Qt └─ 5.15.13 - ├─ mingw132_32-redpanda + ├─ mingw141_32-msvcrt-redpanda │ ├─ bin │ ├─ include │ ├─ lib │ └─ ... - └─ mingw132_64-redpanda + └─ mingw141_64-msvcrt-redpanda ├─ bin ├─ include ├─ lib └─ ... ``` - 也可以从源代码自行构建 Qt 并在构建时指定 `--qt` 参数。 -4. 安装 Windows 11 SDK 22H2 以获取 UCRT 运行时。 要构建此项目,启动所选的 MSYS2 环境,然后运行 ```bash -./packages/msys/build-xp.sh --ucrt 22621 +./packages/msys/build-xp.sh -p 32-msvcrt ``` 此脚本除了接受 `build-mingw.sh` 的参数外,还接受以下参数: +- `-p|--profile `:(必需)MinGW Lite 和 Qt 库的编译配置。可用的配置有 `64-ucrt`、`32-ucrt`、`64-msvcrt`、`32-msvcrt`、`32-win2000`。 - `--qt `:指定 Qt 库目录。例如 `--qt /d/myqt-32`。 目录结构应该如下: diff --git a/packages/msys/build-xp.sh b/packages/msys/build-xp.sh index 5b0c3a20..8e1b4b98 100644 --- a/packages/msys/build-xp.sh +++ b/packages/msys/build-xp.sh @@ -5,11 +5,10 @@ set -euxo pipefail function fn_print_help() { cat <] [-c|--clean] [-nd|--no-deps] [-t|--target-dir ] + packages/msys/build-xp.sh -p|--profile [-c|--clean] [-nd|--no-deps] [-t|--target-dir ] Options: -h, --help Display this information. - -m, --msystem Switch to other MSYS2 environment. - (MINGW32, MINGW64, UCRT64, CLANG32, CLANG64) + -p, --profile MinGW Lite profile. MUST be used before other options. -c, --clean Clean build and package directories. --mingw Alias for --mingw32 (x86 app) or --mingw64 (x64 app). @@ -18,7 +17,7 @@ Options: --ucrt Include UCRT in the package. Windows SDK required. e.g. '--ucrt 22621' for Windows 11 SDK 22H2. --qt Path to Qt library. - Default: /c/Qt/${QT_VERSION}/${QT_NAME}. + Default: /c/Qt/${QT_VERSION}/mingw141_\${PROFILE}-redpanda. -nd, --no-deps Skip dependency check. -t, --target-dir Set target directory for the packages. EOF @@ -27,43 +26,37 @@ EOF source version.inc [[ -n "${APP_VERSION_SUFFIX}" ]] && APP_VERSION="${APP_VERSION}${APP_VERSION_SUFFIX}" +if [[ $# -lt 2 || ($1 != "-p" && $1 != "--profile") ]]; then + echo "Missing profile argument." + exit 1 +fi + if [[ ! -v MSYSTEM ]]; then echo "This script must be run in MSYS2 shell" exit 1 fi -if [[ $# -gt 1 && ($1 == "-m" || $1 == "--msystem") ]]; then - msystem=$2 - shift 2 - case "${msystem}" in - MINGW32|MINGW64|UCRT64|CLANG32|CLANG64) - export MSYSTEM="${msystem}" - exec /bin/bash --login "$0" "$@" - ;; - *) - echo "Invalid MSYSTEM: ${msystem}" - exit 1 - ;; - esac -fi +PROFILE=$2 +shift 2 QT_VERSION="5.15.13" -QT_NAME="" -case "${MSYSTEM}" in - MINGW32|CLANG32) # there is no UCRT32 - NSIS_ARCH=x86 - PACKAGE_BASENAME="redpanda-cpp-${APP_VERSION}-winxp_x86" - QT_NAME="mingw132_32-redpanda" - ;; - MINGW64|UCRT64|CLANG64) +QT_NAME="mingw141_${PROFILE}-redpanda" +case "${PROFILE}" in + 64-ucrt|64-msvcrt) NSIS_ARCH=x64 PACKAGE_BASENAME="redpanda-cpp-${APP_VERSION}-ws2003_x64" - QT_NAME="mingw132_64-redpanda" + ;; + 32-ucrt|32-msvcrt) + NSIS_ARCH=x86 + PACKAGE_BASENAME="redpanda-cpp-${APP_VERSION}-winxp_x86" + ;; + 32-win2000) + NSIS_ARCH=x86 + PACKAGE_BASENAME="redpanda-cpp-${APP_VERSION}-win2000_x86" ;; *) - echo "This script must be run in one of the following MSYS2 shells:" - echo " - MINGW32 / CLANG32" - echo " - MINGW64 / UCRT64 / CLANG64" + echo "Invalid profile: ${PROFILE}" + echo "Available profiles: 64-ucrt, 32-ucrt, 64-msvcrt, 32-msvcrt, 32-win2000" exit 1 ;; esac @@ -73,6 +66,7 @@ CHECK_DEPS=1 compilers=() COMPILER_MINGW32=0 COMPILER_MINGW64=0 +COMPILER_MINGW32_WIN2000=0 TARGET_DIR="$(pwd)/dist" UCRT="" QT_DIR="/c/Qt/${QT_VERSION}/${QT_NAME}" @@ -87,23 +81,37 @@ while [[ $# -gt 0 ]]; do shift ;; --mingw) - case "${NSIS_ARCH}" in - x86) + case "${PROFILE}" in + 64-ucrt|64-msvcrt) + compilers+=("mingw64") + COMPILER_MINGW64=1 + shift + ;; + 32-ucrt|32-msvcrt) compilers+=("mingw32") COMPILER_MINGW32=1 shift ;; - x64) - compilers+=("mingw64") - COMPILER_MINGW64=1 + 32-win2000) + compilers+=("mingw32-win2000") + COMPILER_MINGW32_WIN2000=1 shift ;; esac ;; --mingw32) - compilers+=("mingw32") - COMPILER_MINGW32=1 - shift + case "${PROFILE}" in + 64-ucrt|32-ucrt|64-msvcrt|32-msvcrt) + compilers+=("mingw32") + COMPILER_MINGW32=1 + shift + ;; + 32-win2000) + compilers+=("mingw32-win2000") + COMPILER_MINGW32_WIN2000=1 + shift + ;; + esac ;; --mingw64) compilers+=("mingw64") @@ -111,8 +119,16 @@ while [[ $# -gt 0 ]]; do shift ;; --ucrt) - UCRT="$2" - shift 2 + case "${PROFILE}" in + 64-ucrt|32-ucrt) + UCRT="$2" + shift 2 + ;; + *) + echo "Error: Red Panda C++ is not built against UCRT." + exit 1 + ;; + esac ;; --qt) QT_DIR="$2" @@ -134,32 +150,36 @@ while [[ $# -gt 0 ]]; do done ASTYLE_VERSION_TAG="3.4.14" -BUILD_DIR="${TEMP}/redpanda-xp-${NSIS_ARCH}-build" +BUILD_DIR="${TEMP}/redpanda-xp-${PROFILE}-build" ASTYLE_BUILD_DIR="${BUILD_DIR}/astyle" -PACKAGE_DIR="${TEMP}/redpanda-xp-${NSIS_ARCH}-pkg" +PACKAGE_DIR="${TEMP}/redpanda-xp-${PROFILE}-pkg" QMAKE="${QT_DIR}/bin/qmake.exe" NSIS="/mingw32/bin/makensis" +_7Z="/mingw64/bin/7z" +CMAKE="/mingw64/bin/cmake" SOURCE_DIR="$(pwd)" ASSETS_DIR="${SOURCE_DIR}/assets" UCRT_DIR="/c/Program Files (x86)/Windows Kits/10/Redist/10.0.${UCRT}.0/ucrt/DLLs/${NSIS_ARCH}" -MINGW_LITE_RELEASE="13.2.0-r4" -HOST_MINGW32_ARCHIVE="mingw32-ucrt-${MINGW_LITE_RELEASE}.7z" -HOST_MINGW64_ARCHIVE="mingw64-ucrt-${MINGW_LITE_RELEASE}.7z" +MINGW_LITE_RELEASE="14.1.0-r1" +HOST_MINGW_ARCHIVE="mingw${PROFILE}-${MINGW_LITE_RELEASE}.7z" +HOST_MINGW_BIT="${PROFILE%%-*}" REDPANDA_MINGW_RELEASE="11.4.0-r0" MINGW32_ARCHIVE="mingw32-${REDPANDA_MINGW_RELEASE}.7z" -MINGW32_COMPILER_NAME="MinGW-w64 i686 GCC 11.4" -MINGW32_PACKAGE_SUFFIX="mingw32_11.4" +MINGW32_COMPILER_NAME="MinGW-w64 i686 GCC" +MINGW32_PACKAGE_SUFFIX="mingw32" MINGW64_ARCHIVE="mingw64-${REDPANDA_MINGW_RELEASE}.7z" -MINGW64_COMPILER_NAME="MinGW-w64 x86_64 GCC 11.4" -MINGW64_PACKAGE_SUFFIX="mingw64_11.4" +MINGW64_COMPILER_NAME="MinGW-w64 x86_64 GCC" +MINGW64_PACKAGE_SUFFIX="mingw64" + +MINGW32_WIN2000_ARCHIVE="mingw32-win2000-${MINGW_LITE_RELEASE}.7z" if [[ ${#compilers[@]} -eq 0 ]]; then PACKAGE_BASENAME="${PACKAGE_BASENAME}-none" else - [[ ${COMPILER_MINGW32} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}-${MINGW32_PACKAGE_SUFFIX}" + [[ ${COMPILER_MINGW32} -eq 1 || ${COMPILER_MINGW32_WIN2000} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}-${MINGW32_PACKAGE_SUFFIX}" [[ ${COMPILER_MINGW64} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}-${MINGW64_PACKAGE_SUFFIX}" fi @@ -176,7 +196,8 @@ if [[ ${CHECK_DEPS} -eq 1 ]]; then exit 1 fi deps=( - ${MINGW_PACKAGE_PREFIX}-7zip + mingw-w64-x86_64-7zip + mingw-w64-x86_64-cmake mingw-w64-i686-nsis curl git ) @@ -218,21 +239,15 @@ fi if [[ ${COMPILER_MINGW64} -eq 1 && ! -f "${ASSETS_DIR}/${MINGW64_ARCHIVE}" ]]; then curl -L "https://github.com/redpanda-cpp/toolchain-win32-mingw-xp/releases/download/${REDPANDA_MINGW_RELEASE}/${MINGW64_ARCHIVE}" -o "${ASSETS_DIR}/${MINGW64_ARCHIVE}" fi +if [[ ${COMPILER_MINGW32_WIN2000} -eq 1 && ! -f "${ASSETS_DIR}/${MINGW32_WIN2000_ARCHIVE}" ]]; then + curl -L "https://github.com/redpanda-cpp/mingw-lite/releases/download/${MINGW_LITE_RELEASE}/${MINGW32_WIN2000_ARCHIVE}" -o "${ASSETS_DIR}/${MINGW32_WIN2000_ARCHIVE}" +fi ## prepare host compiler -case "${NSIS_ARCH}" in - x86) - [[ -f "${ASSETS_DIR}/${HOST_MINGW32_ARCHIVE}" ]] || curl -L "https://github.com/redpanda-cpp/mingw-lite/releases/download/${MINGW_LITE_RELEASE}/${HOST_MINGW32_ARCHIVE}" -o "${ASSETS_DIR}/${HOST_MINGW32_ARCHIVE}" - [[ -x "${BUILD_DIR}/mingw32/bin/gcc.exe" ]] || 7z x "${ASSETS_DIR}/${HOST_MINGW32_ARCHIVE}" -o"${BUILD_DIR}" - export PATH="${BUILD_DIR}/mingw32/bin:${PATH}" - ;; - x64) - [[ -f "${ASSETS_DIR}/${HOST_MINGW64_ARCHIVE}" ]] || curl -L "https://github.com/redpanda-cpp/mingw-lite/releases/download/${MINGW_LITE_RELEASE}/${HOST_MINGW64_ARCHIVE}" -o "${ASSETS_DIR}/${HOST_MINGW64_ARCHIVE}" - [[ -x "${BUILD_DIR}/mingw64/bin/gcc.exe" ]] || 7z x "${ASSETS_DIR}/${HOST_MINGW64_ARCHIVE}" -o"${BUILD_DIR}" - export PATH="${BUILD_DIR}/mingw64/bin:${PATH}" - ;; -esac +[[ -f "${ASSETS_DIR}/${HOST_MINGW_ARCHIVE}" ]] || curl -L "https://github.com/redpanda-cpp/mingw-lite/releases/download/${MINGW_LITE_RELEASE}/${HOST_MINGW_ARCHIVE}" -o "${ASSETS_DIR}/${HOST_MINGW_ARCHIVE}" +[[ -x "${BUILD_DIR}/mingw${HOST_MINGW_BIT}/bin/gcc.exe" ]] || "${_7Z}" x "${ASSETS_DIR}/${HOST_MINGW_ARCHIVE}" -o"${BUILD_DIR}" +export PATH="${BUILD_DIR}/mingw${HOST_MINGW_BIT}/bin:${PATH}" ## build fn_print_progress "Building astyle..." @@ -242,7 +257,7 @@ popd pushd . cd "${ASTYLE_BUILD_DIR}" -cmake . -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" +"${CMAKE}" . -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" mingw32-make -j$(nproc) cp AStyle/AStyle.exe "${PACKAGE_DIR}/astyle.exe" popd @@ -285,27 +300,37 @@ nsis_flags=( -DMINGW32_COMPILER_NAME="${MINGW32_COMPILER_NAME}" -DMINGW64_COMPILER_NAME="${MINGW64_COMPILER_NAME}" ) -case $NSIS_ARCH in - x86) - nsis_flags+=( - -DREQUIRED_WINDOWS_BUILD=2600 - -DREQUIRED_WINDOWS_NAME="Windows XP" - ) - ;; - x64) +case "${PROFILE}" in + 64-ucrt|64-msvcrt) nsis_flags+=( -DREQUIRED_WINDOWS_BUILD=3790 -DREQUIRED_WINDOWS_NAME="Windows Server 2003" ) ;; + 32-ucrt|32-msvcrt) + nsis_flags+=( + -DREQUIRED_WINDOWS_BUILD=2600 + -DREQUIRED_WINDOWS_NAME="Windows XP" + ) + ;; + 32-win2000) + nsis_flags+=( + -DREQUIRED_WINDOWS_BUILD=2195 + -DREQUIRED_WINDOWS_NAME="Windows XP" + ) + ;; esac if [[ ${COMPILER_MINGW32} -eq 1 ]]; then nsis_flags+=(-DHAVE_MINGW32) - [[ -d "mingw32" ]] || 7z x "${SOURCE_DIR}/assets/${MINGW32_ARCHIVE}" -o"${PACKAGE_DIR}" + [[ -d "mingw32" ]] || "${_7Z}" x "${SOURCE_DIR}/assets/${MINGW32_ARCHIVE}" -o"${PACKAGE_DIR}" fi if [[ ${COMPILER_MINGW64} -eq 1 ]]; then nsis_flags+=(-DHAVE_MINGW64) - [[ -d "mingw64" ]] || 7z x "${SOURCE_DIR}/assets/${MINGW64_ARCHIVE}" -o"${PACKAGE_DIR}" + [[ -d "mingw64" ]] || "${_7Z}" x "${SOURCE_DIR}/assets/${MINGW64_ARCHIVE}" -o"${PACKAGE_DIR}" +fi +if [[ ${COMPILER_MINGW32_WIN2000} -eq 1 ]]; then + nsis_flags+=(-DHAVE_MINGW32) + [[ -d "mingw32" ]] || "${_7Z}" x "${SOURCE_DIR}/assets/${MINGW32_WIN2000_ARCHIVE}" -o"${PACKAGE_DIR}" fi if [[ -n "${UCRT}" ]]; then nsis_flags+=(-DHAVE_UCRT) @@ -317,8 +342,8 @@ fi "${NSIS}" "${nsis_flags[@]}" redpanda.nsi fn_print_progress "Making Portable Package..." -7z x "${SETUP_NAME}" -o"RedPanda-CPP" -xr'!$PLUGINSDIR' -x"!uninstall.exe" -7z a -mmt -mx9 -ms=on -mqs=on -mf=BCJ2 "${PORTABLE_NAME}" "RedPanda-CPP" +"${_7Z}" x "${SETUP_NAME}" -o"RedPanda-CPP" -xr'!$PLUGINSDIR' -x"!uninstall.exe" +"${_7Z}" a -mmt -mx9 -ms=on -mqs=on -mf=BCJ2 "${PORTABLE_NAME}" "RedPanda-CPP" rm -rf "RedPanda-CPP" mv "${SETUP_NAME}" "${TARGET_DIR}"