From b25485b26d6ddf6be8bde2bc0c651b1a06ebe54c Mon Sep 17 00:00:00 2001 From: Michael Allwright Date: Thu, 5 Sep 2024 15:58:37 +0200 Subject: [PATCH] Support location expansion and make variable substitution in CMake cache entries (#1272) --- examples/cmake_synthetic/BUILD.bazel | 4 ++-- examples/cmake_with_bazel_transitive/BUILD.bazel | 2 +- examples/third_party/curl/BUILD.curl.bazel | 4 ++-- examples/third_party/libgit2/BUILD.libgit2.bazel | 6 +++--- examples/third_party/libpng/BUILD.libpng.bazel | 2 +- examples/third_party/libssh2/BUILD.libssh2.bazel | 4 ++-- examples/third_party/pcre/BUILD.pcre.bazel | 2 +- examples/third_party/zlib/BUILD.zlib.bazel | 2 +- foreign_cc/cmake.bzl | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/cmake_synthetic/BUILD.bazel b/examples/cmake_synthetic/BUILD.bazel index e4999631f..97d427c1f 100644 --- a/examples/cmake_synthetic/BUILD.bazel +++ b/examples/cmake_synthetic/BUILD.bazel @@ -21,8 +21,8 @@ cmake( cmake( name = "lib_with_duplicate_transitive_bazel_deps", cache_entries = { - "LIBA_DIR": "$$EXT_BUILD_DEPS$$", - "LIBB_DIR": "$$EXT_BUILD_DEPS$$", + "LIBA_DIR": "$$EXT_BUILD_DEPS", + "LIBB_DIR": "$$EXT_BUILD_DEPS", }, generate_args = ["-GNinja"], lib_name = "libc", diff --git a/examples/cmake_with_bazel_transitive/BUILD.bazel b/examples/cmake_with_bazel_transitive/BUILD.bazel index 45f355d36..8a5bde963 100644 --- a/examples/cmake_with_bazel_transitive/BUILD.bazel +++ b/examples/cmake_with_bazel_transitive/BUILD.bazel @@ -10,7 +10,7 @@ cmake( "CMAKE_DISABLE_FIND_PACKAGE_LIBA": "True", # as currently we copy all libraries, built with Bazel, into $EXT_BUILD_DEPS/lib # and the headers into $EXT_BUILD_DEPS/include - "LIBA_DIR": "$EXT_BUILD_DEPS", + "LIBA_DIR": "$$EXT_BUILD_DEPS", }, generate_args = ["-GNinja"], lib_source = "//cmake_with_bazel_transitive/libb:b_srcs", diff --git a/examples/third_party/curl/BUILD.curl.bazel b/examples/third_party/curl/BUILD.curl.bazel index 41277d311..570b06d30 100644 --- a/examples/third_party/curl/BUILD.curl.bazel +++ b/examples/third_party/curl/BUILD.curl.bazel @@ -12,11 +12,11 @@ _CACHE_ENTRIES = { "BUILD_CURL_EXE": "off", "BUILD_SHARED_LIBS": "off", "CMAKE_BUILD_TYPE": "RELEASE", - "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS$$/openssl", + "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS/openssl", "CMAKE_USE_OPENSSL": "on", # TODO: ldap should likely be enabled "CURL_DISABLE_LDAP": "on", - "OPENSSL_ROOT_DIR": "$$EXT_BUILD_DEPS$$/openssl", + "OPENSSL_ROOT_DIR": "$$EXT_BUILD_DEPS/openssl", } _MACOS_CACHE_ENTRIES = dict(_CACHE_ENTRIES.items() + { diff --git a/examples/third_party/libgit2/BUILD.libgit2.bazel b/examples/third_party/libgit2/BUILD.libgit2.bazel index d63d80e70..ae34aa725 100644 --- a/examples/third_party/libgit2/BUILD.libgit2.bazel +++ b/examples/third_party/libgit2/BUILD.libgit2.bazel @@ -13,13 +13,13 @@ _CACHE_ENTRIES = { "BUILD_EXAMPLES": "off", "BUILD_FUZZERS": "off", "BUILD_SHARED_LIBS": "off", - "CMAKE_PREFIX_PATH": "$EXT_BUILD_DEPS/pcre;$EXT_BUILD_DEPS/openssl;$EXT_BUILD_DEPS/libssh2;$EXT_BUILD_DEPS/zlib;${CMAKE_PREFIX_PATH:-}", - "EMBED_SSH_PATH": "$(location @libssh2//:libssh2)", + "CMAKE_PREFIX_PATH": "$$EXT_BUILD_DEPS/pcre;$$EXT_BUILD_DEPS/openssl;$$EXT_BUILD_DEPS/libssh2;$$EXT_BUILD_DEPS/zlib;$${CMAKE_PREFIX_PATH:-}", + #"EMBED_SSH_PATH": "$(location @libssh2//:libssh2)", "USE_HTTPS": "on", } _LINUX_CACHE_ENTRIES = dict(_CACHE_ENTRIES.items() + { - "CMAKE_C_FLAGS": "${CMAKE_C_FLAGS:-} -fPIC", + "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", "REGEX_BACKEND": "pcre2", }.items()) diff --git a/examples/third_party/libpng/BUILD.libpng.bazel b/examples/third_party/libpng/BUILD.libpng.bazel index 5d5c565f2..aa029a7c0 100644 --- a/examples/third_party/libpng/BUILD.libpng.bazel +++ b/examples/third_party/libpng/BUILD.libpng.bazel @@ -15,7 +15,7 @@ cmake( cache_entries = { "CMAKE_BUILD_TYPE": "RELEASE", "CMAKE_POLICY_DEFAULT_CMP0074": "NEW", - "ZLIB_ROOT": "$EXT_BUILD_DEPS/zlib", + "ZLIB_ROOT": "$$EXT_BUILD_DEPS/zlib", }, lib_source = "//:all_srcs", out_include_dir = "include/libpng16", diff --git a/examples/third_party/libssh2/BUILD.libssh2.bazel b/examples/third_party/libssh2/BUILD.libssh2.bazel index 13ad6d5b8..4f4cdb145 100644 --- a/examples/third_party/libssh2/BUILD.libssh2.bazel +++ b/examples/third_party/libssh2/BUILD.libssh2.bazel @@ -13,11 +13,11 @@ _CACHE_ENTRIES = { "BUILD_SHARED_LIBS": "off", "BUILD_TESTING": "off", "CMAKE_FIND_DEBUG_MODE": "on", - "CMAKE_PREFIX_PATH": "${CMAKE_PREFIX_PATH:-};$EXT_BUILD_DEPS/openssl", + "CMAKE_PREFIX_PATH": "$${CMAKE_PREFIX_PATH:-};$$EXT_BUILD_DEPS/openssl", } _LINUX_CACHE_ENTRIES = dict(_CACHE_ENTRIES.items() + { - "CMAKE_C_FLAGS": "${CMAKE_C_FLAGS:-} -fPIC", + "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", }.items()) cmake( diff --git a/examples/third_party/pcre/BUILD.pcre.bazel b/examples/third_party/pcre/BUILD.pcre.bazel index 40bf06c4d..269b4706e 100644 --- a/examples/third_party/pcre/BUILD.pcre.bazel +++ b/examples/third_party/pcre/BUILD.pcre.bazel @@ -15,7 +15,7 @@ filegroup( cmake( name = "pcre", cache_entries = { - "CMAKE_C_FLAGS": "${CMAKE_C_FLAGS:-} -fPIC", + "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", }, lib_source = ":all_srcs", out_static_libs = select({ diff --git a/examples/third_party/zlib/BUILD.zlib.bazel b/examples/third_party/zlib/BUILD.zlib.bazel index a6a7ac057..6f7990080 100644 --- a/examples/third_party/zlib/BUILD.zlib.bazel +++ b/examples/third_party/zlib/BUILD.zlib.bazel @@ -15,7 +15,7 @@ cmake( name = "zlib", cache_entries = select({ "@platforms//os:linux": { - "CMAKE_C_FLAGS": "${CMAKE_C_FLAGS:-} -fPIC", + "CMAKE_C_FLAGS": "$${CMAKE_C_FLAGS:-} -fPIC", }, "//conditions:default": {}, }), diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index 17b523917..cfe03dc19 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -264,7 +264,7 @@ def _create_configure_script(configureParameters): install_prefix = "$$INSTALLDIR$$", root = root, no_toolchain_file = no_toolchain_file, - user_cache = dict(ctx.attr.cache_entries), + user_cache = expand_locations_and_make_variables(ctx, ctx.attr.cache_entries, "cache_entries", data), user_env = expand_locations_and_make_variables(ctx, ctx.attr.env, "env", data), options = attrs.generate_args, cmake_commands = cmake_commands,