Add bindata rule

Test Plan: Created a sample rule and packaged files to a go binary

X-Origin-Diff: phab/D252
GitOrigin-RevId: f80c25518008fded7104fa6945d077a52d928d85
diff --git a/build/bindata/BUILD b/build/bindata/BUILD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build/bindata/BUILD
diff --git a/build/bindata/README.md b/build/bindata/README.md
new file mode 100644
index 0000000..ae93b53
--- /dev/null
+++ b/build/bindata/README.md
@@ -0,0 +1,34 @@
+##Bindata
+
+This rule uses [go-bindata](https://github.com/kevinburke/go-bindata) to package arbitrary go files.
+Please refer to the documentation there on how to use the packaged data.
+
+Generally this rule is very similar to the `bindata` rule in the default go bazel package.
+However this rule also creates an embeddable go library right away.
+
+###How to use
+
+Add the files you want to package to the `srcs` attribute, set the `package` attribute to the 
+go package you want the result to be in and embed the rule into a `go_library`.
+
+####Example: Packaging sql migrations
+
+These rules package all `.sql` files into the target and make it accessible at `importpath` in the package `models`. 
+```
+
+go_library(
+    name = "go_default_library",
+    embed = [
+        ":migrations_pack",
+    ],
+    importpath = "git.monogon.dev/source/nexantic.git/golibs/minijob/generated/sql",
+    visibility = ["//visibility:public"],
+)
+
+bindata(
+    name = "migrations_pack",
+    package = "models",
+    srcs = glob(["*.sql"]),
+)
+
+```
diff --git a/build/bindata/bindata.bzl b/build/bindata/bindata.bzl
new file mode 100644
index 0000000..23293c1
--- /dev/null
+++ b/build/bindata/bindata.bzl
@@ -0,0 +1,73 @@
+#  Copyright 2020 The Monogon Project Authors.
+#
+#  SPDX-License-Identifier: Apache-2.0
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+load("@bazel_gazelle//:deps.bzl", "go_repository")
+load(
+    "@io_bazel_rules_go//go/private:rules/rule.bzl",
+    "go_rule",
+)
+load(
+    "@io_bazel_rules_go//go:def.bzl",
+    "GoLibrary",
+    "go_context",
+    "go_library",
+)
+
+def _bindata_impl(ctx):
+    out = ctx.actions.declare_file("bindata.go")
+
+    arguments = ctx.actions.args()
+    arguments.add_all([
+        "-pkg",
+        ctx.attr.package,
+        "-prefix",
+        ctx.label.package,
+        "-o",
+        out,
+    ])
+    arguments.add_all(ctx.files.srcs)
+
+    ctx.actions.run(
+        inputs = ctx.files.srcs,
+        outputs = [out],
+        executable = ctx.file.bindata,
+        arguments = [arguments],
+    )
+
+    go = go_context(ctx)
+
+    source_files = [out]
+
+    library = go.new_library(
+        go,
+        srcs = source_files,
+    )
+    source = go.library_to_source(go, None, library, False)
+    providers = [library, source]
+    output_groups = {
+        "go_generated_srcs": source_files,
+    }
+
+    return providers + [OutputGroupInfo(**output_groups)]
+
+bindata = go_rule(
+    _bindata_impl,
+    attrs = {
+        "srcs": attr.label_list(mandatory = True, allow_files = True),
+        "package": attr.string(mandatory = True),
+        "bindata": attr.label(allow_single_file = True, default = Label("@com_github_kevinburke_go_bindata//go-bindata")),
+    },
+)