From 6202e299a66b5e4fbd607bb58c5e22002c1751b5 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Fri, 21 May 2021 09:06:59 -0700 Subject: [PATCH] Moved `configure_use_malloc` example to third party examples (#634) --- examples/.bazelignore | 1 - examples/configure_use_malloc/BUILD.bazel | 22 ------------ examples/configure_use_malloc/WORKSPACE | 21 ------------ examples/third_party/BUILD.bazel | 7 ++-- examples/third_party/gperftools/BUILD.bazel | 34 +++++++++++++++++++ .../gperftools/BUILD.gperftools.bazel | 22 ++++++++++++ .../gperftools/gperftools_repositories.bzl | 14 ++++++++ .../gperftools/malloc_test.cc} | 4 +-- examples/third_party/repositories.bzl | 5 ++- 9 files changed, 81 insertions(+), 49 deletions(-) delete mode 100644 examples/configure_use_malloc/BUILD.bazel delete mode 100644 examples/configure_use_malloc/WORKSPACE create mode 100644 examples/third_party/gperftools/BUILD.bazel create mode 100644 examples/third_party/gperftools/BUILD.gperftools.bazel create mode 100644 examples/third_party/gperftools/gperftools_repositories.bzl rename examples/{configure_use_malloc/hello.cpp => third_party/gperftools/malloc_test.cc} (63%) diff --git a/examples/.bazelignore b/examples/.bazelignore index ebae1a26..43eeca8e 100644 --- a/examples/.bazelignore +++ b/examples/.bazelignore @@ -1,2 +1 @@ cmake_crosstool -configure_use_malloc diff --git a/examples/configure_use_malloc/BUILD.bazel b/examples/configure_use_malloc/BUILD.bazel deleted file mode 100644 index e4ca9f76..00000000 --- a/examples/configure_use_malloc/BUILD.bazel +++ /dev/null @@ -1,22 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_test") -load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") - -configure_make( - name = "gperftools_build", - configure_options = [ - "--enable-shared=no", - "--enable-frame-pointers", - "--disable-libunwind", - ], - lib_source = "@gperftools//:all", - out_static_libs = ["libtcmalloc_and_profiler.a"], -) - -# This currently gives an error: -# "ERROR: <...>/use_malloc/BUILD:17:14: in malloc attribute of cc_test rule //:test: -# configure_make rule '//:gperftools_build' is misplaced here (expected cc_library)" -cc_test( - name = "test", - srcs = ["hello.cpp"], - malloc = ":gperftools_build", -) diff --git a/examples/configure_use_malloc/WORKSPACE b/examples/configure_use_malloc/WORKSPACE deleted file mode 100644 index 87fdfb7a..00000000 --- a/examples/configure_use_malloc/WORKSPACE +++ /dev/null @@ -1,21 +0,0 @@ -workspace(name = "use_malloc_test") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -local_repository( - name = "rules_foreign_cc", - path = "../..", -) - -load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") - -rules_foreign_cc_dependencies() - -all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""" - -http_archive( - name = "gperftools", - build_file_content = all_content, - strip_prefix = "gperftools-2.7", - urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz"], -) diff --git a/examples/third_party/BUILD.bazel b/examples/third_party/BUILD.bazel index c16dbc97..5d48036e 100644 --- a/examples/third_party/BUILD.bazel +++ b/examples/third_party/BUILD.bazel @@ -8,6 +8,7 @@ test_suite( "//cares:test_c_ares", "//curl:curl_build_test", "//gn:gn_launch_test", + "//gperftools:test", "//libgit2:libgit2_build_test", "//libpng:test_libpng", "//libssh2:libssh2_build_test", @@ -21,11 +22,12 @@ test_suite( tags = ["manual"], tests = [ # Missing a new enough m4 to build - #"//bison:bison_build_test", + # "//bison:bison_build_test", "//cares:test_c_ares", "//curl:curl_build_test", # Attempts to access git sha during configure of build so fails - #"//gn:gn_launch_test", + # "//gn:gn_launch_test", + "//gperftools:test", "//libgit2:libgit2_build_test", "//libpng:test_libpng", "//libssh2:libssh2_build_test", @@ -41,6 +43,7 @@ test_suite( "//cares:test_c_ares", "//curl:curl_build_test", "//gn:gn_launch_test", + "//gperftools:test", "//iconv:iconv_build_test", "//libgit2:libgit2_build_test", "//libpng:test_libpng", diff --git a/examples/third_party/gperftools/BUILD.bazel b/examples/third_party/gperftools/BUILD.bazel new file mode 100644 index 00000000..5f74b270 --- /dev/null +++ b/examples/third_party/gperftools/BUILD.bazel @@ -0,0 +1,34 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") +# load("@rules_cc//cc:defs.bzl", "cc_test") + +exports_files( + [ + "BUILD.gperftools.bazel", + ], + visibility = ["//visibility:public"], +) + +# TODO(rules_foreign_cc#227) This currently gives an error: +# "ERROR: <...>/use_malloc/BUILD:17:14: in malloc attribute of cc_test rule //:test: +# configure_make rule '@gperftools//:gperftools_build' is misplaced here (expected cc_library)" +# cc_test( +# name = "malloc_test", +# srcs = ["malloc_test.cpp"], +# malloc = "@gperftools//:gperftools_build", +# ) + +build_test( + name = "build_test", + targets = [ + "@gperftools//:gperftools_build", + ], +) + +test_suite( + name = "test", + tests = [ + ":build_test", + # ":malloc_test", + ], + visibility = ["//:__pkg__"], +) diff --git a/examples/third_party/gperftools/BUILD.gperftools.bazel b/examples/third_party/gperftools/BUILD.gperftools.bazel new file mode 100644 index 00000000..2028c94c --- /dev/null +++ b/examples/third_party/gperftools/BUILD.gperftools.bazel @@ -0,0 +1,22 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +configure_make( + name = "gperftools_build", + configure_env_vars = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + configure_options = [ + "--enable-shared=no", + "--enable-frame-pointers", + "--disable-libunwind", + ], + lib_source = ":all_srcs", + out_static_libs = ["libtcmalloc_and_profiler.a"], + visibility = ["//visibility:public"], +) diff --git a/examples/third_party/gperftools/gperftools_repositories.bzl b/examples/third_party/gperftools/gperftools_repositories.bzl new file mode 100644 index 00000000..0ef1592b --- /dev/null +++ b/examples/third_party/gperftools/gperftools_repositories.bzl @@ -0,0 +1,14 @@ +"""A module defining the third party dependency gperftools""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +def gperftools_repositories(): + maybe( + http_archive, + name = "gperftools", + build_file = Label("//gperftools:BUILD.gperftools.bazel"), + sha256 = "1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9", + strip_prefix = "gperftools-2.7", + urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz"], + ) diff --git a/examples/configure_use_malloc/hello.cpp b/examples/third_party/gperftools/malloc_test.cc similarity index 63% rename from examples/configure_use_malloc/hello.cpp rename to examples/third_party/gperftools/malloc_test.cc index 4fc77098..5a0f1ebd 100644 --- a/examples/configure_use_malloc/hello.cpp +++ b/examples/third_party/gperftools/malloc_test.cc @@ -2,5 +2,5 @@ int main(int argc, char* argv[]) { - std::cout << "Hi there!"; -} \ No newline at end of file + std::cout << "Hi there!"; +} diff --git a/examples/third_party/repositories.bzl b/examples/third_party/repositories.bzl index ce70de53..8fc79a1d 100644 --- a/examples/third_party/repositories.bzl +++ b/examples/third_party/repositories.bzl @@ -1,10 +1,12 @@ -# buildifier: disable=module-docstring +"""A centralized module defining all repositories required for third party examples of rules_foreign_cc""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//bison:bison_repositories.bzl", "bison_repositories") load("//cares:cares_repositories.bzl", "cares_repositories") load("//curl:curl_repositories.bzl", "curl_repositories") load("//gn:gn_repositories.bzl", "gn_repositories") +load("//gperftools:gperftools_repositories.bzl", "gperftools_repositories") load("//iconv:iconv_repositories.bzl", "iconv_repositories") load("//libgit2:libgit2_repositories.bzl", "libgit2_repositories") load("//libpng:libpng_repositories.bzl", "libpng_repositories") @@ -20,6 +22,7 @@ def repositories(): cares_repositories() curl_repositories() gn_repositories() + gperftools_repositories() iconv_repositories() libgit2_repositories() libpng_repositories()