Skip to content

Commit 8823cbb

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 8823cbb

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

tests/core/cgo/BUILD.bazel

Lines changed: 28 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,30 @@ 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 = [
568+
"cdeps_embed_base.go",
569+
"cdeps_embed.h",
570+
],
571+
cgo = True,
572+
importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/cdeps_embed",
573+
)
574+
575+
go_library(
576+
name = "cdeps_embed_with_cdeps",
577+
cdeps = [":native_dep"],
578+
embed = [":cdeps_embed_base"],
579+
importpath = "github.com/bazelbuild/rules_go/tests/core/cgo/cdeps_embed",
580+
)
581+
582+
go_test(
583+
name = "cdeps_embed_test",
584+
srcs = ["cdeps_embed_test.go"],
585+
embed = [":cdeps_embed_with_cdeps"],
586+
)

tests/core/cgo/cdeps_embed.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef CDEPS_EMBED_H
2+
#define CDEPS_EMBED_H
3+
4+
void native_greeting(void);
5+
6+
#endif

tests/core/cgo/cdeps_embed_base.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cdeps_embed
2+
3+
// #include "cdeps_embed.h"
4+
import "C"
5+
6+
func CallNative() {
7+
C.native_greeting()
8+
}

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+
CallNative()
15+
}

0 commit comments

Comments
 (0)