diff --git a/go/private/actions/archive.bzl b/go/private/actions/archive.bzl index 8b17c1926e..cb8731f1c7 100644 --- a/go/private/actions/archive.bzl +++ b/go/private/actions/archive.bzl @@ -144,7 +144,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d is_external_pkg = is_external_pkg, ) else: - cgo_deps = depset() + cgo_deps = [] emit_compilepkg( go, sources = source.srcs, @@ -204,17 +204,12 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d runfiles = source.runfiles, _validation_output = out_nogo_validation, _nogo_diagnostics = out_diagnostics, - _cgo_deps = cgo_deps, + _cgo_deps = depset(cgo_deps), ) x_defs = dict(source.x_defs) for a in direct: x_defs.update(a.x_defs) - # Ensure that the _cgo_export.h of the current target comes first when cgo_exports is iterated - # by prepending it and specifying the order explicitly. This is required as the CcInfo attached - # to the archive only exposes a single header rather than combining all headers. - cgo_exports_direct = [out_cgo_export_h] if out_cgo_export_h else [] - cgo_exports = depset(direct = cgo_exports_direct, transitive = [a.cgo_exports for a in direct], order = "preorder") return GoArchive( source = source, data = data, @@ -222,8 +217,8 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d libs = depset(direct = [out_lib], transitive = [a.libs for a in direct]), transitive = depset([data], transitive = [a.transitive for a in direct]), x_defs = x_defs, - cgo_deps = depset(transitive = [cgo_deps] + [a.cgo_deps for a in direct]), - cgo_exports = cgo_exports, + cgo_deps = depset(cgo_deps, transitive = [a.cgo_deps for a in direct]), + cgo_export = out_cgo_export_h, runfiles = runfiles, _headers = headers, ) diff --git a/go/private/rules/binary.bzl b/go/private/rules/binary.bzl index 0ec4b26c4a..eb21282910 100644 --- a/go/private/rules/binary.bzl +++ b/go/private/rules/binary.bzl @@ -49,8 +49,6 @@ load( "non_go_transition", ) -_EMPTY_DEPSET = depset([]) - def _include_path(hdr): if not hdr.root.path: fail("Expected hdr to be a generated file, got source file: " + hdr.path) @@ -66,9 +64,10 @@ def _include_path(hdr): def new_cc_import( go, - hdrs = _EMPTY_DEPSET, - defines = _EMPTY_DEPSET, - local_defines = _EMPTY_DEPSET, + headers = None, + includes = None, + defines = None, + local_defines = None, dynamic_library = None, static_library = None, alwayslink = False, @@ -77,8 +76,8 @@ def new_cc_import( compilation_context = cc_common.create_compilation_context( defines = defines, local_defines = local_defines, - headers = hdrs, - includes = depset([_include_path(hdr) for hdr in hdrs.to_list()]), + headers = headers, + includes = includes, ), linking_context = cc_common.create_linking_context( linker_inputs = depset([ @@ -137,9 +136,7 @@ def _go_binary_impl(ctx): importable = False, is_main = is_main, ) - name = ctx.attr.basename - if not name: - name = ctx.label.name + name = ctx.attr.basename or ctx.label.name executable = None if ctx.attr.out: # Use declare_file instead of attr.output(). When users set output files @@ -161,7 +158,7 @@ def _go_binary_impl(ctx): providers = [ archive, OutputGroupInfo( - cgo_exports = archive.cgo_exports, + cgo_exports = [archive.cgo_export] if archive.cgo_export else [], compilation_outputs = [archive.data.file], nogo_fix = [nogo_diagnostics] if nogo_diagnostics else [], _validation = [validation_output] if validation_output else [], @@ -202,14 +199,14 @@ def _go_binary_impl(ctx): "windows": ["-mthreads"], }.get(go.mode.goos, ["-pthread"]), } - cgo_exports = archive.cgo_exports.to_list() - if cgo_exports: + if archive.cgo_export: header = ctx.actions.declare_file("{}.h".format(name)) ctx.actions.symlink( output = header, - target_file = cgo_exports[0], + target_file = archive.cgo_export, ) - cc_import_kwargs["hdrs"] = depset([header]) + cc_import_kwargs["headers"] = depset([header]) + cc_import_kwargs["includes"] = depset([_include_path(header)]) if go.mode.linkmode == LINKMODE_C_SHARED: cc_import_kwargs["dynamic_library"] = executable elif go.mode.linkmode == LINKMODE_C_ARCHIVE: diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl index f64f313e68..61cfd0a837 100644 --- a/go/private/rules/cgo.bzl +++ b/go/private/rules/cgo.bzl @@ -89,7 +89,7 @@ def cgo_configure(go, srcs, cdeps, cppopts, copts, cxxopts, clinkopts): inputs_direct = [] inputs_transitive = [] - deps_direct = [] + deps = [] lib_opts = [] runfiles = go._ctx.runfiles(collect_data = True) seen_alwayslink_libs = {} @@ -104,7 +104,7 @@ def cgo_configure(go, srcs, cdeps, cppopts, copts, cxxopts, clinkopts): inputs_transitive.append(cc_transitive_headers) cc_libs, cc_link_flags = _cc_libs_and_flags(d) inputs_direct.extend(cc_libs) - deps_direct.extend(cc_libs) + deps.extend(cc_libs) cc_defines = d[CcInfo].compilation_context.defines.to_list() cppopts.extend(["-D" + define for define in cc_defines]) cc_includes = d[CcInfo].compilation_context.includes.to_list() @@ -170,7 +170,6 @@ def cgo_configure(go, srcs, cdeps, cppopts, copts, cxxopts, clinkopts): fail("unknown library has neither cc nor objc providers: %s" % d.label) inputs = depset(direct = inputs_direct, transitive = inputs_transitive) - deps = depset(direct = deps_direct) # HACK: some C/C++ toolchains will ignore libraries (including dynamic libs # specified with -l flags) unless they appear after .o or .a files with diff --git a/go/private/rules/library.bzl b/go/private/rules/library.bzl index 9703ba93e9..d338c83c56 100644 --- a/go/private/rules/library.bzl +++ b/go/private/rules/library.bzl @@ -67,7 +67,7 @@ def _go_library_impl(ctx): extensions = ["go"], ), OutputGroupInfo( - cgo_exports = archive.cgo_exports, + cgo_exports = [archive.cgo_export] if archive.cgo_export else [], compilation_outputs = [archive.data.file], nogo_fix = [nogo_diagnostics] if nogo_diagnostics else [], _validation = [validation_output] if validation_output else [], diff --git a/go/private/rules/test.bzl b/go/private/rules/test.bzl index 46ae669633..ceb92e2e5a 100644 --- a/go/private/rules/test.bzl +++ b/go/private/rules/test.bzl @@ -737,7 +737,6 @@ def _recompile_external_deps(go, external_go_info, internal_archive, library_lab transitive = depset(direct = [arc_data], transitive = [a.transitive for a in deps]), x_defs = go_info.x_defs, cgo_deps = depset(transitive = [arc_data._cgo_deps] + [a.cgo_deps for a in deps]), - cgo_exports = depset(transitive = [a.cgo_exports for a in deps]), runfiles = go_info.runfiles, mode = go.mode, _headers = internal_archive._headers, diff --git a/go/providers.rst b/go/providers.rst index 633c571cb2..435858af71 100644 --- a/go/providers.rst +++ b/go/providers.rst @@ -285,9 +285,9 @@ which is available through the :param:`data` field. | The direct cgo dependencies of this library. | | This has the same constraints as things that can appear in the deps of a cc_library_. | +--------------------------------+-----------------------------------------------------------------+ -| :param:`cgo_exports` | :type:`depset of GoInfo` | +| :param:`cgo_export` | :type:`File` | +--------------------------------+-----------------------------------------------------------------+ -| The transitive set of c headers needed to reference exports of this archive. | +| The c headers needed to reference exports of this archive. | +--------------------------------+-----------------------------------------------------------------+ | :param:`runfiles` | runfiles_ | +--------------------------------+-----------------------------------------------------------------+