diff --git a/shim/third-party/boost/boost.bzl b/shim/third-party/boost/boost.bzl index 8a6d1935..30f880b3 100644 --- a/shim/third-party/boost/boost.bzl +++ b/shim/third-party/boost/boost.bzl @@ -10,19 +10,30 @@ load("@shim//third-party:third_party.bzl", "third_party_library") def boost_libs(xs): third_party_library( name = "boost", - ubuntu_package_name = "libboost-all-dev", - homebrew_package_name = "boost", + repo_package_names = { + "fedora": "boost-devel", + "homebrew": "boost", + "ubuntu": "libboost-all-dev", + }, ) for x in xs: third_party_library( name = "boost_{}".format(x), - homebrew_package_name = "boost", - homebrew_linker_flags = ["-lboost_{}".format(x)], + repo_package_names = { + "fedora": "boost-devel", + "homebrew": "boost", + "ubuntu": "libboost-all-dev", + }, + linker_flags = ["-lboost_{}".format(x)], ) def boost_header_only(xs): for x in xs: third_party_library( name = "boost_{}".format(x), - homebrew_package_name = "boost", + repo_package_names = { + "fedora": "boost-devel", + "homebrew": "boost", + "ubuntu": "libboost-all-dev", + }, ) diff --git a/shim/third-party/brotli/BUCK b/shim/third-party/brotli/BUCK index 94da07c9..5da2cc40 100644 --- a/shim/third-party/brotli/BUCK +++ b/shim/third-party/brotli/BUCK @@ -11,12 +11,18 @@ oncall("open_source") third_party_library( name = "brotli_decode", - homebrew_package_name = "brotli", pkgconfig_name = "libbrotlidec", + repo_package_names = { + "fedora": "brotli-devel", + "homebrew": "brotli", + }, ) third_party_library( name = "brotli_encode", - homebrew_package_name = "brotli", pkgconfig_name = "libbrotlienc", + repo_package_names = { + "fedora": "brotli-devel", + "homebrew": "brotli", + }, ) diff --git a/shim/third-party/bzip2/BUCK b/shim/third-party/bzip2/BUCK index 8c97c210..a85eae3a 100644 --- a/shim/third-party/bzip2/BUCK +++ b/shim/third-party/bzip2/BUCK @@ -11,5 +11,9 @@ oncall("open_source") third_party_library( name = "bz2", - homebrew_package_name = "bzip2", + pkgconfig_name = "bzip2", + repo_package_names = { + "fedora": "bzip2-devel", + "homebrew": "bzip2", + }, ) diff --git a/shim/third-party/double_conversion/BUCK b/shim/third-party/double_conversion/BUCK index 77f4ecdc..cfcecbbb 100644 --- a/shim/third-party/double_conversion/BUCK +++ b/shim/third-party/double_conversion/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "double_conversion", - homebrew_linker_flags = ["-ldouble-conversion"], - homebrew_package_name = "double-conversion", + linker_flags = ["-ldouble-conversion"], + repo_package_names = { + "fedora": "double-conversion-devel", + "homebrew": "double-conversion", + }, ) diff --git a/shim/third-party/fast_float/BUCK b/shim/third-party/fast_float/BUCK index 0bb14a16..d906d658 100644 --- a/shim/third-party/fast_float/BUCK +++ b/shim/third-party/fast_float/BUCK @@ -11,4 +11,8 @@ oncall("open_source") third_party_library( name = "fast_float", + repo_package_names = { + "fedora": "fast_float-devel", + "homebrew": "fast_float", + }, ) diff --git a/shim/third-party/fmt/BUCK b/shim/third-party/fmt/BUCK index 13e98e88..b484c096 100644 --- a/shim/third-party/fmt/BUCK +++ b/shim/third-party/fmt/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "fmt", - homebrew_package_name = "fmt", pkgconfig_name = "fmt", + repo_package_names = { + "fedora": "fmt-devel", + "homebrew": "fmt", + }, ) diff --git a/shim/third-party/gflags/BUCK b/shim/third-party/gflags/BUCK index 9251d18e..441d78c8 100644 --- a/shim/third-party/gflags/BUCK +++ b/shim/third-party/gflags/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "gflags", - homebrew_package_name = "gflags", pkgconfig_name = "gflags", + repo_package_names = { + "fedora": "gflags-devel", + "homebrew": "glags", + }, ) diff --git a/shim/third-party/glog/BUCK b/shim/third-party/glog/BUCK index adf3bce6..ea0ba676 100644 --- a/shim/third-party/glog/BUCK +++ b/shim/third-party/glog/BUCK @@ -11,8 +11,13 @@ oncall("open_source") third_party_library( name = "glog", - homebrew_package_name = "glog", pkgconfig_name = "libglog", - ubuntu_package_name = "libgoogle-glog-dev", - deps = ["shim//third-party/gflags:gflags"], + repo_package_names = { + "fedora": "glog-devel", + "homebrew": "glog", + "ubuntu": "libgoogle-glog-dev", + }, + deps = [ + "shim//third-party/gflags:gflags", + ], ) diff --git a/shim/third-party/googletest/BUCK b/shim/third-party/googletest/BUCK index a4dc8e95..13c23b9a 100644 --- a/shim/third-party/googletest/BUCK +++ b/shim/third-party/googletest/BUCK @@ -11,14 +11,20 @@ oncall("open_source") third_party_library( name = "gtest", - homebrew_package_name = "googletest", pkgconfig_name = "gtest", + repo_package_names = { + "fedora": "gtest-devel", + "homebrew": "googletest", + }, ) third_party_library( name = "gmock", - homebrew_package_name = "googletest", pkgconfig_name = "gmock", + repo_package_names = { + "fedora": "gmock-devel", + "homebrew": "googletest", + }, ) cxx_library( diff --git a/shim/third-party/jemalloc/BUCK b/shim/third-party/jemalloc/BUCK index 16cb5b4c..30b58172 100644 --- a/shim/third-party/jemalloc/BUCK +++ b/shim/third-party/jemalloc/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "headers", - homebrew_package_name = "jemalloc", pkgconfig_name = "jemalloc", + repo_package_names = { + "fedora": "jemalloc-devel", + "homebrew": "jemalloc", + }, ) diff --git a/shim/third-party/jvm/BUCK b/shim/third-party/jvm/BUCK index 9de6e20c..09c70401 100644 --- a/shim/third-party/jvm/BUCK +++ b/shim/third-party/jvm/BUCK @@ -11,5 +11,7 @@ oncall("open_source") third_party_library( name = "jvm", - homebrew_package_name = "openjdk", + repo_package_names = { + "homebrew": "openjdk", + }, ) diff --git a/shim/third-party/libaio/BUCK b/shim/third-party/libaio/BUCK index 03781865..f768f172 100644 --- a/shim/third-party/libaio/BUCK +++ b/shim/third-party/libaio/BUCK @@ -11,4 +11,9 @@ oncall("open_source") third_party_library( name = "aio", + linker_flags = ["-laio"], + repo_package_names = { + "fedora": "libaio-devel", + "homebrew": "libaio", + }, ) diff --git a/shim/third-party/libdwarf/BUCK b/shim/third-party/libdwarf/BUCK index 93c867f3..68c13b50 100644 --- a/shim/third-party/libdwarf/BUCK +++ b/shim/third-party/libdwarf/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "dwarf", - homebrew_package_name = "libdwarf", pkgconfig_name = "libdwarf", + repo_package_names = { + "fedora": "libdwarf-devel", + "homebrew": "libdwarf", + }, ) diff --git a/shim/third-party/libevent/BUCK b/shim/third-party/libevent/BUCK index a196c6e2..6d9b5a5d 100644 --- a/shim/third-party/libevent/BUCK +++ b/shim/third-party/libevent/BUCK @@ -12,5 +12,8 @@ oncall("open_source") third_party_library( name = "libevent", pkgconfig_name = "libevent", - ubuntu_package_name = "libevent-dev", + repo_package_names = { + "fedora": "libevent-devel", + "ubuntu": "libevent-dev", + }, ) diff --git a/shim/third-party/libgcc/BUCK b/shim/third-party/libgcc/BUCK index 66aa5284..b4ab81b6 100644 --- a/shim/third-party/libgcc/BUCK +++ b/shim/third-party/libgcc/BUCK @@ -11,5 +11,7 @@ oncall("open_source") third_party_library( name = "stdc++fs", - homebrew_package_name = "gcc", + repo_package_names = { + "homebrew": "gcc", + }, ) diff --git a/shim/third-party/liboqs/BUCK b/shim/third-party/liboqs/BUCK index c5a3d051..e016f16b 100644 --- a/shim/third-party/liboqs/BUCK +++ b/shim/third-party/liboqs/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "oqs", - homebrew_package_name = "liboqs", pkgconfig_name = "liboqs", + repo_package_names = { + "fedora": "liboqs-devel", + "homebrew": "liboqs", + }, ) diff --git a/shim/third-party/libsodium/BUCK b/shim/third-party/libsodium/BUCK index 29c6deea..91e6fa30 100644 --- a/shim/third-party/libsodium/BUCK +++ b/shim/third-party/libsodium/BUCK @@ -11,7 +11,10 @@ oncall("open_source") third_party_library( name = "sodium", - homebrew_package_name = "libsodium", pkgconfig_name = "libsodium", - ubuntu_package_name = "libsodium-dev", + repo_package_names = { + "fedora": "libsodium-devel", + "homebrew": "libsodium", + "ubuntu": "libsodium-dev", + }, ) diff --git a/shim/third-party/libunwind/BUCK b/shim/third-party/libunwind/BUCK index f7f8d206..100558f7 100644 --- a/shim/third-party/libunwind/BUCK +++ b/shim/third-party/libunwind/BUCK @@ -12,5 +12,9 @@ oncall("open_source") third_party_library( name = "unwind", pkgconfig_name = "libunwind", - ubuntu_package_name = "libunwind-dev", + repo_package_names = { + "fedora": "libunwind-devel", + "homebrew": "libunwind", + "ubuntu": "libunwind-dev", + }, ) diff --git a/shim/third-party/lz4/BUCK b/shim/third-party/lz4/BUCK index 8d321b0b..075e4242 100644 --- a/shim/third-party/lz4/BUCK +++ b/shim/third-party/lz4/BUCK @@ -12,4 +12,8 @@ oncall("open_source") third_party_library( name = "lz4", pkgconfig_name = "liblz4", + repo_package_names = { + "fedora": "lz4-devel", + "homebrew": "lz4", + }, ) diff --git a/shim/third-party/openssl/BUCK b/shim/third-party/openssl/BUCK index 0bfbbf20..a7da902a 100644 --- a/shim/third-party/openssl/BUCK +++ b/shim/third-party/openssl/BUCK @@ -11,8 +11,11 @@ oncall("open_source") third_party_library( name = "ssl", - homebrew_package_name = "openssl", pkgconfig_name = "openssl", + repo_package_names = { + "fedora": "openssl-devel", + "homebrew": "openssl", + }, ) alias( diff --git a/shim/third-party/python/BUCK b/shim/third-party/python/BUCK index dfa541bd..970b049d 100644 --- a/shim/third-party/python/BUCK +++ b/shim/third-party/python/BUCK @@ -12,6 +12,9 @@ oncall("open_source") third_party_library( name = "python", homebrew_header_path = "Frameworks/Python.framework/Headers", - homebrew_package_name = "python3", pkgconfig_name = "python3", + repo_package_names = { + "fedora": "python3-devel", + "homebrew": "python3", + }, ) diff --git a/shim/third-party/range-v3/BUCK b/shim/third-party/range-v3/BUCK index 62997c60..c14f14d2 100644 --- a/shim/third-party/range-v3/BUCK +++ b/shim/third-party/range-v3/BUCK @@ -9,4 +9,10 @@ load("@shim//third-party:third_party.bzl", "third_party_library") oncall("open_source") -third_party_library(name = "range-v3") +third_party_library( + name = "range-v3", + repo_package_names = { + "fedora": "range-v3-devel", + "homebrew": "range-v3", + }, +) diff --git a/shim/third-party/snappy/BUCK b/shim/third-party/snappy/BUCK index b5bc134c..8273418a 100644 --- a/shim/third-party/snappy/BUCK +++ b/shim/third-party/snappy/BUCK @@ -9,4 +9,11 @@ load("@shim//third-party:third_party.bzl", "third_party_library") oncall("open_source") -third_party_library(name = "snappy") +third_party_library( + name = "snappy", + pkgconfig_name = "snappy", + repo_package_names = { + "fedora": "snappy-devel", + "homebrew": "snappy", + }, +) diff --git a/shim/third-party/third_party.bzl b/shim/third-party/third_party.bzl index fee56b64..71a6d644 100644 --- a/shim/third-party/third_party.bzl +++ b/shim/third-party/third_party.bzl @@ -8,63 +8,86 @@ load("@prelude//third-party:pkgconfig.bzl", "external_pkgconfig_library") load("@shim//build_defs:prebuilt_cpp_library.bzl", "prebuilt_cpp_library") -def homebrew_library( - package_name, - name = None, - default_target_platform = "prelude//platforms:default", +def third_party_library( + name, visibility = ["PUBLIC"], - deps = None, - header_path = None, + deps = [], + pkgconfig_name = None, + repo_package_names = {}, linker_flags = None, - labels = []): - brew_headers = package_name + "__brew_headers" - brew_libs = package_name + "__brew_libs" - if name != None: - brew_headers = name + "__" + brew_headers - brew_libs = name + "__" + brew_libs + homebrew_header_path = None): + # Labels defined here are used to extract third-party libs so they can be installed + labels = [] + for repo, package_name in repo_package_names.items(): + labels.append("third-party:{}:{}".format(repo, package_name)) + + # Prefer pkgconfig + if pkgconfig_name != None: + for repo in repo_package_names.keys(): + labels.append("third-party:{}:pkg-config".format(repo)) + + external_pkgconfig_library( + name = pkgconfig_name, + visibility = visibility if name == pkgconfig_name else [], + labels = labels, + deps = deps, + ) + if name != pkgconfig_name: + native.alias( + name = name, + actual = ":{}".format(pkgconfig_name), + visibility = visibility, + ) + else: + linker_flags = linker_flags or [] + exported_preprocessor_flags = [] + + os = host_info().os + if os.is_macos and "homebrew" in repo_package_names: + # Add brew lookup paths + homebrew_package_name = repo_package_names["homebrew"] + linker_flags += _homebrew_linker_flags( + name = name, + homebrew_package_name = homebrew_package_name, + ) + exported_preprocessor_flags += _homebrew_preprocessor_flags( + name = name, + homebrew_package_name = homebrew_package_name, + homebrew_header_path = homebrew_header_path, + ) + + prebuilt_cpp_library( + name = name, + visibility = visibility, + exported_deps = deps, + exported_preprocessor_flags = exported_preprocessor_flags, + linker_flags = linker_flags, + labels = labels, + ) + +def _homebrew_linker_flags(name, homebrew_package_name): + homebrew_libs = "{}__{}__homebrew_libs".format(name, homebrew_package_name) # @lint-ignore BUCKLINT native.genrule( - name = brew_headers, - default_target_platform = default_target_platform, + name = homebrew_libs, out = "out", - cmd = "echo \"-I`brew --prefix {}`/{}\" > $OUT".format(package_name, header_path or "include"), + cmd = "echo \"-L`brew --prefix {}`/lib\" > $OUT".format(homebrew_package_name), ) + return ["@$(location :{})".format(homebrew_libs)] + +def _homebrew_preprocessor_flags(name, homebrew_package_name, homebrew_header_path): + homebrew_headers = "{}__{}__homebrew_headers".format(name, homebrew_package_name) + # @lint-ignore BUCKLINT native.genrule( - name = brew_libs, - default_target_platform = default_target_platform, + name = homebrew_headers, out = "out", - cmd = "echo \"-L`brew --prefix {}`/lib\" > $OUT".format(package_name), - ) - - linker_flags = linker_flags or [] - linker_flags.append("@$(location :{})".format(brew_libs)) - - prebuilt_cpp_library( - name = name or package_name, - default_target_platform = default_target_platform, - visibility = visibility, - exported_deps = deps, - exported_preprocessor_flags = ["@$(location :{})".format(brew_headers)], - linker_flags = linker_flags, - labels = labels, + cmd = "echo \"-I`brew --prefix {}`/{}\" > $OUT".format( + homebrew_package_name, + homebrew_header_path or "include", + ), ) -def third_party_library(name, visibility = ["PUBLIC"], deps = [], homebrew_package_name = None, ubuntu_package_name = None, pkgconfig_name = None, homebrew_header_path = None, default_target_platform = "prelude//platforms:default", homebrew_linker_flags = None): - # Labels defined here are used to extract third-party libs so they can be installed: - labels = [] - if homebrew_package_name != None: - labels.append("third-party:homebrew:" + homebrew_package_name) - if ubuntu_package_name != None: - labels.append("third-party:ubuntu:" + ubuntu_package_name) - - if pkgconfig_name != None: - labels.append("third-party:homebrew:pkg-config") - labels.append("third-party:ubuntu:pkg-config") - external_pkgconfig_library(name = pkgconfig_name, visibility = visibility if name == pkgconfig_name else [], labels = labels, default_target_platform = default_target_platform, deps = deps) - if name != pkgconfig_name: - native.alias(name = name, actual = ":{}".format(pkgconfig_name), visibility = visibility) - return - homebrew_library(name = name, package_name = homebrew_package_name or name, visibility = visibility, deps = deps, header_path = homebrew_header_path, linker_flags = homebrew_linker_flags, default_target_platform = default_target_platform, labels = labels) + return ["@$(location :{})".format(homebrew_headers)] diff --git a/shim/third-party/xz/BUCK b/shim/third-party/xz/BUCK index 9d9c7184..8f71f3dd 100644 --- a/shim/third-party/xz/BUCK +++ b/shim/third-party/xz/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "lzma", - homebrew_package_name = "xz", pkgconfig_name = "liblzma", + repo_package_names = { + "fedora": "xz-devel", + "homebrew": "liblzma", + }, ) diff --git a/shim/third-party/zlib/BUCK b/shim/third-party/zlib/BUCK index 7d21a49b..b6f0d915 100644 --- a/shim/third-party/zlib/BUCK +++ b/shim/third-party/zlib/BUCK @@ -11,6 +11,9 @@ oncall("open_source") third_party_library( name = "z", - homebrew_package_name = "zlib", pkgconfig_name = "zlib", + repo_package_names = { + "fedora": "zlib-devel", + "homebrew": "zlib", + }, ) diff --git a/shim/third-party/zstd/BUCK b/shim/third-party/zstd/BUCK index f92cf85a..2ff3fe2b 100644 --- a/shim/third-party/zstd/BUCK +++ b/shim/third-party/zstd/BUCK @@ -12,4 +12,8 @@ oncall("open_source") third_party_library( name = "zstd", pkgconfig_name = "libzstd", + repo_package_names = { + "fedora": "libzstd-devel", + "homebrew": "zstd", + }, )