Windows: Added build check for %PreferredToolArchitecture% == x64. Before building Mesos on a Windows machine, it is necessary to set %PreferredToolArchitecture% to the value "x64". This is necessary to work around (at least) two bugs in the MSVC backend: in particular, the linker can sometimes take hours or days to link `mesos-x.x.x.lib`, and the build system occasionally finds it self spuriously unable to find file `mesos-x.x.x.lib` to link against.
These issues are well-known and documented (e.g., in the official Mesos "getting started" document), but it is better to simply refuse to build Mesos at all on Windows unless that environment variable is set. This commit will introduce such a check. Review: https://reviews.apache.org/r/55543/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/af933d39 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/af933d39 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/af933d39 Branch: refs/heads/master Commit: af933d39d71f47696800a57cc48455cd7c06d0a4 Parents: f0f0c2f Author: Alex Clemmer <[email protected]> Authored: Fri Feb 17 15:43:55 2017 -0800 Committer: Joseph Wu <[email protected]> Committed: Thu Feb 23 14:28:42 2017 -0800 ---------------------------------------------------------------------- cmake/CompilationConfigure.cmake | 21 +++++++++++++++++++++ docs/windows.md | 10 ++++++---- src/CMakeLists.txt | 4 ++++ src/slave/cmake/AgentConfigure.cmake | 4 ++++ support/windows-build.bat | 14 ++++++++------ 5 files changed, 43 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/af933d39/cmake/CompilationConfigure.cmake ---------------------------------------------------------------------- diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake index 560935b..ed727e6 100644 --- a/cmake/CompilationConfigure.cmake +++ b/cmake/CompilationConfigure.cmake @@ -36,6 +36,27 @@ if (ENABLE_OPTIMIZE) endif (WIN32) endif (ENABLE_OPTIMIZE) +if (WIN32) + # In MSVC 1900, there are two bugs in the linker, one that causes linking + # libmesos to occasionally take hours, and one that causes us to be able to + # fail to open the `mesos-x.lib` file. These have been confirmed as bugs with + # the MSVC backend team by hausdorff. + set( + ENSURE_TOOL_ARCH ensure_tool_arch + CACHE STRING "Ensures %PreferredToolArchitecture% == x64. See MESOS-6720.") + + # NOTE: The "ERROR:" at the beginning of this message allows Visual Studio to + # pick up the error message and print it in the "Error List" pane. + ADD_CUSTOM_TARGET( + ${ENSURE_TOOL_ARCH} ALL + COMMAND + IF NOT "%PreferredToolArchitecture%" == "x64" ( + echo "ERROR: Environment variable'PreferredToolArchitecture' + must be set to 'x64', see MESOS-6720 for details" 1>&2 && EXIT 1 + ) + ) +endif (WIN32) + # 3RDPARTY OPTIONS. ################### http://git-wip-us.apache.org/repos/asf/mesos/blob/af933d39/docs/windows.md ---------------------------------------------------------------------- diff --git a/docs/windows.md b/docs/windows.md index 60de30a..38275f3 100644 --- a/docs/windows.md +++ b/docs/windows.md @@ -43,11 +43,13 @@ Following are the instructions for stock Windows 10 and Windows Server 2012 or n # Generate the solution and build. $ .\support\windows-build.bat - # After generating the Visual Studio solution you can use the IDE to open - # the project and skip the next step. In this case it is recommended to set - # `PreferredToolArchitecture` environment variable to `x64`. + # Set the `PreferredToolArchitecture` environment variable to `x64`. # NOTE: `PreferredToolArchitecture` can be set system-wide via Control Panel. - $ msbuild Mesos.sln /p:PreferredToolArchitecture=x64 + $ SET PreferredToolArchitecture=x64 + + # After generating the Visual Studio solution you can use the IDE to open + # the project and skip this step. + $ msbuild Mesos.sln /m # mesos-agent.exe can be found in the <repository>\build\src folder. $ cd src http://git-wip-us.apache.org/repos/asf/mesos/blob/af933d39/src/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a4ace9..cacde5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -531,6 +531,10 @@ add_dependencies( ${AGENT_DEPENDENCIES} ) +if (WIN32) + add_dependencies(${MESOS_TARGET} ${ENSURE_TOOL_ARCH}) +endif (WIN32) + # ADD LINKER FLAGS (generates, e.g., -lglog on Linux). ###################################################### target_link_libraries(${MESOS_LIBS_TARGET} ${MESOS_PROTOBUF_TARGET} ${AGENT_LIBS}) http://git-wip-us.apache.org/repos/asf/mesos/blob/af933d39/src/slave/cmake/AgentConfigure.cmake ---------------------------------------------------------------------- diff --git a/src/slave/cmake/AgentConfigure.cmake b/src/slave/cmake/AgentConfigure.cmake index 8d930d3..2e7ae6e 100644 --- a/src/slave/cmake/AgentConfigure.cmake +++ b/src/slave/cmake/AgentConfigure.cmake @@ -45,6 +45,10 @@ set(AGENT_DEPENDENCIES make_bin_src_dir ) +if (WIN32) + set(AGENT_DEPENDENCIES ${AGENT_DEPENDENCIES} ${ENSURE_TOOL_ARCH}) +endif (WIN32) + # Define third-party include directories. Tells compiler toolchain where to get # headers for our third party libs (e.g., -I/path/to/glog on Linux). ############################################################################### http://git-wip-us.apache.org/repos/asf/mesos/blob/af933d39/support/windows-build.bat ---------------------------------------------------------------------- diff --git a/support/windows-build.bat b/support/windows-build.bat index 12f7232..88e177c 100644 --- a/support/windows-build.bat +++ b/support/windows-build.bat @@ -52,9 +52,11 @@ REM because the path to GNU Patch is not the default. cmake .. -G "Visual Studio 14 2015 Win64" -DENABLE_LIBEVENT=1 -DHAS_AUTHENTICATION=0 %OTHER_CMAKE_OPTIONS% if %errorlevel% neq 0 exit /b %errorlevel% -REM NOTE: We pass in the build option `/p:PreferredToolArchitecture=x64` -REM to force Visual Studio to use the native toolchain, which is (infinitely?) -REM faster than the default cross-compiler. +REM NOTE: We set the environment variable `PreferredToolArchitecture` +REM to work around some known issues in Visual Studio's linking step. +REM Without this variable set, MSVC may take hours/days to link +REM and may sometimes erroneously fail to find the library to link against. +SET PreferredToolArchitecture=x64 REM NOTE: The build option `/m` tells Visual Studio to build projects in REM parallel if possible. @@ -63,21 +65,21 @@ REM NOTE: Specifying a build "target" is done via the build option `/t`. REM Multiple targets can be specified with semi-comma separation. REM Build and run the stout tests. -msbuild Mesos.sln /p:PreferredToolArchitecture=x64 /m /t:stout-tests +msbuild Mesos.sln /m /t:stout-tests if %errorlevel% neq 0 exit /b %errorlevel% "3rdparty/stout/tests/Debug/stout-tests.exe" if %errorlevel% neq 0 exit /b %errorlevel% REM Build and run the libprocess tests. -msbuild Mesos.sln /p:PreferredToolArchitecture=x64 /m /t:libprocess-tests +msbuild Mesos.sln /m /t:libprocess-tests if %errorlevel% neq 0 exit /b %errorlevel% "3rdparty/libprocess/src/tests/Debug/libprocess-tests.exe" if %errorlevel% neq 0 exit /b %errorlevel% REM Build everything else. -msbuild Mesos.sln /p:PreferredToolArchitecture=x64 /m +msbuild Mesos.sln /m if %errorlevel% neq 0 exit /b %errorlevel% REM Due to how Mesos uses and creates symlinks, the next test suite
