about summary refs log tree commit diff
path: root/nix/buildTypedGo/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-06-18T01·29+0100
committerVincent Ambo <mail@tazj.in>2020-06-18T01·29+0100
commite1e1764e323e220c800d3ab1d43da12745a9b86b (patch)
treecec059fdf21dd16a84993e985282ef5e3a4443d7 /nix/buildTypedGo/default.nix
parent22821b886bdb161fa6222caa3a77d3e3872a0640 (diff)
feat(nix/buildTypedGo): Add a //nix/buildGo wrapper for typed Go r/1017
These functions work like buildGo.program & buildGo.package, but run
the .go2 sources through go2go first before passing them to the
//nix/buildGo equivalents.

Change-Id: Id1ebab6085c390d6986387370181377b9f5d39e8
Diffstat (limited to 'nix/buildTypedGo/default.nix')
-rw-r--r--nix/buildTypedGo/default.nix33
1 files changed, 33 insertions, 0 deletions
diff --git a/nix/buildTypedGo/default.nix b/nix/buildTypedGo/default.nix
new file mode 100644
index 000000000000..1c443484920f
--- /dev/null
+++ b/nix/buildTypedGo/default.nix
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: Apache-2.0
+#
+# A crude wrapper around //nix/buildGo that supports the Go 2 alpha.
+#
+# The way the alpha is implemented is via a transpiler from typed to
+# untyped Go.
+{ depot, pkgs, ... }:
+
+let
+  inherit (builtins)
+    stringLength
+    substring;
+
+  inherit (depot.nix.buildGo) gpackage program;
+
+  go2goext = file: substring 0 ((stringLength file) - 1) file;
+  go2go = file: pkgs.runCommandNoCC "${go2goext (toString file)}" {} ''
+    cp ${file} .
+    ${pkgs.go}/bin/go tool go2go translate *.go2
+    mv *.go $out
+  '';
+
+in rec {
+  program = { name, srcs, deps ? [], x_defs ? {} }: depot.nix.buildGo.program {
+    inherit name deps x_defs;
+    srcs = map go2go srcs;
+  };
+
+  package = { name, srcs, deps ? [], x_defs ? {}, sfiles ? [] }: depot.nix.buildGo.package {
+    inherit name deps x_defs sfiles;
+    srcs = map go2go srcs;
+  };
+}