The Will Will Web

記載著 Will 在網路世界的學習心得與技術分享

管理 Redis 伺服器的利器:Redis Desktop Manager (原始碼建置筆記)

最近需要下載 Redis Desktop Manager 回來用,不過官網上的 Windows 版本已經不提供最新版直接下載,取而代之的是讓你取得原始碼自行建置,建置的成功你就可以直接用最新版,否則你就需要付費加入他們的訂閱計畫 (USD 2.99/mo),才能直接拿到最新版。其實以不到新台幣 100 的價格,我覺得完全可以。但我還是手癢自己 Build 了一遍,結果花了 6 個小時才建置成功,雖然看似完全不值得花這時間,但藉此學習 QtCMake 基本概念也還不錯。本篇文章我就紀錄一下完整的建置過程。

環境準備

  1. 作業系統:Windows 10

  2. 安裝 Visual Studio 2015 Community with Updates

    choco install visualstudio2015community -y
    
  3. 安裝 Qt 5.9

    請安裝 Qt 5.9 的最新版,我今天安裝的版本為 Qt 5.9.6,請記得安裝過程中要勾選這個版本!

    這個 Qt 軟體的安裝過程非常久,要耐心等候。

  4. 安裝 Win32 OpenSSL 1.0.X

    請務必安裝 Win32 OpenSSL v1.0.2p (20MB Installer) 這個版本,也就是 Win32 + v1.0.x 且檔案大小最大的版本。

    請安裝到預設的 C:\OpenSSL-Win32 資料夾。

  5. 安裝 CMake

  6. 取得 RedisDesktopManager 原始碼

    git clone --recursive https://github.com/uglide/RedisDesktopManager.git -b 0.9 rdm && cd ./rdm
    

建置專案

  1. 開啟命令提示字元視窗 (Command Prompt)

  2. 進入專案原始碼的 3rdparty/qredisclient/3rdparty/qsshclient/3rdparty/libssh2 資料夾

  3. 使用 CMake 工具進行建置

    這裡的重點在於 CRYPTO_BACKEND=WinCNG 參數,如果不加上這條,就無法建置成功,也無法產生必要的 libssh2.lib 檔案。

    cmake -DCRYPTO_BACKEND=WinCNG -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./output --build .
    cmake --build . --target install
    mkdir build\src\release
    copy output\lib\* build\src\release
    
  4. 開啟 Qt Creator 開發工具,並開啟 src/rdm.pro 專案檔

  5. Qt Creator 中先選擇 Desktop Qt 5.9.6 MSVC2015 32bit > Release 設定檔,然後執行建置動作。( Ctrl-B )

節錄 AppVeyor 的 CI 命令

由於 uglide/RedisDesktopManager 專案有跟 AppVeyor 整合,所以有全自動化的 CI 機制。我直接從 Log 中取得完整的 CI 指令,改天想找個時間自己嘗試一下,看能不能用 Azure DevOps Pipeline 整合出另一套完整的 CI 機制。

以下是完整的執行命令:

git clone -q --depth=5 https://github.com/uglide/RedisDesktopManager.git C:\projects\redisdesktopmanager
cd C:\projects\redisdesktopmanager
git fetch -q origin +refs/pull/4245/merge:
git checkout -qf FETCH_HEAD
git submodule update --init --recursive

set QTDIR=C:\Qt\5.9\msvc2015
set PATH=%QTDIR%\bin;%PATH%
echo %PATH%

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
powershell -command "iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/appveyor/secure-file/master/install.ps1'))"
qmake -v

set SRCDIR=%cd%
cd ./3rdparty/qredisclient/3rdparty/qsshclient/3rdparty/libssh2
cmake -G "Visual Studio 14 2015" -DCRYPTO_BACKEND=OpenSSL -DOPENSSL_ROOT_DIR=C:\OpenSSL-Win32\ -DBUILD_EXAMPLES=off -DBUILD_TESTING=off -H. -Bbuild
cmake --build build --config "Release"

cd %SRCDIR%
python ./build/utils/set_version.py %APPVEYOR_BUILD_VERSION% > ./src/version.h
python ./build/utils/set_version.py %APPVEYOR_BUILD_VERSION% > ./3rdparty/crashreporter/src/version.h
cd ./3rdparty/crashreporter
qmake CONFIG+=release DESTDIR=%SRCDIR%/bin/windows/release

powershell -Command "(Get-Content Makefile.Release).replace('DEFINES       =', 'DEFINES       = -DAPP_NAME=\\\"RedisDesktopManager\\\" -DAPP_VERSION=\\\""%APPVEYOR_BUILD_VERSION%"\\\" -DCRASH_SERVER_URL=\\\"https://oops.redisdesktop.com/crash-report\\\"') " > Makefile.Release2
nmake -f Makefile.Release2

cd %SRCDIR%/src
qmake CONFIG+=release
nmake /S /NOLOGO release


cd %SRCDIR%
copy /y .\bin\windows\release\rdm.exe .\build\windows\installer\resources\rdm.exe
copy /y .\bin\windows\release\rdm.pdb .\build\windows\installer\resources\rdm.pdb
%SRCDIR%/3rdparty/gbreakpad/src/tools/windows/binaries/dump_syms .\bin\windows\release\rdm.pdb  > .\build\windows\installer\resources\rdm.sym
cd build/windows/installer/resources/
windeployqt --no-angle --no-opengl-sw --no-compiler-runtime --no-translations --release --force --qmldir %SRCDIR%/src/qml rdm.exe

rmdir /S /Q .\platforminputcontexts
rmdir /S /Q .\qmltooling
rmdir /S /Q .\QtGraphicalEffects
del /Q  .\imageformats\qtiff.dll
del /Q  .\imageformats\qwebp.dll
cd %SRCDIR%
call "C:\\Program Files (x86)\\NSIS\\makensis.exe" /V1 /DVERSION=%APPVEYOR_BUILD_VERSION%  ./build/windows/installer/installer.nsi
appveyor-tools\secure-file -encrypt build/windows/installer/redis-desktop-manager-%APPVEYOR_BUILD_VERSION%.exe -secret %secret% || exit 0

echo 'Windows build is used only for installer compilation. Skip tests.'

相關連結

留言評論