Rule to build a fully static library

See original GitHub issue

Among the multiple “release” outputs of my project, I’d like to include a single static library, which packages the objects of all dependencies into it. However, from what I can tell, bazel cannot build such targets.

The following target produces a single .so containing all symbols from //product/foo and //product/bar.:

cc_binary(
  name = "libproduct.so",
  linkshared = 1,
  deps = [
     "//product/foo",
     "//product/bar",
  ],
)

I believe there is no way to generate a similar static library (libproduct.a). Is that something that will be of interest to add?

(#492 seems somewhat related, but not exactly)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:55
  • Comments:74 (43 by maintainers)

github_iconTop GitHub Comments

14reactions
hlopkocommented, Jul 8, 2019

Work on #5200 has started, we plan to share designs in the Q3 and have it finished in Q4.

Note that it is possible to implement naive rule that will unarchive all transitive static libraries, and rearchive them into one big .a file today. See the example in rules_cc that can be extended to do this https://github.com/bazelbuild/rules_cc/blob/master/examples/my_c_archive/my_c_archive.bzl. So you don’t have to wait for #5200 to be implemented if you don’t need to be able to filter out which deps will make it into the final archive in the same way as cc_shared_library will.

9reactions
lilinxiongcommented, May 14, 2021

So for nearly 5 years, children can run all over the floor, this problem is still not solved. Please allow me to laugh for 5 minutes first. hhhhhhhhhhhh~

Read more comments on GitHub >

github_iconTop Results From Across the Web

1.16. Building a Static Library with GNU Make - O'Reilly
First, create a makefile in the directory where you want your static library to be created, and declare a phony target all whose...
Read more >
Building And Using Static And Shared "C" Libraries
First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either...
Read more >
How can I include an already built static library (.a file) using ...
I am trying to include a small static library using Bazel, but I seem to encounter an error no matter the method I...
Read more >
C / C++ Rules - Bazel
For a C++ library, linkstatic=True indicates that only static linking is allowed, so no .so will be produced. linkstatic=False does not prevent static...
Read more >
Static and Dynamic Libraries | Set 1 - GeeksforGeeks
Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found