about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-17T10·53+0100
committerflokli <flokli@flokli.de>2023-10-17T19·51+0000
commite38733a955f6f6fc8962cf0e669d9cf4696bc14d (patch)
tree52dd4e750ab54870d782add53527f29fe5c2e3d2
parent0325ae3ba328ac7b4215057d2c00ac467dd9d820 (diff)
chore(tvix): move castore golang bindings to tvix/castore-go r/6843
Have `tvix/castore/protos` only contain the protos, no go noise.

Make the `.pb.go` file generation a pure Nix build
at `//tvix/castore/protos:go-bindings`, and have a script at
`//tvix:castore-go-generate` (TBD) that copies the results to
`tvix/castore-go`.

`//tvix:castore-go`, with sources in `tvix/castore-go` now contains the
tooling around the generated bindings, and the generated bindings
themselves (So go mod replace workflows still work).

An additional CI step is added from there to ensure idempotenty of
the .pb.go files.

The code.tvl.fyi webserver config is updated to the new source code
path. I'm still unsure if we want to also update the go.mod name. While
being a backwards-incompatible change, it'll probbaly make it easier
where to find these files, and the amount of external consumers is still
low enough.

Part of b/323.

Change-Id: I2edadd118c22ec08e57c693f6cc2ef3261c62489
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9787
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
-rw-r--r--nix/bufCheck/default.nix1
-rw-r--r--ops/modules/www/code.tvl.fyi.nix2
-rw-r--r--tvix/castore-go/LICENSE21
-rw-r--r--tvix/castore-go/README.md10
-rw-r--r--tvix/castore-go/castore.go (renamed from tvix/castore/protos/castore.go)0
-rw-r--r--tvix/castore-go/castore.pb.go (renamed from tvix/castore/protos/castore.pb.go)0
-rw-r--r--tvix/castore-go/castore_test.go (renamed from tvix/castore/protos/castore_test.go)0
-rw-r--r--tvix/castore-go/default.nix25
-rw-r--r--tvix/castore-go/go.mod (renamed from tvix/castore/protos/go.mod)0
-rw-r--r--tvix/castore-go/go.sum (renamed from tvix/castore/protos/go.sum)0
-rw-r--r--tvix/castore-go/rename_node.go (renamed from tvix/castore/protos/rename_node.go)0
-rw-r--r--tvix/castore-go/rpc_blobstore.pb.go (renamed from tvix/castore/protos/rpc_blobstore.pb.go)0
-rw-r--r--tvix/castore-go/rpc_blobstore_grpc.pb.go (renamed from tvix/castore/protos/rpc_blobstore_grpc.pb.go)0
-rw-r--r--tvix/castore-go/rpc_directory.pb.go (renamed from tvix/castore/protos/rpc_directory.pb.go)0
-rw-r--r--tvix/castore-go/rpc_directory_grpc.pb.go (renamed from tvix/castore/protos/rpc_directory_grpc.pb.go)0
-rw-r--r--tvix/castore/protos/default.nix33
-rw-r--r--tvix/default.nix11
17 files changed, 94 insertions, 9 deletions
diff --git a/nix/bufCheck/default.nix b/nix/bufCheck/default.nix
index 3a64513304..f247e6839e 100644
--- a/nix/bufCheck/default.nix
+++ b/nix/bufCheck/default.nix
@@ -7,7 +7,6 @@ pkgs.writeShellScriptBin "ci-buf-check" ''
   (cd $(git rev-parse --show-toplevel) && buf lint .)
 
   # Run buf generate, and bail out if generated files are changed.
-  (cd $(git rev-parse --show-toplevel) && buf generate --path tvix/castore/protos)
   (cd $(git rev-parse --show-toplevel) && buf generate --path tvix/store/protos)
   # Check if any files have changed
   if [[ -n "$(git status --porcelain -unormal)" ]]; then
diff --git a/ops/modules/www/code.tvl.fyi.nix b/ops/modules/www/code.tvl.fyi.nix
index 8d8938bcae..6a7e4b2503 100644
--- a/ops/modules/www/code.tvl.fyi.nix
+++ b/ops/modules/www/code.tvl.fyi.nix
@@ -21,7 +21,7 @@
         }
 
         location = /go-get/tvix/castore/protos {
-            alias ${pkgs.writeText "go-import-metadata.html" ''<html><meta name="go-import" content="code.tvl.fyi/tvix/castore/protos git https://code.tvl.fyi/depot.git:/tvix/castore/protos.git"></html>''};
+            alias ${pkgs.writeText "go-import-metadata.html" ''<html><meta name="go-import" content="code.tvl.fyi/tvix/castore/protos git https://code.tvl.fyi/depot.git:/tvix/castore-go.git"></html>''};
         }
 
         location = /go-get/tvix/store/protos {
diff --git a/tvix/castore-go/LICENSE b/tvix/castore-go/LICENSE
new file mode 100644
index 0000000000..2034ada6fd
--- /dev/null
+++ b/tvix/castore-go/LICENSE
@@ -0,0 +1,21 @@
+Copyright © The Tvix Authors
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+“Software”), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/tvix/castore-go/README.md b/tvix/castore-go/README.md
new file mode 100644
index 0000000000..1aee48dfdf
--- /dev/null
+++ b/tvix/castore-go/README.md
@@ -0,0 +1,10 @@
+# castore-go
+
+This directory contains generated golang bindings, both for the `tvix-castore`
+data models, as well as the gRPC bindings.
+
+They are generated with `mg run //tvix:castore-go-generate`.
+These files end with `.pb.go`, and are ensured to be up to date by a CI check.
+
+Additionally, code useful when interacting with these data structures
+(ending just with `.go`) is provided.
diff --git a/tvix/castore/protos/castore.go b/tvix/castore-go/castore.go
index c9e3757885..c9e3757885 100644
--- a/tvix/castore/protos/castore.go
+++ b/tvix/castore-go/castore.go
diff --git a/tvix/castore/protos/castore.pb.go b/tvix/castore-go/castore.pb.go
index 5323d6c923..5323d6c923 100644
--- a/tvix/castore/protos/castore.pb.go
+++ b/tvix/castore-go/castore.pb.go
diff --git a/tvix/castore/protos/castore_test.go b/tvix/castore-go/castore_test.go
index fda87a6cfb..fda87a6cfb 100644
--- a/tvix/castore/protos/castore_test.go
+++ b/tvix/castore-go/castore_test.go
diff --git a/tvix/castore-go/default.nix b/tvix/castore-go/default.nix
new file mode 100644
index 0000000000..09bbb77f81
--- /dev/null
+++ b/tvix/castore-go/default.nix
@@ -0,0 +1,25 @@
+{ depot, pkgs, ... }:
+
+(pkgs.buildGoModule {
+  name = "castore-go";
+  src = depot.third_party.gitignoreSource ./.;
+  vendorHash = "sha256-ZNtSSW+oCxMsBtURSrea9/GyUHDagtGefM+Ii+VkgCA=";
+}).overrideAttrs (_: {
+  meta.ci.extraSteps = {
+    check = {
+      label = ":water_buffalo: ensure generated protobuf files match";
+      needsOutput = true;
+      command = pkgs.writeShellScript "pb-go-check" ''
+        ${depot.tvix.castore-go-generate}
+        if [[ -n "$(git status --porcelain -unormal)" ]]; then
+            echo "-----------------------------"
+            echo ".pb.go files need to be updated, run //tvix:castore-go-generate"
+            echo "-----------------------------"
+            git status -unormal
+            exit 1
+        fi
+      '';
+      alwaysRun = true;
+    };
+  };
+})
diff --git a/tvix/castore/protos/go.mod b/tvix/castore-go/go.mod
index 9048aa205c..9048aa205c 100644
--- a/tvix/castore/protos/go.mod
+++ b/tvix/castore-go/go.mod
diff --git a/tvix/castore/protos/go.sum b/tvix/castore-go/go.sum
index 535b8e32f0..535b8e32f0 100644
--- a/tvix/castore/protos/go.sum
+++ b/tvix/castore-go/go.sum
diff --git a/tvix/castore/protos/rename_node.go b/tvix/castore-go/rename_node.go
index 80537b16d3..80537b16d3 100644
--- a/tvix/castore/protos/rename_node.go
+++ b/tvix/castore-go/rename_node.go
diff --git a/tvix/castore/protos/rpc_blobstore.pb.go b/tvix/castore-go/rpc_blobstore.pb.go
index 1afc826744..1afc826744 100644
--- a/tvix/castore/protos/rpc_blobstore.pb.go
+++ b/tvix/castore-go/rpc_blobstore.pb.go
diff --git a/tvix/castore/protos/rpc_blobstore_grpc.pb.go b/tvix/castore-go/rpc_blobstore_grpc.pb.go
index 0876bcc4e9..0876bcc4e9 100644
--- a/tvix/castore/protos/rpc_blobstore_grpc.pb.go
+++ b/tvix/castore-go/rpc_blobstore_grpc.pb.go
diff --git a/tvix/castore/protos/rpc_directory.pb.go b/tvix/castore-go/rpc_directory.pb.go
index f658c6b60c..f658c6b60c 100644
--- a/tvix/castore/protos/rpc_directory.pb.go
+++ b/tvix/castore-go/rpc_directory.pb.go
diff --git a/tvix/castore/protos/rpc_directory_grpc.pb.go b/tvix/castore-go/rpc_directory_grpc.pb.go
index f19e457d86..f19e457d86 100644
--- a/tvix/castore/protos/rpc_directory_grpc.pb.go
+++ b/tvix/castore-go/rpc_directory_grpc.pb.go
diff --git a/tvix/castore/protos/default.nix b/tvix/castore/protos/default.nix
new file mode 100644
index 0000000000..e2e2f910ee
--- /dev/null
+++ b/tvix/castore/protos/default.nix
@@ -0,0 +1,33 @@
+{ depot, pkgs, ... }: {
+  # Produces the golang bindings.
+  go-bindings = pkgs.stdenv.mkDerivation {
+    name = "go-bindings";
+
+    src = depot.nix.sparseTree {
+      name = "castore-protos";
+      root = depot.path.origSrc;
+      paths = [
+        ./castore.proto
+        ./rpc_blobstore.proto
+        ./rpc_directory.proto
+        ../../../buf.yaml
+        ../../../buf.gen.yaml
+      ];
+    };
+
+    nativeBuildInputs = [
+      pkgs.buf
+      pkgs.protoc-gen-go
+      pkgs.protoc-gen-go-grpc
+    ];
+
+    buildPhase = ''
+      export HOME=$TMPDIR
+      buf lint
+      buf generate
+
+      mkdir -p $out
+      cp tvix/castore/protos/*.pb.go $out/
+    '';
+  };
+}
diff --git a/tvix/default.nix b/tvix/default.nix
index dfb9f41437..3365fe7981 100644
--- a/tvix/default.nix
+++ b/tvix/default.nix
@@ -106,12 +106,10 @@ in
   # workspace too.
   shell = (import ./shell.nix { inherit pkgs; });
 
-  # Builds and tests the code in castore/protos.
-  castore-protos-go = pkgs.buildGoModule {
-    name = "castore-golang";
-    src = depot.third_party.gitignoreSource ./castore/protos;
-    vendorHash = "sha256-ZNtSSW+oCxMsBtURSrea9/GyUHDagtGefM+Ii+VkgCA=";
-  };
+  # Update `.pb.go` files in tvix/castore-go with the generated ones.
+  castore-go-generate = pkgs.writeShellScriptBin "castore-go-protogen" ''
+    (cd $(git rev-parse --show-toplevel)/tvix/castore-go && rm *.pb.go && cp ${depot.tvix.castore.protos.go-bindings}/*.pb.go . && chmod +w *.pb.go)
+  '';
 
   # Builds and tests the code in store/protos.
   store-protos-go = pkgs.buildGoModule {
@@ -146,7 +144,6 @@ in
   };
 
   meta.ci.targets = [
-    "castore-protos-go"
     "store-protos-go"
     "shell"
     "rust-docs"