Skip to content

Commit 3fc9406

Browse files
committed
Add cc_static_library for non-bazel projects
Bazel 7.4.x+ have a new `cc_static_library` rule that creates a redistributable static library from a set of deps. This allows us to create a standalone version of tcmalloc that users can easily pull into non-bazel projects. This should lower the friction for cmake users to use tcmalloc.
1 parent b826880 commit 3fc9406

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/quickstart.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,26 @@ build --cxxopt='-std=c++17'
254254

255255
Congratulations! You've created your first binary using TCMalloc.
256256

257+
### Using TCMalloc in non-Bazel Projects
258+
259+
If you are not using Bazel, you can instead build a standalone version
260+
of TCMalloc that you can vendor in your project. Before doing so you
261+
should still run the tests, as described above, to make sure the
262+
vendored library will work in your environment. Then build the
263+
standalone bazel target:
264+
265+
```
266+
tcmalloc$ bazel build tcmalloc:tcmalloc_standalone --experimental_cc_static_library
267+
```
268+
269+
Once this builds you can copy the resulting static library from
270+
`bazel-bin/tcmalloc/libtcmalloc_standalone.a` into your project!
271+
272+
Note that if you have dependencies in your project that are also
273+
included in TCMalloc, it is up to you to ensure the versions are
274+
compatible in order to avoid symbol conflicts (which may or may not be
275+
hard errors at link time).
276+
257277
## What's Next
258278

259279
* Read our [overview](overview.md), if you haven't already. The overview

tcmalloc/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ cc_library(
111111
alwayslink = 1,
112112
)
113113

114+
cc_static_library(
115+
name = "tcmalloc_standalone",
116+
deps = [":tcmalloc"],
117+
tags = ["manual"],
118+
)
119+
114120
cc_library(
115121
name = "tcmalloc_internal_methods_only",
116122
srcs = [

0 commit comments

Comments
 (0)