Skip to content

Commit a494a68

Browse files
committed
When a go_library embeds another go_library that has cdeps but not
cgo=True (because it itself embeds a library with cgo=True), the cdeps were not being propagated. This is a regression from v0.51.0. In v0.50.1, cdeps and related cgo options were merged unconditionally: source["cdeps"] = source["cdeps"] or s.cdeps In v0.51.0 (PR #4030), the logic was changed to only merge these when s.cgo is True: if s.cgo: source["cdeps"] = s.cdeps This breaks the pattern where: - Library A has cgo=True and C code - Library B embeds A, adds cdeps, but doesn't set cgo=True - Test embeds B The cdeps from B don't propagate to the test because B doesn't have cgo=True, causing undefined symbol errors during linking. This fix restores the v0.50.1 behavior: merge cgo-related attributes if the embedded library has them, regardless of the cgo flag.
1 parent 1be32b0 commit a494a68

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

go/private/context.bzl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,17 @@ def _merge_embed(source, embed):
225225
if source["cgo"]:
226226
fail("multiple libraries with cgo enabled")
227227
source["cgo"] = s.cgo
228-
source["cdeps"] = s.cdeps
229-
source["cppopts"] = s.cppopts
230-
source["copts"] = s.copts
231-
source["cxxopts"] = s.cxxopts
232-
source["clinkopts"] = s.clinkopts
228+
229+
# Merge cgo-related attributes if the embedded library has them,
230+
# even if it doesn't have cgo=True itself. This is necessary because
231+
# a library can have cdeps without cgo=True if it embeds another library
232+
# that has cgo=True. The cdeps must propagate through the embed chain.
233+
if s.cdeps or s.cppopts or s.copts or s.cxxopts or s.clinkopts:
234+
source["cdeps"] = source["cdeps"] or s.cdeps
235+
source["cppopts"] = source["cppopts"] or s.cppopts
236+
source["copts"] = source["copts"] or s.copts
237+
source["cxxopts"] = source["cxxopts"] or s.cxxopts
238+
source["clinkopts"] = source["clinkopts"] or s.clinkopts
233239

234240
def _dedup_archives(archives):
235241
"""Returns a list of archives without duplicate import paths.

0 commit comments

Comments
 (0)