build/toolbase/gotoolchain: init

Another piece of the toolbase puzzle, this one is a library which
provides information about the Go SDK picked by Bazel/rules_go, and
allows to build tools that call the `go` tool.

This is effectively the logic from //build/fietsje:def.bzl, but
rewritten to be reusable. In a later CL, we will make Fietsje use this
logic instead of its existing starlark/shell magic.

Change-Id: I2be723089410c81843b54df77bcd665a4e050cbb
Reviewed-on: https://review.monogon.dev/c/monogon/+/329
Reviewed-by: Mateusz Zalega <mateusz@monogon.tech>
diff --git a/build/toolbase/gotoolchain/toolchain.go.in b/build/toolbase/gotoolchain/toolchain.go.in
new file mode 100644
index 0000000..ca3db65
--- /dev/null
+++ b/build/toolbase/gotoolchain/toolchain.go.in
@@ -0,0 +1,24 @@
+// gotoolchain provides information about the Go toolchain used on the host by
+// rules_go.
+package gotoolchain
+
+import (
+	"fmt"
+
+	"github.com/bazelbuild/rules_go/go/tools/bazel"
+)
+
+func mustRunfile(s string) string {
+	res, err := bazel.Runfile(s)
+	if err != nil {
+		panic(fmt.Sprintf("runfile %q not found: %v", s, err))
+	}
+	return res
+}
+
+var (
+	// Go is a path to the `go` executable.
+	Go = mustRunfile(`GOTOOL`)
+	// Root is the GOROOT path.
+	Root = mustRunfile(`GOROOT`)
+)