From 2282c13fae1e9205d52a053cbe3100b1b5df3d3d Mon Sep 17 00:00:00 2001 From: Cyano Hao Date: Thu, 2 Jan 2025 09:36:54 +0800 Subject: [PATCH] Add packaging support for WSL toolchain (#569) --- BUILD.md | 2 + BUILD_cn.md | 2 + BUILD_ru.md | 2 + RedPandaIDE/settings.cpp | 5 ++ packages/msys/build-llvm.sh | 1 + packages/msys/build-mingw.sh | 81 ++++++++++++++++++- platform/windows/installer-scripts/lang.nsh | 6 ++ .../windows/installer-scripts/redpanda.nsi | 20 +++++ platform/windows/installer-scripts/utils.nsh | 39 ++++----- 9 files changed, 134 insertions(+), 24 deletions(-) diff --git a/BUILD.md b/BUILD.md index 8881fbc47..9deb11f6d 100644 --- a/BUILD.md +++ b/BUILD.md @@ -74,6 +74,8 @@ Extra arguments for `build-mingw.sh`: - `--mingw32`: add `assets/mingw32.7z` to the package. - `--mingw64`: add `assets/mingw64.7z` to the package. - `--mingw`: alias for `--mingw64` (x64 app). +- `--gcc-linux-x86-64`: add `assets/gcc-linux-x86-64.7z` and `assets/alpine-minirootfs-x86_64.tar` to the package. +- `--gcc-linux-aarch64`: add `assets/gcc-linux-aarch64.7z` and `assets/alpine-minirootfs-aarch64.tar` to the package. - `--ucrt `: add UCRT runtime from Windows SDK to the package. e.g. `--ucrt 22621` for Windows 11 SDK 22H2. ## Windows NT 5.x Qt Library with MinGW Lite Toolchain diff --git a/BUILD_cn.md b/BUILD_cn.md index 4f45b5d35..1ca76958e 100644 --- a/BUILD_cn.md +++ b/BUILD_cn.md @@ -74,6 +74,8 @@ - `--mingw32`:把 `assets/mingw32.7z` 添加到包中。 - `--mingw64`:把 `assets/mingw64.7z` 添加到包中。 - `--mingw`:`--mingw64`(x64 程序)的别名。 +- `--gcc-linux-x86-64`:把 `assets/gcc-linux-x86-64.7z` 和 `assets/alpine-minirootfs-x86_64.tar` 添加到包中。 +- `--gcc-linux-aarch64`:把 `assets/gcc-linux-aarch64.7z` 和 `assets/alpine-minirootfs-aarch64.tar` 添加到包中。 - `--ucrt `:把 Windows SDK 附带的 UCRT 运行时添加到包中。例如 `--ucrt 22621` 表示 Windows 11 SDK 22H2。 ## 用于 Windows NT 5.x 的 Qt 库 + MinGW Lite 工具链 diff --git a/BUILD_ru.md b/BUILD_ru.md index 32726cdb7..6ef96aa01 100644 --- a/BUILD_ru.md +++ b/BUILD_ru.md @@ -77,6 +77,8 @@ Red Panda C++ должна работать с любым 64-битным наб - `--mingw32`: и `assets/mingw32.7z` для сборки пакета. - `--mingw64`: и `assets/mingw64.7z` для сборки пакета. - `--mingw`: псевдоним для `--mingw64` (x64-приложение). +- `--gcc-linux-x86-64`: add `assets/gcc-linux-x86-64.7z` and `assets/alpine-minirootfs-x86_64.tar` to the package. +- `--gcc-linux-aarch64`: add `assets/gcc-linux-aarch64.7z` and `assets/alpine-minirootfs-aarch64.tar` to the package. - `--ucrt `: добавить UCRT runtime из Windows SDK в пакет. Например, `--ucrt 22621` для Windows 11 SDK 22H2. ## Windows NT 5.x с библиотекой Qt с набором инструментов MinGW Lite diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 1b06c1de0..fb4aeee94 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -3352,6 +3352,11 @@ void Settings::CompilerSets::findSets() mSettings->dirs().appDir() + "/clang64/bin", mSettings->dirs().appDir() + "/mingw64/bin", mSettings->dirs().appDir() + "/mingw32/bin", + + // cross toolchain targeting Linux + // directory names follow dynamic linker (ld-linux-x86-64.so -> gcc-linux-x86-64) + mSettings->dirs().appDir() + "/gcc-linux-x86-64/bin", + mSettings->dirs().appDir() + "/gcc-linux-aarch64/bin", } + pathList; #endif QString folder, canonicalFolder; diff --git a/packages/msys/build-llvm.sh b/packages/msys/build-llvm.sh index 8ae656fd6..6d928e425 100644 --- a/packages/msys/build-llvm.sh +++ b/packages/msys/build-llvm.sh @@ -203,6 +203,7 @@ function package() { -DUSE_MODERN_FONT -DHAVE_LLVM -DHAVE_OPENCONSOLE + -DSTRICT_ARCH_CHECK # required by OpenConsole -DHAVE_COMPILER_HINT ) "$_NSIS" "${nsis_flags[@]}" redpanda.nsi diff --git a/packages/msys/build-mingw.sh b/packages/msys/build-mingw.sh index 8544359d4..f90828e64 100644 --- a/packages/msys/build-mingw.sh +++ b/packages/msys/build-mingw.sh @@ -16,6 +16,8 @@ function fn_print_help() { --mingw Alias for --mingw32 (x86 app) or --mingw64 (x64 app). --mingw32 Build mingw32 integrated compiler. --mingw64 Build mingw64 integrated compiler. + --gcc-linux-x86-64 Build x86_64-linux-gnu integrated compiler. + --gcc-linux-aarch64 Build aarch64-linux-gnu integrated compiler. --ucrt Include UCRT in the package. Windows SDK required. e.g. '--ucrt 22621' for Windows 11 SDK 22H2. -nd, --no-deps Skip dependency check. @@ -74,6 +76,10 @@ CHECK_DEPS=1 compilers=() COMPILER_MINGW32=0 COMPILER_MINGW64=0 +COMPILER_GCC_LINUX_X8664=0 +COMPILER_GCC_LINUX_AARCH64=0 +REQUIRED_WINDOWS_BUILD=7600 +REQUIRED_WINDOWS_NAME="Windows 7" TARGET_DIR="$(pwd)/dist" UCRT="" while [[ $# -gt 0 ]]; do @@ -114,6 +120,36 @@ while [[ $# -gt 0 ]]; do COMPILER_MINGW64=1 shift ;; + --gcc-linux-x86-64) + case "${NSIS_ARCH}" in + x64) + compilers+=("gcc-linux-x86-64") + COMPILER_GCC_LINUX_X8664=1 + REQUIRED_WINDOWS_BUILD=17763 + REQUIRED_WINDOWS_NAME="Windows 10 v1809" + shift + ;; + *) + echo "architecture mismatch, --gcc-linux-x86-64 is only supported on x64" + exit 1 + ;; + esac + ;; + --gcc-linux-aarch64) + case "${NSIS_ARCH}" in + arm64) + compilers+=("gcc-linux-aarch64") + COMPILER_GCC_LINUX_AARCH64=1 + REQUIRED_WINDOWS_BUILD=22000 + REQUIRED_WINDOWS_NAME="Windows 11" + shift + ;; + *) + echo "architecture mismatch, --gcc-linux-aarch64 is only supported on arm64" + exit 1 + ;; + esac + ;; --ucrt) case "${MSYSTEM}" in UCRT64|CLANG64) @@ -177,11 +213,18 @@ MINGW64_ARCHIVE="mingw64.7z" MINGW64_COMPILER_NAME="MinGW-w64 X86_64 GCC 11.4" MINGW64_PACKAGE_SUFFIX="MinGW64_11.4" +GCC_LINUX_X8664_ARCHIVE="gcc-linux-x86-64.7z" +ALPINE_X8664_ARCHIVE="alpine-minirootfs-x86_64.tar" + +GCC_LINUX_AARCH64_ARCHIVE="gcc-linux-aarch64.7z" +ALPINE_AARCH64_ARCHIVE="alpine-minirootfs-aarch64.tar" + if [[ ${#compilers[@]} -eq 0 ]]; then PACKAGE_BASENAME="${PACKAGE_BASENAME}.NoCompiler" else [[ ${COMPILER_MINGW32} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}.${MINGW32_PACKAGE_SUFFIX}" [[ ${COMPILER_MINGW64} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}.${MINGW64_PACKAGE_SUFFIX}" + [[ ${COMPILER_GCC_LINUX_X8664} -eq 1 || ${COMPILER_GCC_LINUX_AARCH64} -eq 1 ]] && PACKAGE_BASENAME="${PACKAGE_BASENAME}.Linux_GCC" fi function fn_print_progress() { @@ -215,6 +258,22 @@ if [[ ${COMPILER_MINGW64} -eq 1 && ! -f "${SOURCE_DIR}/assets/${MINGW64_ARCHIVE} echo "Missing MinGW archive: assets/${MINGW64_ARCHIVE} or MinGW folder: assets/${MINGW64_FOLDER}" exit 1 fi +if [[ ${COMPILER_GCC_LINUX_X8664} -eq 1 ]]; then + if [[ ! -f "${SOURCE_DIR}/assets/${GCC_LINUX_X8664_ARCHIVE}" ]]; then + echo "Missing GCC archive: assets/${GCC_LINUX_X8664_ARCHIVE}" + fi + if [[ ! -f "${SOURCE_DIR}/assets/${ALPINE_X8664_ARCHIVE}" ]]; then + echo "Missing Alpine rootfs: assets/${ALPINE_X8664_ARCHIVE}" + fi +fi +if [[ ${COMPILER_GCC_LINUX_AARCH64} -eq 1 ]]; then + if [[ ! -f "${SOURCE_DIR}/assets/${GCC_LINUX_AARCH64_ARCHIVE}" ]]; then + echo "Missing GCC archive: assets/${GCC_LINUX_AARCH64_ARCHIVE}" + fi + if [[ ! -f "${SOURCE_DIR}/assets/${ALPINE_AARCH64_ARCHIVE}" ]]; then + echo "Missing Alpine rootfs: assets/${ALPINE_AARCH64_ARCHIVE}" + fi +fi if [[ -n "${UCRT}" && ! -f "${UCRT_DIR}/ucrtbase.dll" ]]; then echo "Missing Windows SDK, UCRT cannot be included." exit 1 @@ -290,8 +349,8 @@ nsis_flags=( -DFINALNAME="${SETUP_NAME}" -DMINGW32_COMPILER_NAME="${MINGW32_COMPILER_NAME}" -DMINGW64_COMPILER_NAME="${MINGW64_COMPILER_NAME}" - -DREQUIRED_WINDOWS_BUILD=7600 - -DREQUIRED_WINDOWS_NAME="Windows 7" + -DREQUIRED_WINDOWS_BUILD="${REQUIRED_WINDOWS_BUILD}" + -DREQUIRED_WINDOWS_NAME="${REQUIRED_WINDOWS_NAME}" -DUSE_MODERN_FONT ) if [[ ${COMPILER_MINGW32} -eq 1 ]]; then @@ -308,6 +367,24 @@ if [[ ${COMPILER_MINGW64} -eq 1 ]]; then [[ -d "${SOURCE_DIR}/assets/${MINGW64_FOLDER}" ]] && cp -a --dereference "${SOURCE_DIR}/assets/${MINGW64_FOLDER}" "${PACKAGE_DIR}" fi fi +if [[ ${COMPILER_GCC_LINUX_X8664} -eq 1 ]]; then + nsis_flags+=(-DHAVE_GCC_LINUX_X8664 -DSTRICT_ARCH_CHECK) + if [[ ! -d "gcc-linux-x86_64" ]]; then + "${_7Z}" x "${SOURCE_DIR}/assets/${GCC_LINUX_X8664_ARCHIVE}" -o"${PACKAGE_DIR}" + fi + if [[ ! -d "alpine-minirootfs.tar" ]]; then + cp "${SOURCE_DIR}/assets/${ALPINE_X8664_ARCHIVE}" alpine-minirootfs.tar + fi +fi +if [[ ${COMPILER_GCC_LINUX_AARCH64} -eq 1 ]]; then + nsis_flags+=(-DHAVE_GCC_LINUX_AARCH64 -DSTRICT_ARCH_CHECK) + if [[ ! -d "gcc-linux-aarch64" ]]; then + "${_7Z}" x "${SOURCE_DIR}/assets/${GCC_LINUX_AARCH64_ARCHIVE}" -o"${PACKAGE_DIR}" + fi + if [[ ! -d "alpine-minirootfs.tar" ]]; then + cp "${SOURCE_DIR}/assets/${ALPINE_AARCH64_ARCHIVE}" alpine-minirootfs.tar + fi +fi if [[ -n "${UCRT}" ]]; then nsis_flags+=(-DHAVE_UCRT) if [[ ! -f ucrt/ucrtbase.dll ]]; then diff --git a/platform/windows/installer-scripts/lang.nsh b/platform/windows/installer-scripts/lang.nsh index cdaa14dd7..eaf426871 100644 --- a/platform/windows/installer-scripts/lang.nsh +++ b/platform/windows/installer-scripts/lang.nsh @@ -20,6 +20,8 @@ LangString SectionLangsName 1033 "Language files" LangString SectionMinGW32Name 1033 "${MINGW32_COMPILER_NAME} compiler" LangString SectionMinGW64Name 1033 "${MINGW64_COMPILER_NAME} compiler" LangString SectionLlvmName 1033 "LLVM-MinGW compiler" +LangString SectionGccLinuxX8664Name 1033 "Linux x86-64 GCC compiler" +LangString SectionGccLinuxAarch64Name 1033 "Linux aarch64 GCC compiler" LangString SectionAssocsName 1033 "Associate files to Red Panda C++" LangString SectionAssocExtNameBegin 1033 "Associate" LangString SectionAssocExtNameEnd 1033 "files to Red Panda C++" @@ -30,6 +32,7 @@ LangString SectionCompressName 1033 "Compress installation directory" LangString SectionConfigName 1033 "Remove old configuration files" LangString ErrorArchMismatch 1033 "Architecture mismatch. This package is for ${ARCH}, but the operating system is $osArch." +LangString ErrorStrictArchMismatch 1033 "Architecture mismatch. This package is STRICTLY for ${ARCH}, but the operating system is $osArch." LangString ErrorWindowsBuildRequired 1033 "Unsupported operating system. ${REQUIRED_WINDOWS_NAME} (${REQUIRED_WINDOWS_BUILD}) or later is required." LangString WarningArchMismatch 1033 "Note: installing Red Panda C++ for ${ARCH} on $osArch OS. You may want to install native build instead." @@ -65,6 +68,8 @@ LangString SectionLangsName 2052 "语言文件" LangString SectionMinGW32Name 2052 "${MINGW32_COMPILER_NAME} 编译器" LangString SectionMinGW64Name 2052 "${MINGW64_COMPILER_NAME} 编译器" LangString SectionLlvmName 2052 "LLVM-MinGW 编译器" +LangString SectionGccLinuxX8664Name 2052 "Linux x86_64 GCC 编译器" +LangString SectionGccLinuxAarch64Name 2052 "Linux aarch64 GCC 编译器" LangString SectionAssocsName 2052 "关联文件到小熊猫C++" LangString SectionAssocExtNameBegin 2052 "将" LangString SectionAssocExtNameEnd 2052 "文件关联到小熊猫C++" @@ -75,6 +80,7 @@ LangString SectionCompressName 2052 "压缩安装目录" LangString SectionConfigName 2052 "删除原有配置文件" LangString ErrorArchMismatch 2052 "架构不匹配。此软件包适用于 ${ARCH},但操作系统是 $osArch。" +LangString ErrorStrictArchMismatch 2052 "架构不匹配。此软件包**只能用于** ${ARCH},但操作系统是 $osArch。" LangString ErrorWindowsBuildRequired 2052 "不支持的操作系统。需要 ${REQUIRED_WINDOWS_NAME} (${REQUIRED_WINDOWS_BUILD}) 或更高版本。" LangString WarningArchMismatch 2052 "注意:在 $osArch 操作系统上安装小熊猫C++ ${ARCH} 版本。你可能想要安装本机版本。" diff --git a/platform/windows/installer-scripts/redpanda.nsi b/platform/windows/installer-scripts/redpanda.nsi index 6bc517e42..49206cc30 100644 --- a/platform/windows/installer-scripts/redpanda.nsi +++ b/platform/windows/installer-scripts/redpanda.nsi @@ -173,6 +173,26 @@ SectionEnd SectionEnd !endif +!ifdef HAVE_GCC_LINUX_X8664 + Section "$(SectionGccLinuxX8664Name)" SectionGccLinuxX8664 + SectionIn 1 3 + SetOutPath $INSTDIR + + File "alpine-minirootfs.tar" + File /nonfatal /r "gcc-linux-x86-64" + SectionEnd +!endif + +!ifdef HAVE_GCC_LINUX_AARCH64 + Section "$(SectionGccLinuxAarch64Name)" SectionGccLinuxAarch64 + SectionIn 1 3 + SetOutPath $INSTDIR + + File "alpine-minirootfs.tar" + File /nonfatal /r "gcc-linux-aarch64" + SectionEnd +!endif + #################################################################### # File association SectionGroup "$(SectionAssocsName)" SectionAssocs diff --git a/platform/windows/installer-scripts/utils.nsh b/platform/windows/installer-scripts/utils.nsh index 02468353f..4c8da2363 100644 --- a/platform/windows/installer-scripts/utils.nsh +++ b/platform/windows/installer-scripts/utils.nsh @@ -15,36 +15,31 @@ Var /GLOBAL sectionDepTemp !macroend !macro CheckOsArch - ; special check for OpenConsole.exe: - ; - 32-bit cannot be installed on 64-bit OS - ; - x64 can be install on arm64 OS - !ifdef HAVE_OPENCONSOLE - !if "${ARCH}" == "x86" - ${If} $osArch != "x86" + !ifdef STRICT_ARCH_CHECK + ${If} $osArch != "${ARCH}" + MessageBox MB_OK|MB_ICONSTOP "$(ErrorStrictArchMismatch)" + Abort + ${EndIf} + !else + !if "${ARCH}" == "x64" + ${If} $osArch == "x86" MessageBox MB_OK|MB_ICONSTOP "$(ErrorArchMismatch)" Abort ${EndIf} !endif - !endif - !if "${ARCH}" == "x64" - ${If} $osArch == "x86" - MessageBox MB_OK|MB_ICONSTOP "$(ErrorArchMismatch)" - Abort - ${EndIf} - !endif + !if "${ARCH}" == "arm64" + ${If} $osArch != "arm64" + MessageBox MB_OK|MB_ICONSTOP "$(ErrorArchMismatch)" + Abort + ${EndIf} + !endif - !if "${ARCH}" == "arm64" - ${If} $osArch != "arm64" - MessageBox MB_OK|MB_ICONSTOP "$(ErrorArchMismatch)" - Abort + ; warning if not matching + ${If} $osArch != "${ARCH}" + MessageBox MB_OK|MB_ICONEXCLAMATION "$(WarningArchMismatch)" ${EndIf} !endif - - ; warning if not matching - ${If} $osArch != "${ARCH}" - MessageBox MB_OK|MB_ICONEXCLAMATION "$(WarningArchMismatch)" - ${EndIf} !macroend !macro CheckOsBuild