4949 "non_go_transition" ,
5050)
5151
52- _EMPTY_DEPSET = depset ([])
53-
5452def _include_path (hdr ):
5553 if not hdr .root .path :
5654 fail ("Expected hdr to be a generated file, got source file: " + hdr .path )
@@ -66,9 +64,10 @@ def _include_path(hdr):
6664
6765def new_cc_import (
6866 go ,
69- hdrs = _EMPTY_DEPSET ,
70- defines = _EMPTY_DEPSET ,
71- local_defines = _EMPTY_DEPSET ,
67+ headers = None ,
68+ includes = None ,
69+ defines = None ,
70+ local_defines = None ,
7271 dynamic_library = None ,
7372 static_library = None ,
7473 alwayslink = False ,
@@ -77,8 +76,8 @@ def new_cc_import(
7776 compilation_context = cc_common .create_compilation_context (
7877 defines = defines ,
7978 local_defines = local_defines ,
80- headers = hdrs ,
81- includes = depset ([ _include_path ( hdr ) for hdr in hdrs . to_list ()]) ,
79+ headers = headers ,
80+ includes = includes ,
8281 ),
8382 linking_context = cc_common .create_linking_context (
8483 linker_inputs = depset ([
@@ -137,9 +136,7 @@ def _go_binary_impl(ctx):
137136 importable = False ,
138137 is_main = is_main ,
139138 )
140- name = ctx .attr .basename
141- if not name :
142- name = ctx .label .name
139+ name = ctx .attr .basename or ctx .label .name
143140 executable = None
144141 if ctx .attr .out :
145142 # Use declare_file instead of attr.output(). When users set output files
@@ -161,7 +158,7 @@ def _go_binary_impl(ctx):
161158 providers = [
162159 archive ,
163160 OutputGroupInfo (
164- cgo_exports = archive .cgo_exports ,
161+ cgo_exports = [ archive .cgo_export ] if archive . cgo_export else [] ,
165162 compilation_outputs = [archive .data .file ],
166163 nogo_fix = [nogo_diagnostics ] if nogo_diagnostics else [],
167164 _validation = [validation_output ] if validation_output else [],
@@ -202,14 +199,14 @@ def _go_binary_impl(ctx):
202199 "windows" : ["-mthreads" ],
203200 }.get (go .mode .goos , ["-pthread" ]),
204201 }
205- cgo_exports = archive .cgo_exports .to_list ()
206- if cgo_exports :
202+ if archive .cgo_export :
207203 header = ctx .actions .declare_file ("{}.h" .format (name ))
208204 ctx .actions .symlink (
209205 output = header ,
210- target_file = cgo_exports [ 0 ] ,
206+ target_file = archive . cgo_export ,
211207 )
212- cc_import_kwargs ["hdrs" ] = depset ([header ])
208+ cc_import_kwargs ["headers" ] = depset ([header ])
209+ cc_import_kwargs ["includes" ] = depset ([_include_path (header )])
213210 if go .mode .linkmode == LINKMODE_C_SHARED :
214211 cc_import_kwargs ["dynamic_library" ] = executable
215212 elif go .mode .linkmode == LINKMODE_C_ARCHIVE :
0 commit comments