Skip to content

Commit 393faea

Browse files
Pass headers along as transitive dependencies (#4298)
This fixes github.com/cloudflare/circl relative imports by making those headers available at compile time. **What type of PR is this?** Feature **What does this PR do? Why is it needed?** Expose headers in GoArchive so that compilepkg can make them visible. This will make it possible for relative imports to find header files. **Which issues(s) does this PR fix?** Fixes #4154 **Other notes for review**
1 parent 11c6145 commit 393faea

File tree

12 files changed

+50
-1
lines changed

12 files changed

+50
-1
lines changed

go/private/actions/archive.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
8787
importpath, _ = effective_importpath_pkgpath(source)
8888

8989
cgo_out_dir = None
90+
headers = depset(
91+
direct = [f for f in source.srcs if f.path.split(".")[-1].lower().startswith("h")],
92+
transitive = [a._headers for a in direct],
93+
)
94+
9095
if source.cgo and not go.mode.pure:
9196
cgo_out_dir = go.declare_directory(go, path = out_lib.basename + ".cgo")
9297

@@ -116,6 +121,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
116121
importpath = importpath,
117122
importmap = importmap,
118123
archives = direct,
124+
headers = headers,
119125
out_lib = out_lib,
120126
out_export = out_export,
121127
out_facts = out_facts,
@@ -146,6 +152,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
146152
importpath = importpath,
147153
importmap = importmap,
148154
archives = direct,
155+
headers = headers,
149156
out_lib = out_lib,
150157
out_export = out_export,
151158
out_facts = out_facts,
@@ -217,4 +224,5 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
217224
cgo_deps = depset(transitive = [cgo_deps] + [a.cgo_deps for a in direct]),
218225
cgo_exports = cgo_exports,
219226
runfiles = runfiles,
227+
_headers = headers,
220228
)

go/private/actions/compilepkg.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def emit_compilepkg(
5757
importpath = "",
5858
importmap = "",
5959
archives = [],
60+
headers = depset(),
6061
cgo = False,
6162
cgo_inputs = depset(),
6263
cgo_out_dir = None,
@@ -95,7 +96,7 @@ def emit_compilepkg(
9596
sdk = go.sdk
9697
inputs_direct = (sources + embedsrcs + [sdk.package_list] +
9798
[archive.data.export_file for archive in archives])
98-
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs]
99+
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs, headers]
99100
outputs = [out_lib, out_export]
100101

101102
shared_args = go.builder_args(go, use_path_mapping = True)

go/private/rules/test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ def _recompile_external_deps(go, external_go_info, internal_archive, library_lab
732732
cgo_exports = depset(transitive = [a.cgo_exports for a in deps]),
733733
runfiles = go_info.runfiles,
734734
mode = go.mode,
735+
_headers = internal_archive._headers,
735736
)
736737
label_to_archive[label] = archive
737738

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "a",
5+
srcs = [
6+
"a.go",
7+
"a.s",
8+
],
9+
deps = ["//tests/core/transitive_headers/b"],
10+
importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/a",
11+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../b/b.h"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "b",
5+
srcs = [
6+
"b.go",
7+
"b.h",
8+
],
9+
deps = ["//tests/core/transitive_headers/c"],
10+
importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/b",
11+
visibility = ["//visibility:public"],
12+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../c/c.h"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "c",
5+
srcs = [
6+
"c.go",
7+
"c.h",
8+
],
9+
importpath = "github.com/bazelbuild/rules_go/tests/core/transitive_headers/c",
10+
visibility = ["//visibility:public"],
11+
)

0 commit comments

Comments
 (0)