forked from mirrors/kingfisher
Merge pull request #61 from mongodb/development
Fixed broken windows build script
This commit is contained in:
commit
7996413ecf
1 changed files with 46 additions and 59 deletions
105
buildwin.bat
105
buildwin.bat
|
|
@ -1,27 +1,23 @@
|
|||
@echo off
|
||||
REM ---------------------------------------------------------------------------
|
||||
REM Build a Windows-x64 release of Kingfisher and package it with checksums.
|
||||
REM
|
||||
REM • Installs Hyperscan statically via vcpkg so vectorscan-rs-sys can link
|
||||
REM against hs.lib.
|
||||
REM • Installs Rust (via Chocolatey) if missing.
|
||||
REM • Call with -force to clone & bootstrap vcpkg if it isn’t found.
|
||||
REM Build a Windows‑x64 release binary and package it with checksums.
|
||||
REM ‑ Clones vcpkg (if requested) and pins it to commit 4887ad6d14.
|
||||
REM ---------------------------------------------------------------------------
|
||||
|
||||
setlocal EnableDelayedExpansion
|
||||
setlocal
|
||||
|
||||
REM ── Project name ────────────────────────────────────────────────────────────
|
||||
set "PROJECT_NAME=kingfisher"
|
||||
set "VCPKG_COMMIT=4887ad6d14" REM ← known‑good vcpkg snapshot
|
||||
|
||||
REM ── Require Windows ─────────────────────────────────────────────────────────
|
||||
REM ── Require Windows ────────────────────────────────────────────────────────
|
||||
if NOT "%OS%"=="Windows_NT" (
|
||||
echo This script must be run on Windows.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM ── Locate MSVC toolchain ───────────────────────────────────────────────────
|
||||
REM ── Locate MSVC toolchain ──────────────────────────────────────────────────
|
||||
if "%VCINSTALLDIR%"=="" (
|
||||
echo VCINSTALLDIR not set — attempting auto-detection...
|
||||
echo VCINSTALLDIR not set - attempting auto-detection…
|
||||
for %%P in (
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC"
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\Professional\VC"
|
||||
|
|
@ -29,11 +25,10 @@ if "%VCINSTALLDIR%"=="" (
|
|||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC"
|
||||
) do if exist "%%~P\Auxiliary\Build\vcvars64.bat" (
|
||||
set "VCINSTALLDIR=%%~P"
|
||||
echo Found Visual C++ Build Tools at: %%~P
|
||||
echo Found Visual C++ Build Tools at: %%~P
|
||||
goto :vc_found
|
||||
)
|
||||
echo ERROR: Could not find a suitable Visual Studio installation.
|
||||
echo Install “Desktop development with C++” or set VCINSTALLDIR.
|
||||
exit /b 1
|
||||
)
|
||||
:vc_found
|
||||
|
|
@ -45,89 +40,81 @@ call "%VCINSTALLDIR%\Auxiliary\Build\vcvars64.bat" || (
|
|||
exit /b 1
|
||||
)
|
||||
|
||||
REM ── Locate or bootstrap vcpkg ───────────────────────────────────────────────
|
||||
REM ── Locate or bootstrap vcpkg, then pin to commit ──────────────────────────
|
||||
where vcpkg.exe >nul 2>&1
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
REM ----- vcpkg.exe not on PATH ------------------------------------------
|
||||
if exist "%HOMEDRIVE%\vcpkg\vcpkg.exe" (
|
||||
set "VCPKG_EXE=%HOMEDRIVE%\vcpkg\vcpkg.exe"
|
||||
REM vcpkg folder exists → pin it
|
||||
echo Found existing vcpkg tree, pinning to %VCPKG_COMMIT%…
|
||||
git -C "%HOMEDRIVE%\vcpkg" fetch --depth=1 origin %VCPKG_COMMIT%
|
||||
git -C "%HOMEDRIVE%\vcpkg" checkout %VCPKG_COMMIT% ^
|
||||
|| (echo ERROR: checkout failed.&exit /b 1)
|
||||
) else if "%~1"=="-force" (
|
||||
echo Cloning and bootstrapping vcpkg…
|
||||
REM Fresh clone
|
||||
echo Cloning and bootstrapping vcpkg at commit %VCPKG_COMMIT%…
|
||||
if exist "%HOMEDRIVE%\vcpkg" rmdir /s /q "%HOMEDRIVE%\vcpkg"
|
||||
git clone https://github.com/microsoft/vcpkg.git "%HOMEDRIVE%\vcpkg"
|
||||
git clone https://github.com/microsoft/vcpkg.git "%HOMEDRIVE%\vcpkg" ^
|
||||
|| (echo ERROR: git clone failed.&exit /b 1)
|
||||
pushd "%HOMEDRIVE%\vcpkg"
|
||||
call .\bootstrap-vcpkg.bat || (echo ERROR: vcpkg bootstrap failed.&exit /b 1)
|
||||
set "VCPKG_EXE=%CD%\vcpkg.exe"
|
||||
git checkout %VCPKG_COMMIT% || (echo ERROR: checkout failed.&exit /b 1)
|
||||
call .\bootstrap-vcpkg.bat || (echo ERROR: bootstrap failed.&exit /b 1)
|
||||
popd
|
||||
) else (
|
||||
echo ERROR: vcpkg not found. Install it or rerun with -force.
|
||||
exit /b 1
|
||||
)
|
||||
) else (
|
||||
REM ----- vcpkg.exe already on PATH ---------------------------------------
|
||||
for /f "tokens=*" %%i in ('where vcpkg.exe') do set "VCPKG_EXE=%%i"
|
||||
echo Found vcpkg at: %VCPKG_EXE%
|
||||
REM Ensure the tree is on the expected commit
|
||||
git -C "%HOMEDRIVE%\vcpkg" fetch --depth=1 origin %VCPKG_COMMIT%
|
||||
git -C "%HOMEDRIVE%\vcpkg" checkout %VCPKG_COMMIT% ^
|
||||
|| (echo ERROR: checkout failed.&exit /b 1)
|
||||
)
|
||||
if not defined VCPKG_EXE set "VCPKG_EXE=%HOMEDRIVE%\vcpkg\vcpkg.exe"
|
||||
|
||||
echo Found vcpkg at: !VCPKG_EXE!
|
||||
|
||||
REM Derive vcpkg root
|
||||
for %%i in ("!VCPKG_EXE!") do set "VCPKG_ROOT=%%~dpi"
|
||||
if "!VCPKG_ROOT:~-1!"=="\" set "VCPKG_ROOT=!VCPKG_ROOT:~0,-1!"
|
||||
|
||||
REM ── Ensure LOCALAPPDATA has a drive letter (GitHub Actions quirk) ───────────
|
||||
REM ── LOCALAPPDATA fix for CI ------------------------------------------------
|
||||
if /I not "%LOCALAPPDATA:~1,1%"==":" (
|
||||
echo LOCALAPPDATA lacks drive letter; pointing it at APPDATA.
|
||||
set "LOCALAPPDATA=%APPDATA%"
|
||||
)
|
||||
|
||||
REM ── Install Hyperscan statically ────────────────────────────────────────────
|
||||
set "VCPKG_TRIPLET=x64-windows-static"
|
||||
echo Installing Hyperscan (!VCPKG_TRIPLET!) via vcpkg…
|
||||
|
||||
pushd "!VCPKG_ROOT!"
|
||||
"!VCPKG_EXE!" install hyperscan:!VCPKG_TRIPLET! --clean-after-build || (
|
||||
echo ERROR: vcpkg install failed.
|
||||
popd
|
||||
exit /b 1
|
||||
)
|
||||
popd
|
||||
|
||||
REM ── Install Hyperscan (unchanged) -----------------------------------------
|
||||
echo Installing hyperscan via vcpkg...
|
||||
"%VCPKG_EXE%" install hyperscan:x64-windows
|
||||
set "LIBHS_NO_PKG_CONFIG=1"
|
||||
set "HYPERSCAN_ROOT=%HOMEDRIVE%\vcpkg\installed\x64-windows"
|
||||
set "LIB=%HYPERSCAN_ROOT%\lib;%LIB%"
|
||||
set "INCLUDE=%HYPERSCAN_ROOT%\include;%INCLUDE%"
|
||||
|
||||
REM Path hints for vectorscan-rs-sys
|
||||
set "HYPERSCAN_ROOT=!VCPKG_ROOT!\installed\!VCPKG_TRIPLET!"
|
||||
set "LIB=!HYPERSCAN_ROOT!\lib;%LIB%"
|
||||
set "INCLUDE=!HYPERSCAN_ROOT!\include;%INCLUDE%"
|
||||
|
||||
REM Fallback: rename vectorscan.lib -> hs.lib if vcpkg changed the name
|
||||
if not exist "!HYPERSCAN_ROOT!\lib\hs.lib" if exist "!HYPERSCAN_ROOT!\lib\vectorscan.lib" (
|
||||
copy "!HYPERSCAN_ROOT!\lib\vectorscan.lib" "!HYPERSCAN_ROOT!\lib\hs.lib" >nul
|
||||
)
|
||||
|
||||
REM ── Install Rust toolchain if absent ────────────────────────────────────────
|
||||
REM ── Check for Rust toolchain (unchanged) -----------------------------------
|
||||
where rustc.exe >nul 2>&1
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo Installing Rust via Chocolatey…
|
||||
choco install rust-ms -y || exit /b 1
|
||||
choco install cmake -y --installargs "ADD_CMAKE_TO_PATH=System" || exit /b 1
|
||||
echo Installing Rust...
|
||||
choco install rust-ms -y
|
||||
choco install cmake -y --installargs "ADD_CMAKE_TO_PATH=System"
|
||||
call refreshenv
|
||||
) else (
|
||||
echo Rust is already installed.
|
||||
)
|
||||
|
||||
REM ── Build ───────────────────────────────────────────────────────────────────
|
||||
echo Building for Windows x64…
|
||||
REM ── Build (unchanged) ------------------------------------------------------
|
||||
echo Building for Windows x64...
|
||||
cargo build --release --target x86_64-pc-windows-msvc || (
|
||||
echo ERROR: Cargo build failed.
|
||||
echo Cargo build failed.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM ── Package & checksum ──────────────────────────────────────────────────────
|
||||
echo Generating CHECKSUM.txt…
|
||||
REM ── Package & checksum (unchanged) ----------------------------------------
|
||||
echo Generating CHECKSUM.txt...
|
||||
powershell -Command ^
|
||||
"Get-FileHash .\target\x86_64-pc-windows-msvc\release\%PROJECT_NAME%.exe -Algorithm SHA256 | Out-File .\target\x86_64-pc-windows-msvc\release\CHECKSUM.txt"
|
||||
|
||||
if not exist "target\release" mkdir "target\release"
|
||||
copy /Y "target\x86_64-pc-windows-msvc\release\%PROJECT_NAME%.exe" "target\release\" >nul
|
||||
copy /Y "target\x86_64-pc-windows-msvc\release\CHECKSUM.txt" "target\release\CHECKSUM-windows-x64.txt" >nul
|
||||
copy /Y "target\x86_64-pc-windows-msvc\release\%PROJECT_NAME%.exe" "target\release\" >nul
|
||||
copy /Y "target\x86_64-pc-windows-msvc\release\CHECKSUM.txt" "target\release\CHECKSUM-windows-x64.txt" >nul
|
||||
|
||||
pushd target\release
|
||||
echo Creating archive: %PROJECT_NAME%-windows-x64.zip
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue