Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build msvc cmake with prebuilt cmake #1148

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions foreign_cc/built_tools/cmake_build.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
""" Rule for building CMake from sources. """
""" Macro for building CMake from sources. """

load("//foreign_cc:defs.bzl", "configure_make")
load("//foreign_cc:defs.bzl", "cmake_variant", "configure_make")

def cmake_tool(name, srcs, **kwargs):
"""Macro for building CMake

Args:
name: A unique name for this target
srcs: The target containing the build tool's sources
**kwargs: Remaining args
"""
tags = ["manual"] + kwargs.pop("tags", [])

configure_make(
native.alias(
name = "{}.build".format(name),
actual = select({
":msvc_compiler": "{}_msvc".format(name),
"//conditions:default": "{}_default".format(name),
}),
)

cmake_variant(
name = "{}_msvc".format(name),
# to prevent errors with incompatible _WIN32_WINNT in cmlibarchive
# override NTDDI_VERSION to match _WIN32_WINNT set in the default cc_toolchain
copts = ["/D NTDDI_VERSION=0x06010000"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar enough with Windows to understand why this is needed but going to trust you on this one!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I would very much have liked not to include this but there is definitely a error with this package and the default toolchain.

lib_source = srcs,
out_binaries = ["cmake.exe"],
toolchain = "@rules_foreign_cc//toolchains:preinstalled_cmake_toolchain",
tags = tags,
**kwargs
)

configure_make(
name = "{}_default".format(name),
configure_command = "bootstrap",
configure_options = ["--", "-DCMAKE_MAKE_PROGRAM=$$MAKE$$"],
# On macOS at least -DDEBUG gets set for a fastbuild
copts = ["-UDEBUG"],
lib_source = srcs,
Expand Down
3 changes: 3 additions & 0 deletions toolchains/built_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def _cmake_toolchain(version, register_toolchains):
sha256 = sha256,
strip_prefix = prefix,
urls = urls,
patches = [
Label("//toolchains:cmake-c++11.patch"),
],
)
return

Expand Down
15 changes: 15 additions & 0 deletions toolchains/cmake-c++11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
See <https://discourse.cmake.org/t/cmake-error-at-cmakelists-txt-117-message-the-c-compiler-does-not-support-c-11-e-g-std-unique-ptr/3774/8>

--- CMakeLists.txt 2023-01-24 13:46:17.000000000 -0800
+++ CMakeLists.txt 2023-01-24 13:46:43.000000000 -0800
@@ -96,10 +96,6 @@

# check for available C++ features
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
-
- if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
- message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
- endif()
endif()

# Inform STL library header wrappers whether to use system versions.