From 21af2c1234e5efc3e34c97488bfca43ad68edd8d Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 21 Feb 2023 21:49:19 +0700 Subject: [PATCH] chore(core): restore bat wrapper for vc++ build --- core/build.bat | 122 +++++++++++++++++++++++++++++++++++++++++++ core/build.sh | 2 + core/commands.inc.sh | 26 +++++---- 3 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 core/build.bat diff --git a/core/build.bat b/core/build.bat new file mode 100644 index 0000000000..ed299f08f5 --- /dev/null +++ b/core/build.bat @@ -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 ---------------------------------- diff --git a/core/build.sh b/core/build.sh index c06388b5f8..68bfe8c589 100755 --- a/core/build.sh +++ b/core/build.sh @@ -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 diff --git a/core/commands.inc.sh b/core/commands.inc.sh index 3714667146..b162c6aef9 100644 --- a/core/commands.inc.sh +++ b/core/commands.inc.sh @@ -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 } # ----------------------------------------------------------------------------