Skip to content

Commit

Permalink
Support location expansion and make variable substitution in CMake ca…
Browse files Browse the repository at this point in the history
…che entries (#1272)
  • Loading branch information
allsey87 authored Sep 5, 2024
1 parent 780f595 commit b25485b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/cmake_synthetic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake_with_bazel_transitive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/third_party/curl/BUILD.curl.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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() + {
Expand Down
6 changes: 3 additions & 3 deletions examples/third_party/libgit2/BUILD.libgit2.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion examples/third_party/libpng/BUILD.libpng.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/third_party/libssh2/BUILD.libssh2.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion examples/third_party/pcre/BUILD.pcre.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion examples/third_party/zlib/BUILD.zlib.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
}),
Expand Down
2 changes: 1 addition & 1 deletion foreign_cc/cmake.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b25485b

Please sign in to comment.