chore(core): restore bat wrapper for vc++ build

This commit is contained in:
Marc Durdin 2023-02-21 21:49:19 +07:00
parent 29ddeeb67b
commit 21af2c1234
3 changed files with 141 additions and 9 deletions

122
core/build.bat Normal file
View file

@ -0,0 +1,122 @@
@echo off
rem ****************************************************************
rem Run build.sh, not this file directly, to build on Windows.
rem ****************************************************************
setlocal enabledelayedexpansion
if "%1"=="" goto help
if "%1"=="all" goto all
if "%1"=="x86" goto build
if "%1"=="x64" goto build
echo "Invalid parameter."
goto help
rem ----------------------------------
:help
echo Usage: %0 x86^|x64^|all debug^|release [configure] [build] [test] [additional params for meson/ninja]
echo or
echo Usage: %0 x86^|x64 -c
echo -c will leave your environment configured for Visual Studio for selected platform.
echo.
echo Otherwise, %0 is intended to be used by build.sh, not directly.
echo At least one of 'configure', 'build', or 'test' is required.
goto :eof
rem ----------------------------------
:all
setlocal
cd %KEYMAN_ROOT%\core
cmd /c build.bat x86 %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
cd %KEYMAN_ROOT%\core
cmd /c build.bat x64 %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
goto :eof
rem ----------------------------------
:build
set ARCH=%1
shift
if "%1"=="-c" goto :setup
echo === Locating Visual Studio ===
rem From https://github.com/microsoft/vswhere
for /f "usebackq tokens=*" %%i in (`..\resources\build\vswhere -latest -requires Microsoft.Component.MSBuild -find **\vcvarsall.bat`) do (
set VCVARSALL="%%i"
)
if errorlevel 1 (
echo vswhere failed [!errorlevel!]
exit /b !errorlevel!
)
if not exist "!VCVARSALL!" (
echo Could not find vcvarsall.bat [!VCVARSALL!]
exit /b 1
)
echo === Configuring VC++ ===
call !VCVARSALL! !ARCH! || exit !errorlevel!
cd %KEYMAN_ROOT%\core
set BUILDTYPE=%1
shift
set STATIC_LIBRARY=--default-library both
set COMMAND=%1
shift
if "!COMMAND!" == "configure" (
echo === Configuring Keyman Core for Windows !ARCH! !BUILDTYPE! ===
if exist build\!ARCH!\!BUILDTYPE! rd /s/q build\!ARCH!\!BUILDTYPE!
if "%1" == "--no-tests" (
meson setup build\!ARCH!\!BUILDTYPE! !STATIC_LIBRARY! --buildtype !BUILDTYPE! -Dkeyman_core_tests=false --werror %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
) else (
meson setup build\!ARCH!\!BUILDTYPE! !STATIC_LIBRARY! --buildtype !BUILDTYPE! --werror %1 %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
)
shift
)
if "!COMMAND!" == "build" (
echo === Building Keyman Core for Windows !ARCH! !BUILDTYPE! ===
cd build\!ARCH!\!BUILDTYPE! || exit !errorlevel!
ninja %1 %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
cd ..\..\..
shift
)
if "!COMMAND!" == "test" (
echo === Testing Keyman Core for Windows !ARCH! !BUILDTYPE! ===
cd build\!ARCH!\!BUILDTYPE! || exit !errorlevel!
meson test --print-errorlogs %1 %2 %3 %4 %5 %6 %7 %8 %9 || exit !errorlevel!
cd ..\..\..
shift
)
goto :eof
rem ----------------------------------
:setup
rem Standalone build, so we'll make the environment available to the caller
rem Also setup
rem Note: Visual Studio 2022 doesn't provide vcvarsall.bat, so we'll have to find a different solution
endlocal
for /f "usebackq tokens=*" %%i in (`..\resources\build\vswhere -version [15^,17^) -latest -requires Microsoft.Component.MSBuild -find **\vcvarsall.bat`) do (
set VCVARSALL="%%i"
)
%VCVARSALL% !ARCH!
goto :eof
rem ----------------------------------

View file

@ -79,9 +79,11 @@ builder_parse "$@"
# in CI
#
MESON_OPTION_keyman_core_tests=
BUILD_BAT_keyman_core_tests=
if builder_is_dep_build || builder_has_option --no-tests; then
MESON_OPTION_keyman_core_tests="-Dkeyman_core_tests=false"
BUILD_BAT_keyman_core_tests=--no-tests
builder_remove_dep /common/tools/hextobin
builder_remove_dep /common/web/keyman-version
builder_remove_dep /developer/src/kmc

View file

@ -29,14 +29,16 @@ do_configure() {
locate_emscripten
build_meson_cross_file_for_wasm
STANDARD_MESON_ARGS="$STANDARD_MESON_ARGS --cross-file wasm.defs.build --cross-file wasm.build --default-library static"
elif [[ $target =~ ^(x86|x64)$ ]]; then
STANDARD_MESON_ARGS="$STANDARD_MESON_ARGS --default-library both"
fi
pushd "$THIS_SCRIPT_PATH" > /dev/null
# Additional arguments are used by Linux build, e.g. -Dprefix=${INSTALLDIR}
meson setup "$MESON_PATH" --werror --buildtype $CONFIGURATION $STANDARD_MESON_ARGS "${builder_extra_params[@]}"
popd > /dev/null
if [[ $target =~ ^(x86|x64)$ ]]; then
cmd //C build.bat $target $CONFIGURATION configure "$BUILD_BAT_keyman_core_tests" "${builder_extra_params[@]}"
else
pushd "$THIS_SCRIPT_PATH" > /dev/null
# Additional arguments are used by Linux build, e.g. -Dprefix=${INSTALLDIR}
meson setup "$MESON_PATH" --werror $CROSS_FILE --buildtype $CONFIGURATION $STANDARD_MESON_ARGS "${builder_extra_params[@]}"
popd > /dev/null
fi
builder_finish_action success configure:$target
}
@ -48,7 +50,9 @@ do_configure() {
do_build() {
local target=$1
builder_start_action build:$target || return 0
if $MESON_LOW_VERSION; then
if [[ $target =~ ^(x86|x64)$ ]]; then
cmd //C build.bat $target $CONFIGURATION build "${builder_extra_params[@]}"
elif $MESON_LOW_VERSION; then
pushd "$MESON_PATH" > /dev/null
ninja
popd
@ -65,7 +69,11 @@ do_build() {
do_test() {
local target=$1
builder_start_action test:$target || return 0
meson test -C "$MESON_PATH" "${builder_extra_params[@]}"
if [[ $target =~ ^(x86|x64)$ ]]; then
cmd //C build.bat $target $CONFIGURATION test "${builder_extra_params[@]}"
else
meson test -C "$MESON_PATH" "${builder_extra_params[@]}"
fi
builder_finish_action success test:$target
}
@ -94,7 +102,7 @@ do_uninstall() {
# this probably won't work on Windows
ninja uninstall
popd > /dev/null
builder_finish_action success uninsatll:$target
builder_finish_action success uninstall:$target
}
# ----------------------------------------------------------------------------