Skip to content

Commit

Permalink
Delete cgo_library rule from prelude
Browse files Browse the repository at this point in the history
Summary: It's replaced by `go_library`

Reviewed By: echistyakov

Differential Revision: D62980942

fbshipit-source-id: 0e6476fe5092f060d6d14b6434d95e70753791e5
  • Loading branch information
podtserkovskiy authored and facebook-github-bot committed Sep 19, 2024
1 parent e6c9982 commit ea3e99b
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 183 deletions.
2 changes: 0 additions & 2 deletions decls/go_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
"""),
}

Expand Down
68 changes: 1 addition & 67 deletions decls/go_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -176,7 +111,7 @@ go_exported_library = prelude_rule(
deps = [":example"],
)
cgo_library(
go_library(
name = "example",
package_name = "cgo",
srcs = [
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go/cgo_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
91 changes: 0 additions & 91 deletions go/cgo_library.bzl

This file was deleted.

6 changes: 0 additions & 6 deletions go/transitions/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 1 addition & 16 deletions rules_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea3e99b

Please sign in to comment.