cc_common.compile without `srcs` leads to empty archives being created by cc_common.create_linking_context_from_compilation_outputs
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
The scenario is:
I'm using a cc_common.compile with cc_common.create_linking_context_from_compilation_outputs() to compile sources and create a linking context from it.
The `srcs` list passed to cc_common.compile is empty:
https://bazel.build/versions/6.1.0/rules/lib/cc_common#compile
With bazel 5.x (tested with 5.4.0):
The create_linking_context_from_compilation_outputs creates a `linking_context` containing 1 `LinkerInput` that has 0 Libraries.
```Starlark
print(tut[CcInfo].linking_context)
print(tut[CcInfo].linking_context.linker_inputs.to_list()[0])
print(tut[CcInfo].linking_context.linker_inputs.to_list()[0].libraries)
```
Yields:
```
DEBUG: /home/user/cc_compiler_error/compile.bzl:93:10: , ])>
DEBUG: /home/user/cc_compiler_error/compile.bzl:94:10:
DEBUG: /home/user/cc_compiler_error/compile.bzl:95:10: []
```
However with bazel 6.x (tested with 6.1.1):
It contains generated libraries:
```
DEBUG: /home/user/cc_compiler_error/compile.bzl:93:10: ]bazel-out/k8-fastbuild/bin]libno_files.a, dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]_solib_k8/liblibno_Ufiles.so, resolved_symlink_dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]libno_files.so, alwayslink=false)>, ], userLinkFlags=[], nonCodeInputs=[])>, ])>
DEBUG: /home/user/cc_compiler_error/compile.bzl:94:10: ]bazel-out/k8-fastbuild/bin]libno_files.a, dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]_solib_k8/liblibno_Ufiles.so, resolved_symlink_dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]libno_files.so, alwayslink=false)>, ], userLinkFlags=[], nonCodeInputs=[])>
DEBUG: /home/user/cc_compiler_error/compile.bzl:95:10: []
# The library
DEBUG: /home/user/cc_compiler_error/compile.bzl:99:14: ]bazel-out/k8-fastbuild/bin]libno_files.a, dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]_solib_k8/liblibno_Ufiles.so, resolved_symlink_dynamic_library=File:[[]bazel-out/k8-fastbuild/bin]libno_files.so, alwayslink=false)>
```
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I created a reproduction scenario as a analysistest here: https://github.com/FaBrand/cc_common_compile:
```
USE_BAZEL_VERSION=5.4.0 bazel test //... # Succeeds
USE_BAZEL_VERSION=6.1.1 bazel test //... # Fails
```
### Which operating system are you running Bazel on?
Linux WSL
### What is the output of `bazel info release`?
release 6.1.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?
```text
https://github.com/FaBrand/cc_common_compile.git
48e520a4449855b149a9c3fe3147414d0e9f85a5
48e520a4449855b149a9c3fe3147414d0e9f85a5
```
### Have you found anything relevant by searching the web?
Not really :/
I checked the examples https://github.com/bazelbuild/rules_cc/tree/main/examples but cc_common.compile is not used there in conjunction with `create_linking_context_from_compilation_outputs`
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.