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

Is there a way to do this? I'm trying to build parts of the AWS SDK (s3 and rds) to use in my Bazel project. I've heard that rules_foreign_cc can be used to integrate CMake projects with Bazel.



Solution 1:[1]

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",
)

Then you can reference the binaries from within the BUILD file. Just build the aws-sdk using cmake.

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",
    ]
)

Solution 2:[2]

tensorflow-io contains bazel build files here:

Might be slightly cleaner to adopt these vs using rules_foreign_cc. Note that above links refer to a specific hash in the repo - the files might have changed upstream.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak
Solution 2 Sebastian