blob: a10b5433275ebc5300e53c7f62b266a04644ea20 [file] [log] [blame]
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +01001# Copyright 2020 The Monogon Project Authors.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010017load(
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010018 "@io_bazel_rules_go//go:def.bzl",
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010019 "go_context",
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010020)
21
22def _bindata_impl(ctx):
23 out = ctx.actions.declare_file("bindata.go")
24
25 arguments = ctx.actions.args()
26 arguments.add_all([
27 "-pkg",
28 ctx.attr.package,
29 "-prefix",
Lorenz Brunf8574872020-07-28 17:12:04 +020030 ctx.label.workspace_root,
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010031 "-o",
32 out,
33 ])
34 arguments.add_all(ctx.files.srcs)
35
36 ctx.actions.run(
37 inputs = ctx.files.srcs,
38 outputs = [out],
39 executable = ctx.file.bindata,
40 arguments = [arguments],
41 )
42
43 go = go_context(ctx)
44
45 source_files = [out]
46
47 library = go.new_library(
48 go,
49 srcs = source_files,
50 )
51 source = go.library_to_source(go, None, library, False)
52 providers = [library, source]
53 output_groups = {
54 "go_generated_srcs": source_files,
55 }
56
57 return providers + [OutputGroupInfo(**output_groups)]
58
Serge Bazanskif12bedf2021-01-15 16:58:50 +010059bindata = rule(
60 implementation = _bindata_impl,
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010061 attrs = {
Serge Bazanskif12bedf2021-01-15 16:58:50 +010062 "srcs": attr.label_list(
63 mandatory = True,
64 allow_files = True,
Tim Windelschmidt156248b2025-01-10 00:27:45 +010065 ),
Serge Bazanskif12bedf2021-01-15 16:58:50 +010066 "package": attr.string(
67 mandatory = True,
Tim Windelschmidt156248b2025-01-10 00:27:45 +010068 ),
Serge Bazanskif12bedf2021-01-15 16:58:50 +010069 "bindata": attr.label(
70 allow_single_file = True,
71 default = Label("@com_github_kevinburke_go_bindata//go-bindata"),
72 ),
73 "_go_context_data": attr.label(
74 default = "@io_bazel_rules_go//:go_context_data",
75 ),
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010076 },
Serge Bazanskif12bedf2021-01-15 16:58:50 +010077 toolchains = ["@io_bazel_rules_go//go:toolchain"],
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010078)