diff --git a/decls/go_common.bzl b/decls/go_common.bzl index 9cacf6ca2..4c26077dc 100644 --- a/decls/go_common.bzl +++ b/decls/go_common.bzl @@ -91,8 +91,6 @@ def _external_linker_flags_arg(): return { "external_linker_flags": attrs.list(attrs.arg(), default = [], doc = """ Extra external linker flags passed to go link via `-extld` argument. - If argument is non-empty or `cgo_library` is used, the link mode - will switch to `external`. """), } diff --git a/decls/go_rules.bzl b/decls/go_rules.bzl index 6d9f65564..d9827077a 100644 --- a/decls/go_rules.bzl +++ b/decls/go_rules.bzl @@ -13,77 +13,12 @@ load(":common.bzl", "buck", "prelude_rule") load(":cxx_common.bzl", "cxx_common") load(":go_common.bzl", "go_common") -load(":native_common.bzl", "native_common") load(":re_test_common.bzl", "re_test_common") BuildMode = ["executable", "c_shared", "c_archive"] GoTestCoverStepMode = ["set", "count", "atomic", "none"] -cgo_library = prelude_rule( - name = "cgo_library", - docs = """ - A cgo\\_library() rule builds an object from the supplied set of Go/C source files and - dependencies. The outputs are linked into go executable in the last step (compile). - - The 'go build' command would collect the cgo directives from the source files, however - with buck the flags needs to be passed in the cgo\\_library manually - - This rule borrows from `cxx_binary()` since C/C++ sources are being compiled. - """, - examples = """ - ``` - - # A rule that builds a Go native executable with linked cgo library based on - # C/C++ util library. - go_binary( - name = "bin", - srcs = ["main.go"], - deps = [":lib"] - ) - - cgo_library( - name = "lib", - srcs = ["cgo_source.go"], - deps = [":util"], - ) - - cxx_library( - name = "util", - srcs = ["util.c"], - headers = ["util.h"], - ) - - ``` - """, - further = None, - attrs = ( - # @unsorted-dict-items - go_common.package_name_arg() | - go_common.srcs_arg() | - go_common.embedcfg_arg() | - go_common.package_root_arg() | - cxx_common.headers_arg() | - cxx_common.header_namespace_arg() | - go_common.cxx_preprocessor_flags_arg() | - go_common.cxx_compiler_flags_arg() | - native_common.link_style() | - go_common.compiler_flags_arg() | - go_common.assembler_flags_arg() | - go_common.generate_exported_header() | - { - "contacts": attrs.list(attrs.string(), default = []), - "default_host_platform": attrs.option(attrs.configuration_label(), default = None), - "default_platform": attrs.option(attrs.string(), default = None), - "deps": attrs.list(attrs.dep(), default = []), - "exported_deps": attrs.list(attrs.dep(), default = []), - "labels": attrs.list(attrs.string(), default = []), - "licenses": attrs.list(attrs.source(), default = []), - } | - buck.allow_cache_upload_arg() - ), -) - go_binary = prelude_rule( name = "go_binary", docs = """ @@ -176,7 +111,7 @@ go_exported_library = prelude_rule( deps = [":example"], ) - cgo_library( + go_library( name = "example", package_name = "cgo", srcs = [ @@ -431,7 +366,6 @@ go_bootstrap_binary = prelude_rule( ) go_rules = struct( - cgo_library = cgo_library, go_binary = go_binary, go_bootstrap_binary = go_bootstrap_binary, go_exported_library = go_exported_library, diff --git a/go/cgo_builder.bzl b/go/cgo_builder.bzl index 84e4660f6..6619da057 100644 --- a/go/cgo_builder.bzl +++ b/go/cgo_builder.bzl @@ -163,7 +163,7 @@ def build_cgo(ctx: AnalysisContext, cgo_files: list[Artifact], h_files: list[Art c_compile_cmds = cxx_compile_srcs( ctx, CxxRuleConstructorParams( - rule_type = "cgo_library", + rule_type = "cgo_sources", headers_layout = cxx_get_regular_cxx_headers_layout(ctx), srcs = [CxxSrcWithFlags(file = src) for src in c_files + c_gen_srcs], compiler_flags = c_flags + ctx.attrs.cxx_compiler_flags, diff --git a/go/cgo_library.bzl b/go/cgo_library.bzl deleted file mode 100644 index 1afdc2033..000000000 --- a/go/cgo_library.bzl +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under both the MIT license found in the -# LICENSE-MIT file in the root directory of this source tree and the Apache -# License, Version 2.0 found in the LICENSE-APACHE file in the root directory -# of this source tree. - -load( - "@prelude//cxx:preprocessor.bzl", - "cxx_inherited_preprocessor_infos", - "cxx_merge_cpreprocessors", -) -load( - "@prelude//linking:link_groups.bzl", - "merge_link_group_lib_info", -) -load( - "@prelude//linking:link_info.bzl", - "MergedLinkInfo", - "create_merged_link_info_for_propagation", -) -load( - "@prelude//linking:linkable_graph.bzl", - "create_linkable_graph", -) -load( - "@prelude//linking:shared_libraries.bzl", - "SharedLibraryInfo", - "merge_shared_libraries", -) -load( - "@prelude//utils:utils.bzl", - "map_idx", -) -load(":compile.bzl", "GoPkgCompileInfo", "get_inherited_compile_pkgs") -load(":coverage.bzl", "GoCoverageMode") -load(":link.bzl", "GoPkgLinkInfo", "get_inherited_link_pkgs") -load(":package_builder.bzl", "build_package") -load(":packages.bzl", "cgo_exported_preprocessor", "go_attr_pkg_name", "merge_pkgs") - -def cgo_library_impl(ctx: AnalysisContext) -> list[Provider]: - pkg_name = go_attr_pkg_name(ctx) - - race = ctx.attrs._race - asan = ctx.attrs._asan - coverage_mode = GoCoverageMode(ctx.attrs._coverage_mode) if ctx.attrs._coverage_mode else None - - # Build Go library. - compiled_pkg, pkg_info = build_package( - ctx, - pkg_name, - ctx.attrs.srcs + ctx.attrs.headers, - package_root = ctx.attrs.package_root, - deps = ctx.attrs.deps + ctx.attrs.exported_deps, - tags = ctx.attrs._tags, - race = race, - asan = asan, - coverage_mode = coverage_mode, - embedcfg = ctx.attrs.embedcfg, - cgo_enabled = True, - ) - - pkgs = { - pkg_name: compiled_pkg, - } - - own_exported_preprocessors = [cgo_exported_preprocessor(ctx, pkg_info)] if ctx.attrs.generate_exported_header else [] - - return [ - DefaultInfo(default_output = compiled_pkg.pkg), - GoPkgCompileInfo(pkgs = merge_pkgs([ - pkgs, - get_inherited_compile_pkgs(ctx.attrs.exported_deps), - ])), - GoPkgLinkInfo(pkgs = merge_pkgs([ - pkgs, - get_inherited_link_pkgs(ctx.attrs.deps + ctx.attrs.exported_deps), - ])), - create_merged_link_info_for_propagation(ctx, filter(None, [d.get(MergedLinkInfo) for d in ctx.attrs.deps])), - merge_shared_libraries( - ctx.actions, - deps = filter(None, map_idx(SharedLibraryInfo, ctx.attrs.deps)), - ), - merge_link_group_lib_info(deps = ctx.attrs.deps), - create_linkable_graph( - ctx, - deps = ctx.attrs.deps, - ), - cxx_merge_cpreprocessors(ctx, own_exported_preprocessors, cxx_inherited_preprocessor_infos(ctx.attrs.deps)), - pkg_info, - ] diff --git a/go/transitions/defs.bzl b/go/transitions/defs.bzl index bfcd5c56d..639a4efe9 100644 --- a/go/transitions/defs.bzl +++ b/go/transitions/defs.bzl @@ -233,12 +233,6 @@ go_library_transition = transition( attrs = [], ) -cgo_library_transition = transition( - impl = _chain_transitions(_all_level_tansitions), - refs = _all_level_refs, - attrs = [], -) - go_stdlib_transition = transition( impl = _chain_transitions(_all_level_tansitions), refs = _all_level_refs, diff --git a/rules_impl.bzl b/rules_impl.bzl index d81ab5589..66501a1c9 100644 --- a/rules_impl.bzl +++ b/rules_impl.bzl @@ -20,14 +20,13 @@ load("@prelude//cxx:prebuilt_cxx_library_group.bzl", "prebuilt_cxx_library_group load("@prelude//cxx:windows_resource.bzl", "windows_resource_impl") load("@prelude//erlang:erlang.bzl", _erlang_implemented_rules = "implemented_rules") load("@prelude//git:git_fetch.bzl", "git_fetch_impl") -load("@prelude//go:cgo_library.bzl", "cgo_library_impl") load("@prelude//go:coverage.bzl", "GoCoverageMode") load("@prelude//go:go_binary.bzl", "go_binary_impl") load("@prelude//go:go_exported_library.bzl", "go_exported_library_impl") load("@prelude//go:go_library.bzl", "go_library_impl") load("@prelude//go:go_stdlib.bzl", "go_stdlib_impl") load("@prelude//go:go_test.bzl", "go_test_impl") -load("@prelude//go/transitions:defs.bzl", "asan_attr", "cgo_enabled_attr", "cgo_library_transition", "coverage_mode_attr", "go_binary_transition", "go_exported_library_transition", "go_library_transition", "go_stdlib_transition", "go_test_transition", "race_attr", "tags_attr") +load("@prelude//go/transitions:defs.bzl", "asan_attr", "cgo_enabled_attr", "coverage_mode_attr", "go_binary_transition", "go_exported_library_transition", "go_library_transition", "go_stdlib_transition", "go_test_transition", "race_attr", "tags_attr") load("@prelude//go_bootstrap:go_bootstrap.bzl", "go_bootstrap_binary_impl") load("@prelude//haskell:haskell.bzl", "haskell_binary_impl", "haskell_library_impl", "haskell_prebuilt_library_impl") load("@prelude//haskell:haskell_ghci.bzl", "haskell_ghci_impl") @@ -173,7 +172,6 @@ extra_implemented_rules = struct( git_fetch = git_fetch_impl, #go - cgo_library = cgo_library_impl, go_binary = go_binary_impl, go_bootstrap_binary = go_bootstrap_binary_impl, go_exported_library = go_exported_library_impl, @@ -401,18 +399,6 @@ def _create_manifest_for_source_dir(): inlined_extra_attributes = { - # go - "cgo_library": { - "embedcfg": attrs.option(attrs.source(allow_directory = False), default = None), - "_asan": asan_attr, - "_coverage_mode": coverage_mode_attr, - "_cxx_toolchain": toolchains_common.cxx(), - "_exec_os_type": buck.exec_os_type_arg(), - "_go_stdlib": attrs.default_only(attrs.dep(default = "prelude//go/tools:stdlib")), - "_go_toolchain": toolchains_common.go(), - "_race": race_attr, - "_tags": tags_attr, - }, # csharp "csharp_library": { "_csharp_toolchain": toolchains_common.csharp(), @@ -697,7 +683,6 @@ transitions = { "apple_library": target_sdk_version_transition, "apple_resource": apple_resource_transition, "apple_test": target_sdk_version_transition, - "cgo_library": cgo_library_transition, "cxx_binary": constraint_overrides_transition, "cxx_test": constraint_overrides_transition, "go_binary": go_binary_transition,