Skip to content

Commit 3d7c05f

Browse files
committed
Address PR feedback
- Collect headers and transitive headers into a depset. - Provide the headers depset to emit_compilepkg - Add a compilation target that includes headers with transitive, relative include paths.
1 parent afb689d commit 3d7c05f

File tree

15 files changed

+51
-21
lines changed

15 files changed

+51
-21
lines changed

go/private/actions/archive.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
8888
importmap = "main" if source.is_main else source.importmap
8989
importpath, _ = effective_importpath_pkgpath(source)
9090

91+
headers = depset(
92+
direct = [f for f in source.srcs if f.path.split(".")[-1].lower().startswith("h")],
93+
transitive = [a.data._headers for a in direct],
94+
)
95+
9196
if source.cgo and not go.mode.pure:
9297
# TODO(jayconrod): do we need to do full Bourne tokenization here?
9398
cppopts = [f for fs in source.cppopts for f in fs.split(" ")]
@@ -115,6 +120,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
115120
importpath = importpath,
116121
importmap = importmap,
117122
archives = direct,
123+
headers = headers,
118124
out_lib = out_lib,
119125
out_export = out_export,
120126
out_facts = out_facts,
@@ -145,6 +151,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
145151
importpath = importpath,
146152
importmap = importmap,
147153
archives = direct,
154+
headers = headers,
148155
out_lib = out_lib,
149156
out_export = out_export,
150157
out_facts = out_facts,
@@ -196,7 +203,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
196203
_validation_output = out_nogo_validation,
197204
_nogo_fix_output = out_nogo_fix,
198205
_cgo_deps = cgo_deps,
199-
_headers = tuple([f for f in source.srcs if f.path.split(".")[-1].lower().startswith("h")]),
206+
_headers = headers,
200207
)
201208
x_defs = dict(source.x_defs)
202209
for a in direct:

go/private/actions/compilepkg.bzl

Lines changed: 4 additions & 5 deletions
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
cppopts = [],
@@ -95,11 +96,9 @@ def emit_compilepkg(
9596
archives = archives + [go.coverdata]
9697

9798
sdk = go.sdk
98-
inputs_direct = sources + embedsrcs + [sdk.package_list]
99-
for archive in archives:
100-
inputs_direct.append(archive.data.export_file)
101-
inputs_direct.extend(archive.data._headers)
102-
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs]
99+
inputs_direct = (sources + embedsrcs + [sdk.package_list] +
100+
[archive.data.export_file for archive in archives])
101+
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs, headers]
103102
outputs = [out_lib, out_export]
104103

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

tests/core/go_library/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ go_library(
2828
srcs = [
2929
"inc.go",
3030
"inc_asmhdr.s",
31-
"inc_relative.s",
3231
],
3332
importpath = "asm_header",
34-
deps = ["//tests/core/headers"],
3533
)
3634

3735
go_library(

tests/core/go_library/inc_relative.s

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/core/headers/BUILD.bazel

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/core/headers/hdr.go

Lines changed: 0 additions & 1 deletion
This file was deleted.
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+
)

0 commit comments

Comments
 (0)