2024-01-18 16:14:36 +08:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2024-03-31 08:23:30 +08:00
|
|
|
|
set -euxo pipefail
|
|
|
|
|
|
|
|
|
|
function fn_print_help() {
|
|
|
|
|
cat <<EOF
|
|
|
|
|
Usage:
|
|
|
|
|
packages/msys/build-llvm.sh [-m|--msystem <MSYSTEM>] [-c|--clean] [-nd|--no-deps] [-t|--target-dir <dir>]
|
|
|
|
|
Options:
|
|
|
|
|
-h, --help Display this information.
|
|
|
|
|
-m, --msystem <MSYSTEM> Switch to other MSYS2 environment.
|
|
|
|
|
(MINGW32, MINGW64, UCRT64, CLANG32, CLANG64, CLANGARM64)
|
|
|
|
|
MUST be used before other options.
|
|
|
|
|
-c, --clean Clean build and package directories.
|
|
|
|
|
-nd, --no-deps Skip dependency check.
|
|
|
|
|
-t, --target-dir <dir> Set target directory for the packages.
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source version.inc
|
|
|
|
|
[[ -n "${APP_VERSION_SUFFIX}" ]] && APP_VERSION="${APP_VERSION}${APP_VERSION_SUFFIX}"
|
|
|
|
|
|
|
|
|
|
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|CLANGARM64)
|
|
|
|
|
export MSYSTEM="${msystem}"
|
|
|
|
|
exec /bin/bash --login "$0" "$@"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Invalid MSYSTEM: ${msystem}"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
|
|
|
|
|
2024-01-18 16:14:36 +08:00
|
|
|
|
case $MSYSTEM in
|
|
|
|
|
MINGW32|CLANG32)
|
|
|
|
|
_NATIVE_ARCH=i686
|
|
|
|
|
_DISPLAY_ARCH=x86
|
|
|
|
|
;;
|
|
|
|
|
MINGW64|UCRT64|CLANG64)
|
|
|
|
|
_NATIVE_ARCH=x86_64
|
|
|
|
|
_DISPLAY_ARCH=x64
|
|
|
|
|
;;
|
|
|
|
|
CLANGARM64)
|
|
|
|
|
_NATIVE_ARCH=aarch64
|
|
|
|
|
_DISPLAY_ARCH=arm64
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "This script must be run from one of following MSYS2 shells:"
|
|
|
|
|
echo " - MINGW32/CLANG32"
|
|
|
|
|
echo " - MINGW64/UCRT64/CLANG64"
|
|
|
|
|
echo " - CLANGARM64"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2024-02-19 17:18:34 +08:00
|
|
|
|
REDPANDA_LLVM_VERSION="17-r0"
|
2024-03-31 08:23:30 +08:00
|
|
|
|
WINDOWS_TERMINAL_VERSION="1.19.10821.0"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
|
|
|
|
|
_QMAKE="$MINGW_PREFIX/qt5-static/bin/qmake"
|
|
|
|
|
_NSIS="/mingw32/bin/makensis"
|
|
|
|
|
|
2024-03-31 08:23:30 +08:00
|
|
|
|
_FINAL_NAME="redpanda-cpp-$APP_VERSION-$_DISPLAY_ARCH-llvm.exe"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
|
|
|
|
|
_LLVM_DIR="llvm-mingw"
|
2024-02-19 17:18:34 +08:00
|
|
|
|
_LLVM_ARCHES=("x86_64" "i686" "aarch64")
|
|
|
|
|
_LLVM_ARCHIVE="$_LLVM_DIR-$REDPANDA_LLVM_VERSION-$_NATIVE_ARCH.7z"
|
|
|
|
|
_LLVM_URL="https://github.com/redpanda-cpp/toolchain-win32-llvm/releases/download/$REDPANDA_LLVM_VERSION/$_LLVM_ARCHIVE"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
|
|
|
|
|
_WINDOWS_TERMINAL_DIR="terminal-${WINDOWS_TERMINAL_VERSION}"
|
|
|
|
|
_WINDOWS_TERMINAL_ARCHIVE="Microsoft.WindowsTerminal_${WINDOWS_TERMINAL_VERSION}_$_DISPLAY_ARCH.zip"
|
|
|
|
|
_WINDOWS_TERMINAL_URL="https://github.com/microsoft/terminal/releases/download/v${WINDOWS_TERMINAL_VERSION}/${_WINDOWS_TERMINAL_ARCHIVE}"
|
|
|
|
|
|
|
|
|
|
_SRCDIR="$PWD"
|
|
|
|
|
_ASSETSDIR="$PWD/assets"
|
2024-03-31 08:23:30 +08:00
|
|
|
|
_BUILDDIR="$TEMP/redpanda-llvm-$MSYSTEM-build"
|
|
|
|
|
_PKGDIR="$TEMP/redpanda-llvm-$MSYSTEM-pkg"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
_DISTDIR="$PWD/dist"
|
|
|
|
|
|
|
|
|
|
_CLEAN=0
|
|
|
|
|
_SKIP_DEPS_CHECK=0
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
case $1 in
|
2024-03-31 08:23:30 +08:00
|
|
|
|
-c|--clean)
|
2024-01-18 16:14:36 +08:00
|
|
|
|
_CLEAN=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2024-03-31 08:23:30 +08:00
|
|
|
|
-nd|--no-deps)
|
2024-01-18 16:14:36 +08:00
|
|
|
|
_SKIP_DEPS_CHECK=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
2024-03-31 08:23:30 +08:00
|
|
|
|
-t|--target-dir)
|
|
|
|
|
_DISTDIR="$2"
|
|
|
|
|
shift 2
|
2024-01-18 16:14:36 +08:00
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Unknown argument: $1"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
function check-deps() {
|
|
|
|
|
# MSYS2’s `pacman -Q` is 100x slower than Arch Linux. Allow skipping the check.
|
|
|
|
|
[[ $_SKIP_DEPS_CHECK -eq 1 ]] && return
|
|
|
|
|
case $MSYSTEM in
|
|
|
|
|
MINGW32|MINGW64|UCRT64)
|
|
|
|
|
local compiler=gcc
|
|
|
|
|
;;
|
|
|
|
|
CLANG32|CLANG64|CLANGARM64)
|
|
|
|
|
local compiler=clang
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
local deps=(
|
|
|
|
|
$MINGW_PACKAGE_PREFIX-{$compiler,make,qt5-static}
|
|
|
|
|
mingw-w64-i686-nsis
|
2024-03-31 08:23:30 +08:00
|
|
|
|
git
|
2024-01-18 16:14:36 +08:00
|
|
|
|
)
|
|
|
|
|
for dep in "${deps[@]}"; do
|
|
|
|
|
pacman -Q "$dep" >/dev/null 2>&1 || (
|
|
|
|
|
echo "Missing dependency: $dep"
|
|
|
|
|
exit 1
|
|
|
|
|
)
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prepare-dirs() {
|
2024-02-19 17:18:34 +08:00
|
|
|
|
if [[ $_CLEAN -eq 1 ]]; then
|
|
|
|
|
[[ -d "$_BUILDDIR" ]] && rm -rf "$_BUILDDIR"
|
|
|
|
|
[[ -d "$_PKGDIR" ]] && rm -rf "$_PKGDIR"
|
|
|
|
|
fi
|
2024-01-18 16:14:36 +08:00
|
|
|
|
mkdir -p "$_ASSETSDIR" "$_BUILDDIR" "$_PKGDIR" "$_DISTDIR"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function download-assets() {
|
|
|
|
|
[[ -f "$_ASSETSDIR/$_LLVM_ARCHIVE" ]] || curl -L -o "$_ASSETSDIR/$_LLVM_ARCHIVE" "$_LLVM_URL"
|
|
|
|
|
[[ -f "$_ASSETSDIR/$_WINDOWS_TERMINAL_ARCHIVE" ]] || curl -L -o "$_ASSETSDIR/$_WINDOWS_TERMINAL_ARCHIVE" "$_WINDOWS_TERMINAL_URL"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prepare-openconsole() {
|
|
|
|
|
local windows_terminal_dir="$_BUILDDIR/$_WINDOWS_TERMINAL_DIR"
|
|
|
|
|
if [[ ! -d "$windows_terminal_dir" ]]; then
|
|
|
|
|
bsdtar -C "$_BUILDDIR" -xf "$_ASSETSDIR/$_WINDOWS_TERMINAL_ARCHIVE"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prepare-src() {
|
|
|
|
|
cp "$_SRCDIR"/RedPandaIDE/RedPandaIDE.pro{,.bak}
|
|
|
|
|
sed -i '/CONFIG += ENABLE_LUA_ADDON/ { s/^#\s*// }' "$_SRCDIR"/RedPandaIDE/RedPandaIDE.pro
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function restore-src() {
|
|
|
|
|
mv "$_SRCDIR"/RedPandaIDE/RedPandaIDE.pro{.bak,}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function build() {
|
|
|
|
|
pushd "$_BUILDDIR"
|
|
|
|
|
"$_QMAKE" PREFIX="$_PKGDIR" "$_SRCDIR"
|
|
|
|
|
time mingw32-make WINDOWS_PREFER_OPENCONSOLE=ON -j$(nproc)
|
|
|
|
|
mingw32-make install
|
|
|
|
|
|
2024-03-31 08:23:30 +08:00
|
|
|
|
cp "$_SRCDIR"/packages/msys/compiler_hint.lua "$_PKGDIR"
|
|
|
|
|
cp "$_SRCDIR"/platform/windows/installer-scripts/* "$_PKGDIR"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
cp "$_WINDOWS_TERMINAL_DIR/OpenConsole.exe" "$_PKGDIR"
|
2024-02-19 17:18:34 +08:00
|
|
|
|
[[ -d "$_PKGDIR/llvm-mingw" ]] || bsdtar -C "$_PKGDIR" -xf "$_ASSETSDIR/$_LLVM_ARCHIVE"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
popd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function package() {
|
|
|
|
|
pushd "$_PKGDIR"
|
2024-03-31 08:23:30 +08:00
|
|
|
|
nsis_flags=(
|
|
|
|
|
-DAPP_VERSION="$APP_VERSION"
|
|
|
|
|
-DARCH="$_DISPLAY_ARCH"
|
|
|
|
|
-DFINALNAME="$_FINAL_NAME"
|
|
|
|
|
-DREQUIRED_WINDOWS_BUILD=18362
|
|
|
|
|
-DREQUIRED_WINDOWS_NAME="Windows 10 v1903"
|
|
|
|
|
-DHAVE_LLVM
|
|
|
|
|
-DHAVE_OPENCONSOLE
|
|
|
|
|
)
|
|
|
|
|
"$_NSIS" "${nsis_flags[@]}" redpanda.nsi
|
2024-01-18 16:14:36 +08:00
|
|
|
|
popd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dist() {
|
2024-03-31 08:23:30 +08:00
|
|
|
|
cp "$_PKGDIR/$_FINAL_NAME" "$_DISTDIR"
|
2024-01-18 16:14:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check-deps
|
|
|
|
|
prepare-dirs
|
|
|
|
|
download-assets
|
|
|
|
|
prepare-openconsole
|
|
|
|
|
prepare-src
|
|
|
|
|
trap restore-src EXIT INT TERM
|
|
|
|
|
build
|
|
|
|
|
package
|
|
|
|
|
dist
|