Skip to content

Commit e8938f0

Browse files
committed
Add regression test for cdeps propagation through embed chains
This test verifies that cdeps are properly propagated when a go_library with cdeps embeds another go_library with cgo=True, and a go_test embeds the library with cdeps. This pattern was broken in v0.51.0 and fixed in commit a494a68. The test reuses existing native_dep cc_library to minimize test complexity and follows the same pattern as the external reproducer.
1 parent a494a68 commit e8938f0

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

tests/core/cgo/BUILD.bazel

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ cc_library(
507507
hdrs = ["native_dep.h"],
508508
# Force static linking to ensure that the build doesn't succeed by
509509
# accidentally picking up the shared library in the search path.
510+
alwayslink = True,
510511
linkstatic = True,
511512
)
512513

@@ -556,3 +557,27 @@ go_bazel_test(
556557
"//conditions:default": ["@platforms//:incompatible"],
557558
}),
558559
)
560+
561+
# Regression test for cdeps propagation through embed chains.
562+
# Tests that when a go_library with cdeps embeds another go_library with cgo=True,
563+
# and a go_test embeds the library with cdeps, the cdeps are properly propagated.
564+
# This was broken in rules_go v0.51.0+ and fixed in this commit.
565+
go_library(
566+
name = "cdeps_embed_base",
567+
srcs = ["cdeps_embed_base.go"],
568+
cgo = True,
569+
importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/cdeps_embed",
570+
)
571+
572+
go_library(
573+
name = "cdeps_embed_with_cdeps",
574+
cdeps = [":native_dep"],
575+
embed = [":cdeps_embed_base"],
576+
importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/cdeps_embed",
577+
)
578+
579+
go_test(
580+
name = "cdeps_embed_test",
581+
srcs = ["cdeps_embed_test.go"],
582+
embed = [":cdeps_embed_with_cdeps"],
583+
)

tests/core/cgo/cdeps_embed_base.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cdeps_embed
2+
3+
/*
4+
#include "tests/core/cgo/native_dep.h"
5+
*/
6+
import "C"
7+
8+
// CallNativeGreeting calls the C function from native_dep
9+
func CallNativeGreeting() {
10+
C.native_greeting()
11+
}

tests/core/cgo/cdeps_embed_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cdeps_embed
2+
3+
import "testing"
4+
5+
// TestCdepsEmbedPropagation tests that cdeps are properly propagated
6+
// when a go_library with cdeps embeds another go_library with cgo=True,
7+
// and a go_test embeds the library with cdeps.
8+
//
9+
// This is a regression test for the issue where cdeps were not being
10+
// propagated through embed chains in rules_go v0.51.0+.
11+
func TestCdepsEmbedPropagation(t *testing.T) {
12+
// If cdeps are properly propagated, this will link successfully
13+
// and call the C function from native_dep.
14+
CallNativeGreeting()
15+
}

0 commit comments

Comments
 (0)