Bazel go library: Difference between revisions
Jump to navigation
Jump to search
(→srcs) |
Tag: Manual revert |
||
(7 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
This builds a Go library from a set of source files that are all part of the same package. | This builds a Go library from a set of source files that are all part of the same package. | ||
=Example= | |||
<syntaxhighlight lang='go'> | |||
load("//meta/rules:go.bzl", "go_library") | |||
go_library( | |||
name = "somepkg", | |||
srcs = [ | |||
"file1.go", | |||
"file2.go", | |||
], | |||
importpath = "github.com/someorg/somemodule/pkg/somepkg", | |||
visibility = ["//visibility:public"], # private if this is a library that becomes part of an executable | |||
deps = [ | |||
"//lib/a", | |||
"//lib/b", | |||
... | |||
"@com_github_blang_semver//:semver", | |||
], | |||
) | |||
</syntaxhighlight> | |||
=Attributes= | =Attributes= | ||
==<tt>name</tt>== | ==<tt>name</tt>== | ||
Line 13: | Line 34: | ||
==<tt>deps</tt>== | ==<tt>deps</tt>== | ||
Optional. List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the GoLibrary provider. | Optional. List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the GoLibrary provider. | ||
==<tt>importpath</tt>== | |||
The source import path of this library. Other libraries can import this library using this path. This must either be specified in <code>go_library</code> or inherited from one of the libraries in <code>embed</code>. | |||
==<tt>visibility</tt>== |
Latest revision as of 03:37, 23 July 2024
External
Internal
Overview
This builds a Go library from a set of source files that are all part of the same package.
Example
load("//meta/rules:go.bzl", "go_library")
go_library(
name = "somepkg",
srcs = [
"file1.go",
"file2.go",
],
importpath = "github.com/someorg/somemodule/pkg/somepkg",
visibility = ["//visibility:public"], # private if this is a library that becomes part of an executable
deps = [
"//lib/a",
"//lib/b",
...
"@com_github_blang_semver//:semver",
],
)
Attributes
name
Required, a unique name for this target.
srcs
Optional. The list of Go source files that are compiled to create the package. Only .go
and .s
files are permitted, unless the cgo
attribute is set.
deps
Optional. List of Go libraries this package imports directly. These may be go_library rules or compatible rules with the GoLibrary provider.
importpath
The source import path of this library. Other libraries can import this library using this path. This must either be specified in go_library
or inherited from one of the libraries in embed
.