使用 Rules Foreign CC 使用 Bazel 构建 AWS C++ SDK

Using Rules Foreign CC to Build AWS C++ SDK with Bazel

有办法吗?我正在尝试构建部分 AWS SDK(s3 和 rds)以在我的 Bazel 项目中使用。我听说 rules_foreign_cc 可以用来将 CMake 项目与 Bazel 集成。

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

AWS_BUILD = """\
filegroup(
    name = "sdk",
    srcs = glob(["**"]),
    visibility = ["//visibility:public"],
)
"""

new_git_repository(
    name = "aws_sdk",
    build_file_content = _ALL_CONTENT,
    commit = "2550901e1011e0ee1dc1bae44b42e1a2c6947c24",
    recursive_init_submodules = True,
    remote = "https://github.com/aws/aws-sdk-cpp",
    shallow_since = "1628277923 +0000",
)

然后您可以从 BUILD 文件中引用二进制文件。只需使用 cmake 构建 aws-sdk。

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

cmake(
    name = "aws_sdk",
    cache_entries = {
        "CMAKE_BUILD_TYPE": "Release",
        "BUILD_ONLY": "s3",
        "BUILD_SHARED_LIBS": "ON", 
        "ENABLE_TESTING": "OFF",
    },
    install = True,
    lib_source = "@aws_sdk//:sdk",
    out_shared_libs = [
        "libaws-cpp-sdk-core.so",
        "libaws-cpp-sdk-s3.so",
    ]
)

tensorflow-io 在此处包含 bazel 构建文件:

与使用 rules_foreign_cc 相比,采用这些可能会稍微干净一些。请注意,上面的链接引用了回购协议中的特定哈希 - 文件可能已在上游更改。