diff --git a/internal/builder/gosource.go b/internal/builder/gosource.go index 80d363cb..1b7c7c9c 100644 --- a/internal/builder/gosource.go +++ b/internal/builder/gosource.go @@ -351,6 +351,8 @@ func goFileReads(file string) (imports, embeds []string, err error) { } } } + // A cgo file may include from below its directory: the directory is held whole. + embeds = append(embeds, ".") continue } imports = append(imports, ip) diff --git a/internal/builder/gosource_test.go b/internal/builder/gosource_test.go index 034ed4f9..fd5aa2e6 100644 --- a/internal/builder/gosource_test.go +++ b/internal/builder/gosource_test.go @@ -304,3 +304,15 @@ func TestNativeSourcesHoldTheirDirectoryWhole(t *testing.T) { } } } + +// A cgo file may include from below its directory with nothing native beside it: its directory is held whole. +func TestACgoFileHoldsItsDirectoryWhole(t *testing.T) { + got, err := GoBuildSource(aGoTree(t, map[string]string{"go.mod": "module x\n", + "p/main.go": "package main\n\n// #include \"inc/x.h\"\nimport \"C\"\n", "p/inc/x.h": ""}), "p") + if err != nil { + t.Fatal(err) + } + if !SourceHolds(got, "p/inc/x.h") { + t.Fatalf("a header a cgo preamble includes is not held: %v", got) + } +}