Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 50 additions & 117 deletions go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,130 +71,63 @@ def emit_archive(go, source = None):
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))

importmap = "main" if source.library.is_main else source.library.importmap

if not source.cgo_archives:
# TODO(jayconrod): We still need to support the legacy cgo path when
# Objective C sources are present, since the Objective C toolchain
# isn't exposed to Starlark. The legacy path runs cgo as a separate
# action, then builds generated code with cc_library / objc_library.
# A go_library compiles generated Go code and packs the other
# objects from cgo_archives. "cgo_archives" is not supported on
# the new path because we do all that in one action.
importpath, _ = effective_importpath_pkgpath(source.library)

if source.cgo and not go.mode.pure:
# TODO(jayconrod): do we need to do full Bourne tokenization here?
cppopts = [f for fs in source.cppopts for f in fs.split(" ")]
copts = [f for fs in source.copts for f in fs.split(" ")]
cxxopts = [f for fs in source.cxxopts for f in fs.split(" ")]
clinkopts = [f for fs in source.clinkopts for f in fs.split(" ")]

importpath, _ = effective_importpath_pkgpath(source.library)
if source.cgo and not go.mode.pure:
cgo = cgo_configure(
go,
srcs = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cdeps = source.cdeps,
cppopts = cppopts,
copts = copts,
cxxopts = cxxopts,
clinkopts = clinkopts,
)
if go.mode.link in (LINKMODE_C_SHARED, LINKMODE_C_ARCHIVE):
out_cgo_export_h = go.declare_file(go, path = "_cgo_install.h")
cgo_deps = cgo.deps
runfiles = runfiles.merge(cgo.runfiles)
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
out_cgo_export_h = out_cgo_export_h,
gc_goopts = source.gc_goopts,
cgo = True,
cgo_inputs = cgo.inputs,
cppopts = cgo.cppopts,
copts = cgo.copts,
cxxopts = cgo.cxxopts,
objcopts = cgo.objcopts,
objcxxopts = cgo.objcxxopts,
clinkopts = cgo.clinkopts,
cgo_archives = source.cgo_archives,
testfilter = testfilter,
)
else:
cgo_deps = depset()
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
gc_goopts = source.gc_goopts,
cgo = False,
cgo_archives = source.cgo_archives,
testfilter = testfilter,
)
cgo = cgo_configure(
go,
srcs = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cdeps = source.cdeps,
cppopts = cppopts,
copts = copts,
cxxopts = cxxopts,
clinkopts = clinkopts,
)
if go.mode.link in (LINKMODE_C_SHARED, LINKMODE_C_ARCHIVE):
out_cgo_export_h = go.declare_file(go, path = "_cgo_install.h")
cgo_deps = cgo.deps
runfiles = runfiles.merge(cgo.runfiles)
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
out_cgo_export_h = out_cgo_export_h,
gc_goopts = source.gc_goopts,
cgo = True,
cgo_inputs = cgo.inputs,
cppopts = cgo.cppopts,
copts = cgo.copts,
cxxopts = cgo.cxxopts,
objcopts = cgo.objcopts,
objcxxopts = cgo.objcxxopts,
clinkopts = cgo.clinkopts,
testfilter = testfilter,
)
else:
cgo_deps = source.cgo_deps

if bool(go.cover and go.coverdata and source.cover):
source = go.cover(go, source)
direct.append(go.coverdata)

asmhdr = None
if split.asm:
asmhdr = go.declare_file(go, "go_asm.h")

if len(split.asm) == 0 and not source.cgo_archives:
go.compile(
go,
sources = split.go,
importpath = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
gc_goopts = source.gc_goopts,
testfilter = testfilter,
)
else:
# Assembly files must be passed to the compiler as sources. We need
# to run the assembler to produce a symabis file that gets passed to
# the compiler. The compiler builder does all this so it doesn't
# need to be a separate action (but individual .o files are still
# produced with separate actions).
partial_lib = go.declare_file(go, path = lib_name + "~partial", ext = ".a")
go.compile(
go,
sources = split.go + split.asm + split.headers,
importpath = importmap,
archives = direct,
out_lib = partial_lib,
out_export = out_export,
gc_goopts = source.gc_goopts,
testfilter = testfilter,
asmhdr = asmhdr,
)

# include other .s as inputs, since they may be #included.
# This may result in multiple copies of symbols defined in included
# files, but go build allows it, so we do, too.
asm_headers = split.headers + split.asm + [asmhdr]
extra_objects = []
for src in split.asm:
extra_objects.append(go.asm(go, source = src, hdrs = asm_headers))
go.pack(
go,
in_lib = partial_lib,
out_lib = out_lib,
objects = extra_objects,
archives = source.cgo_archives,
)
cgo_deps = depset()
emit_compilepkg(
go,
sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
cover = source.cover,
importpath = importpath,
importmap = importmap,
archives = direct,
out_lib = out_lib,
out_export = out_export,
gc_goopts = source.gc_goopts,
cgo = False,
testfilter = testfilter,
)

data = GoArchiveData(
name = source.library.name,
Expand Down
2 changes: 0 additions & 2 deletions go/private/actions/compilepkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def emit_compilepkg(
objcopts = [],
objcxxopts = [],
clinkopts = [],
cgo_archives = [],
out_lib = None,
out_export = None,
out_cgo_export_h = None,
Expand All @@ -59,7 +58,6 @@ def emit_compilepkg(

inputs = (sources + [go.package_list] +
[archive.data.file for archive in archives] +
cgo_archives +
go.sdk.tools + go.sdk.headers + go.stdlib.libs)
outputs = [out_lib]
env = go.env
Expand Down
43 changes: 0 additions & 43 deletions go/private/compat/v23.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,6 @@ def cc_libs(target):
libs.append(library_to_link.dynamic_library)
return libs

def cc_compile_flags(target):
# Copied from get_compile_flags in migration instructions from
# bazelbuild/bazel#7036.
options = []
compilation_context = target[CcInfo].compilation_context
for define in compilation_context.defines.to_list():
options.append("-D{}".format(define))

for system_include in compilation_context.system_includes.to_list():
if len(system_include) == 0:
system_include = "."
options.append("-isystem {}".format(system_include))

for include in compilation_context.includes.to_list():
if len(include) == 0:
include = "."
options.append("-I {}".format(include))

for quote_include in compilation_context.quote_includes.to_list():
if len(quote_include) == 0:
quote_include = "."
options.append("-iquote {}".format(quote_include))

return options

def cc_toolchain_all_files(ctx):
return ctx.files._cc_toolchain

Expand All @@ -96,27 +71,9 @@ def get_proto(target):
def proto_check_deps_sources(target):
return target[ProtoInfo].check_deps_sources

def proto_direct_descriptor_set(target):
return target[ProtoInfo].direct_descriptor_set

def proto_direct_sources(target):
return target[ProtoInfo].direct_sources

def proto_source_root(target):
return target[ProtoInfo].proto_source_root

def proto_transitive_descriptor_sets(target):
return target[ProtoInfo].transitive_descriptor_sets

def proto_transitive_imports(target):
return target[ProtoInfo].transitive_imports

def proto_transitive_proto_path(target):
return target[ProtoInfo].transitive_proto_path

def proto_transitive_sources(target):
return target[ProtoInfo].transitive_sources

# Compatibility for --incompatible_disallow_struct_provider
def providers_with_coverage(ctx, source_attributes, dependency_attributes, extensions, providers):
return providers + [coverage_common.instrumented_files_info(
Expand Down
43 changes: 0 additions & 43 deletions go/private/compat/v25.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,6 @@ def cc_libs(target):
libs.append(library_to_link.dynamic_library)
return libs

def cc_compile_flags(target):
# Copied from get_compile_flags in migration instructions from
# bazelbuild/bazel#7036.
options = []
compilation_context = target[CcInfo].compilation_context
for define in compilation_context.defines.to_list():
options.append("-D{}".format(define))

for system_include in compilation_context.system_includes.to_list():
if len(system_include) == 0:
system_include = "."
options.append("-isystem {}".format(system_include))

for include in compilation_context.includes.to_list():
if len(include) == 0:
include = "."
options.append("-I {}".format(include))

for quote_include in compilation_context.quote_includes.to_list():
if len(quote_include) == 0:
quote_include = "."
options.append("-iquote {}".format(quote_include))

return options

def cc_toolchain_all_files(ctx):
return find_cpp_toolchain(ctx).all_files.to_list()

Expand All @@ -100,27 +75,9 @@ def get_proto(target):
def proto_check_deps_sources(target):
return target[ProtoInfo].check_deps_sources

def proto_direct_descriptor_set(target):
return target[ProtoInfo].direct_descriptor_set

def proto_direct_sources(target):
return target[ProtoInfo].direct_sources

def proto_source_root(target):
return target[ProtoInfo].proto_source_root

def proto_transitive_descriptor_sets(target):
return target[ProtoInfo].transitive_descriptor_sets

def proto_transitive_imports(target):
return target[ProtoInfo].transitive_imports

def proto_transitive_proto_path(target):
return target[ProtoInfo].transitive_proto_path

def proto_transitive_sources(target):
return target[ProtoInfo].transitive_sources

# Compatibility for --incompatible_disallow_struct_provider
def providers_with_coverage(ctx, source_attributes, dependency_attributes, extensions, providers):
return providers + [coverage_common.instrumented_files_info(
Expand Down
5 changes: 0 additions & 5 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ def _merge_embed(source, embed):
source["clinkopts"] = source["clinkopts"] or s.clinkopts
source["cgo_deps"] = source["cgo_deps"] + s.cgo_deps
source["cgo_exports"] = source["cgo_exports"] + s.cgo_exports
if s.cgo_archives:
if source["cgo_archives"]:
fail("multiple libraries with cgo_archives embedded")
source["cgo_archives"] = s.cgo_archives

def _dedup_deps(deps):
"""Returns a list of targets without duplicate import paths.
Expand Down Expand Up @@ -237,7 +233,6 @@ def _library_to_source(go, attr, library, coverage_instrumented):
"copts": getattr(attr, "copts", []),
"cxxopts": getattr(attr, "cxxopts", []),
"clinkopts": getattr(attr, "clinkopts", []),
"cgo_archives": [],
"cgo_deps": [],
"cgo_exports": [],
}
Expand Down
Loading