bazelbuild / bazelbuild/bazel

cc_shared_library does not compile and link linkstamp sources

Open
#21,724 2 comments 0 reactions 0 assignees View on GitHub
not stale P3 team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

A cc_shared_library target doesn't compile the sources specified in linkstamp.

### Which category does this issue belong to?

_No response_

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

BUILD:
```
cc_library(
name = "version",
srcs = ["version.cxx"],
linkstamp = "version_linkstamp.cxx",
alwayslink = 1,
)

cc_shared_library(
name = "test",
deps = [":version"],
)
```

`bazel aquery -s --stamp --noenable_bzlmod //:test`

gives:
```
action 'SolibSymlink _solib_k8/_U/libtest.so'
Mnemonic: SolibSymlink
Target: //:test
Configuration: k8-fastbuild
Execution platform: @local_config_platform//:host
ActionKey: dea27c87bf681bed1845147d29145302f10c43a4d839c75d56887803254c7d59
Inputs: [bazel-out/k8-fastbuild/bin/libtest.so]
Outputs: [bazel-out/k8-fastbuild/bin/_solib_k8/_U/libtest.so]

action 'Writing file libtest.so-2.params'
Mnemonic: FileWrite
Target: //:test
Configuration: k8-fastbuild
Execution platform: @local_config_platform//:host
ActionKey: 13f1694227a557cc705feae875a03db9fc92221b21255217196fc083908ca313
Inputs: []
Outputs: [bazel-out/k8-fastbuild/bin/libtest.so-2.params]

action 'Linking libtest.so'
Mnemonic: CppLink
Target: //:test
Configuration: k8-fastbuild
Execution platform: @local_config_platform//:host
ActionKey: 0013ef3f2498529f58e54504110c5e396aad4caa69d9239ab44fa7d15347ec21
Inputs: [bazel-out/k8-fastbuild/bin/_objs/version/version.pic.o, bazel-out/k8-fastbuild/bin/libtest.so-2.params, external/bazel_tools/tools/cpp/build_interface_so, external/bazel_tools/tools/cpp/link_dynamic_library.sh, external/local_config_cc/builtin_include_directory_paths]
Outputs: [bazel-out/k8-fastbuild/bin/libtest.so]
Command Line: (exec /usr/bin/gcc \
-shared \
-o \
bazel-out/k8-fastbuild/bin/libtest.so \
-Wl,-S \
'-fuse-ld=gold' \
-B/usr/bin \
-Wl,-no-as-needed \
-Wl,-z,relro,-z,now \
-pass-exit-codes \
bazel-out/k8-fastbuild/bin/_objs/version/version.pic.o \
-Wl,--push-state,-as-needed \
-lstdc++ \
-Wl,--pop-state \
-Wl,--push-state,-as-needed \
-lm \
-Wl,--pop-state)
# Configuration: a303d5046449e9530d714fc2c7dc28fdb07b7a8e6efa4dfa99bd28400c123431
# Execution platform: @@local_config_platform//:host
```

### Which operating system are you running Bazel on?

Ubuntu 22.04

### What is the output of `bazel info release`?

release 7.1.0

### 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 HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied BUILD targets and `bazel aquery -s --stamp --noenable_bzlmod //:test`; inspect the generated C++ compile and link actions for `cc_shared_library`. Done means the `linkstamp` source is compiled and included when linking the shared library.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.