Skip to content

Commit

Permalink
Add labels field to cgo_library target. (#268)
Browse files Browse the repository at this point in the history
* Propagate labels on go_repo rule

* Modify string concatenation to use list and join

* Rename extraLabels -> labels

* Fix list join

* Rename arg --labels -> --label

* Add quotes around build labels

* Bump please_go version

* Undo changes to go_repo rule

* Update change log

* Add labels argument to cgo_library

* Actually use labels...

---------

Co-authored-by: mspraggs <mspraggs@thoughtmachine.net>
  • Loading branch information
mspraggs and mspraggs authored Jul 23, 2024
1 parent 3d0a207 commit a0bf796
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
31 changes: 26 additions & 5 deletions build_defs/cgo.build_defs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
subinclude("///go//build_defs:go", "///cc//build_defs:c")

def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_srcs:list=[], hdrs:list=[],
package:str=None, compiler_flags:list&cflags=[], linker_flags:list&ldflags=[], pkg_config:list=[],
subdir:str='', deps:list=[], visibility:list=None, test_only:bool&testonly=False, import_path:str='',
_module:str='', _subrepo:str=''):
def cgo_library(
name:str,
srcs:list=[],
resources:list=None,
go_srcs:list=[],
c_srcs:list=[],
hdrs:list=[],
package:str=None,
compiler_flags:list&cflags=[],
linker_flags:list&ldflags=[],
pkg_config:list=[],
subdir:str='',
deps:list=[],
labels:list=[],
visibility:list=None,
test_only:bool&testonly=False,
import_path:str='',
_module:str='',
_subrepo:str='',
):
"""Generates a Go library which can be reused by other rules.

Note that by its nature this is something of a hybrid of Go and C rules. It can depend
Expand Down Expand Up @@ -32,6 +48,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
deps (list): Dependencies. Note that if you intend to depend on cc_library rules,
you will likely be better off wrapping them into a cc_static_library
and depending on that.
labels (list): Labels for this rule.
visibility (list): Visibility specification
test_only (bool): If True, is only visible to test rules.
import_path (str): If set, this will override the import path of the generated go package.
Expand All @@ -48,6 +65,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
resources = resources,
package = package,
deps = deps,
labels = labels,
import_path = import_path,
visibility = visibility,
test_only = test_only,
Expand Down Expand Up @@ -107,6 +125,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
pkg_config_libs = pkg_config,
test_only = test_only,
deps = deps,
labels = labels,
)
go_rule = go_library(
name = f'_{name}#go',
Expand All @@ -119,6 +138,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
import_path=import_path,
_subrepo = _subrepo,
_module = _module,
labels = labels,
)

output = package if package else name
Expand All @@ -129,6 +149,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
outs = [f'{output}.importconfig'],
visibility=visibility,
test_only=test_only,
labels = labels,
)

# And finally combine the compiled C code into the Go archive object so go tool link can find it later.
Expand All @@ -140,7 +161,7 @@ def cgo_library(name:str, srcs:list=[], resources:list=None, go_srcs:list=[], c_
test_only = test_only,
linker_flags = linker_flags,
package = package,
labels = ['link:plz-out/go/pkg/%s_%s' % (CONFIG.OS, CONFIG.ARCH)],
labels = ['link:plz-out/go/pkg/%s_%s' % (CONFIG.OS, CONFIG.ARCH)] + labels,
provides = {
'go': ':' + name,
'go_src': go_rule,
Expand Down
1 change: 1 addition & 0 deletions build_defs/go.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def go_library(name:str, srcs:list, resources:list=[], asm_srcs:list=None, hdrs:
code that you never want to be instrumented.
filter_srcs (bool): If True, filters source files through Go's standard build constraints.
import_path (str): If set, this will override the import path of the generated go package.
labels (list): Labels for this rule.
package (str): The package as it would appear at the top of the go source files. Defaults
to name.
pgo_file (str): The CPU profile to supply for profile-guided optimisation.
Expand Down

0 comments on commit a0bf796

Please sign in to comment.