Moved `configure_use_malloc` example to third party examples (#634)

This commit is contained in:
UebelAndre 2021-05-21 09:06:59 -07:00 committed by GitHub
parent 4e702ae6ea
commit 6202e299a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 49 deletions

View File

@ -1,2 +1 @@
cmake_crosstool
configure_use_malloc

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,5 +2,5 @@
int main(int argc, char* argv[])
{
std::cout << "Hi there!";
}
std::cout << "Hi there!";
}

View File

@ -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()