Add support for cc_library.always_link#2294
Conversation
Signed-off-by: Steeve Morin <steeve@zen.ly>
| "js": ("", ""), | ||
| }) | ||
|
|
||
| def get_static_lib(lib): |
There was a problem hiding this comment.
Rename to cc_static_lib.
Also, please add a doc comment:
"""cc_static_lib returns a static library to link if one is available.
Args:
lib: a library from CcInfo.linking_context.libraries_to_link.
Returns: either static_library, pic_static_library, interface_library, or None.
"""
| static_lib = get_static_lib(lib) | ||
| if static_lib == None and lib.dynamic_library: | ||
| dylib = lib.dynamic_library | ||
| # If both static and dynamic variants are available, Bazel will only give |
There was a problem hiding this comment.
I think this comment can be deleted.
| # If both static and dynamic variants are available, Bazel will only give | ||
| # us the static variant. We'll get one file for each transitive dependency, | ||
| # so the same file may appear more than once. | ||
| if has_simple_shared_lib_extension(dylib.basename): |
There was a problem hiding this comment.
Don't we still need to check for the lib prefix? We remove it unconditionally below.
| elif has_versioned_shared_lib_extension(dylib.basename): | ||
| # With a versioned shared library, we must use the full filename, | ||
| # otherwise the library will not be found by the linker. | ||
| libname = ":%s" % lib.basename |
There was a problem hiding this comment.
dylib I think, here and on the two lines below.
| for goos in GOOS.keys() | ||
| } | ||
| _WHOLE_ARCHIVE_FLAGS_BY_GOOS.update({ | ||
| "darwin": ("-Wl,-all_load", ""), |
There was a problem hiding this comment.
Is this actually an OS difference or a GCC / clang difference? If it's the latter, we should check the compiler name (unless there's a better way to test for that). I think that might be in go.cgo_tools.c_compiler_path. After all, you can have gcc on macOS and clang on Linux.
|
Error from CI on Linux: |
|
Closing inactive PRs. I think this is superseded by #2584. |
Previously if you pulled multiple wheels of the same dep, even ones not affected by patches would be processed, which is expensive for larger wheels because of the unzipping / re-zipping. Fixes bazel-contrib/rules_python#2263
…hen using alwayslink = True (#4438) <!-- Thanks for sending a PR! Before submitting: 1. If this is your first PR, please read CONTRIBUTING.md and sign the CLA first. We cannot review code without a signed CLA. 2. Please file an issue *first*. All features and most bug fixes should have an associated issue with a design discussed and decided upon. Small bug fixes and documentation improvements don't need issues. 3. New features and bug fixes must have tests. Documentation may need to be updated. If you're unsure what to update, send the PR, and we'll discuss in review. 4. Note that PRs updating dependencies and new Go versions are not accepted. Please file an issue instead. --> **What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** Fixes static linking against libraries that have `alwayslink = True` specified. Fixes C++'s dynamic initialization of static variables when using cgo **Which issues(s) does this PR fix?** Fixes #1486 --- Related to #2584 and #2294
This is a rebased version of #1879.
I couldn't reopen the #1879 since the branch was force pushed.
This is a naive, yet functional approach that's compatible with bazel >= 0.23.