summary refs log tree commit diff
path: root/pkgs/os-specific/linux/chromium-os/vm_protos
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/linux/chromium-os/vm_protos')
-rw-r--r--pkgs/os-specific/linux/chromium-os/vm_protos/0003-common-mk-add-goproto_library-source_relative-opt.patch48
-rw-r--r--pkgs/os-specific/linux/chromium-os/vm_protos/0004-vm_tools-proto-set-go_package-correctly.patch102
-rw-r--r--pkgs/os-specific/linux/chromium-os/vm_protos/default.nix5
3 files changed, 155 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/chromium-os/vm_protos/0003-common-mk-add-goproto_library-source_relative-opt.patch b/pkgs/os-specific/linux/chromium-os/vm_protos/0003-common-mk-add-goproto_library-source_relative-opt.patch
new file mode 100644
index 00000000000..e921abd8032
--- /dev/null
+++ b/pkgs/os-specific/linux/chromium-os/vm_protos/0003-common-mk-add-goproto_library-source_relative-opt.patch
@@ -0,0 +1,48 @@
+From 211eea8e623c9e9beb61f38720c718f080bae883 Mon Sep 17 00:00:00 2001
+From: Alyssa Ross <hi@alyssa.is>
+Date: Mon, 28 Jun 2021 17:10:46 +0000
+Subject: [PATCH 3/6] common-mk: add goproto_library source_relative opt
+
+We need this for the go_package changes in protoc-gen-go 1.5.x.  If we
+didn't use source-relative paths, the full module path would be
+repeated in the output location, so we'd get paths like
+src/chromiumos/vm_tools/vm_crash/chromiumos/vm_tools/vm_crash/vm_crash.pb.go.
+
+To avoid the duplication, we either need to set source_relative, or
+set proto_out_dir to just go/src.  The latter isn't workable, because
+then everything two libraries that both use common.proto will both
+generate outputs called "go/src/common.pb.go", which will upset GN.
+
+Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
+---
+ common-mk/proto_library.gni | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/common-mk/proto_library.gni b/common-mk/proto_library.gni
+index fb9fb4231d..23645a134f 100644
+--- a/common-mk/proto_library.gni
++++ b/common-mk/proto_library.gni
+@@ -225,6 +225,9 @@ template("proto_library") {
+ #   proto_lib_dirs (optional)
+ #       Directories to search for protos a proto file depends on.
+ #       proto_in_dir and "${sysroot}/usr/share/proto" are added by default.
++#   source_relative (optional)
++#       If true, the output file is placed in the same relative directory as the
++#       input file (but under proto_out_dir).
+ template("goproto_library") {
+   action(target_name) {
+     forward_variables_from(invoker,
+@@ -254,6 +257,10 @@ template("goproto_library") {
+ 
+     go_plugin_parameters = []
+ 
++    if (defined(invoker.source_relative) && invoker.source_relative) {
++      go_plugin_parameters += [ "paths=source_relative" ]
++    }
++
+     if (defined(invoker.gen_grpc) && invoker.gen_grpc) {
+       go_plugin_parameters += [ "plugins=grpc" ]
+     }
+-- 
+2.32.0
+
diff --git a/pkgs/os-specific/linux/chromium-os/vm_protos/0004-vm_tools-proto-set-go_package-correctly.patch b/pkgs/os-specific/linux/chromium-os/vm_protos/0004-vm_tools-proto-set-go_package-correctly.patch
new file mode 100644
index 00000000000..d77bcf2bdef
--- /dev/null
+++ b/pkgs/os-specific/linux/chromium-os/vm_protos/0004-vm_tools-proto-set-go_package-correctly.patch
@@ -0,0 +1,102 @@
+From fae12c5b06864c0a9687320735c9bed9219c30c8 Mon Sep 17 00:00:00 2001
+From: Alyssa Ross <hi@alyssa.is>
+Date: Wed, 16 Jun 2021 16:09:01 +0000
+Subject: [PATCH 4/6] vm_tools: proto: set go_package correctly
+
+protoc-gen-go 1.5.x has become a lot stricter about this.  We have to
+use import_mapping for common.proto because it ends up being included
+in multiple Go libraries.  I'm not sure why it needs to be built once
+per library, but that's the way it works.
+
+Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
+---
+ vm_tools/proto/BUILD.gn       | 5 +++++
+ vm_tools/proto/tremplin.proto | 2 +-
+ vm_tools/proto/vm_crash.proto | 2 +-
+ vm_tools/proto/vm_guest.proto | 1 +
+ vm_tools/proto/vm_host.proto  | 1 +
+ 5 files changed, 9 insertions(+), 2 deletions(-)
+
+diff --git a/vm_tools/proto/BUILD.gn b/vm_tools/proto/BUILD.gn
+index 79c9b94c9f..aadc40165c 100644
+--- a/vm_tools/proto/BUILD.gn
++++ b/vm_tools/proto/BUILD.gn
+@@ -60,6 +60,8 @@ goproto_library("vm-crash-gorpcs") {
+   proto_in_dir = "./"
+   proto_out_dir = "go/src/chromiumos/vm_tools/vm_crash"
+   gen_grpc = true
++  source_relative = true
++  import_mapping = [ "common.proto=chromiumos/vm_tools/vm_crash" ]
+   sources = [
+     "${proto_in_dir}/common.proto",
+     "${proto_in_dir}/vm_crash.proto",
+@@ -97,6 +99,7 @@ goproto_library("tremplin-gorpcs") {
+   proto_in_dir = "./"
+   proto_out_dir = "go/src/chromiumos/vm_tools/tremplin_proto"
+   gen_grpc = true
++  source_relative = true
+   sources = [ "${proto_in_dir}/tremplin.proto" ]
+ }
+ 
+@@ -120,6 +123,8 @@ goproto_library("vm-gorpcs") {
+   proto_in_dir = "./"
+   proto_out_dir = "go/src/chromiumos/vm_tools/vm_rpc"
+   gen_grpc = true
++  source_relative = true
++  import_mapping = [ "common.proto=chromiumos/vm_tools/vm_rpc" ]
+   sources = [
+     "${proto_in_dir}/common.proto",
+     "${proto_in_dir}/vm_guest.proto",
+diff --git a/vm_tools/proto/tremplin.proto b/vm_tools/proto/tremplin.proto
+index aac76f7a9e..e6a7bbed0e 100644
+--- a/vm_tools/proto/tremplin.proto
++++ b/vm_tools/proto/tremplin.proto
+@@ -8,7 +8,7 @@ option cc_enable_arenas = true;
+ 
+ // This file defines services for tremplin, the container springboard service.
+ package vm_tools.tremplin;
+-option go_package = "tremplin_proto";
++option go_package = "chromiumos/vm_tools/tremplin_proto";
+ 
+ // This needs to be duplicated because the gyp rule for building
+ // go code makes it difficult to have imports.
+diff --git a/vm_tools/proto/vm_crash.proto b/vm_tools/proto/vm_crash.proto
+index 6e4f62fe13..3cd4279989 100644
+--- a/vm_tools/proto/vm_crash.proto
++++ b/vm_tools/proto/vm_crash.proto
+@@ -7,7 +7,7 @@ syntax = "proto3";
+ option cc_enable_arenas = true;
+ 
+ package vm_tools.cicerone;
+-option go_package = "vm_crash";
++option go_package = "chromiumos/vm_tools/vm_crash";
+ 
+ import "common.proto";
+ 
+diff --git a/vm_tools/proto/vm_guest.proto b/vm_tools/proto/vm_guest.proto
+index 86f11d0812..d0946078d5 100644
+--- a/vm_tools/proto/vm_guest.proto
++++ b/vm_tools/proto/vm_guest.proto
+@@ -8,6 +8,7 @@ option cc_enable_arenas = true;
+ 
+ // This file defines services that will be running in the guest VM.
+ package vm_tools;
++option go_package = "chromiumos/vm_tools/vm_rpc";
+ 
+ import "common.proto";
+ import "google/protobuf/timestamp.proto";
+diff --git a/vm_tools/proto/vm_host.proto b/vm_tools/proto/vm_host.proto
+index a8bd066f61..19759b0271 100644
+--- a/vm_tools/proto/vm_host.proto
++++ b/vm_tools/proto/vm_host.proto
+@@ -8,6 +8,7 @@ option cc_enable_arenas = true;
+ 
+ // This file defines services that will be running on the host for the VM.
+ package vm_tools;
++option go_package = "chromiumos/vm_tools/vm_rpc";
+ 
+ import "common.proto";
+ 
+-- 
+2.32.0
+
diff --git a/pkgs/os-specific/linux/chromium-os/vm_protos/default.nix b/pkgs/os-specific/linux/chromium-os/vm_protos/default.nix
index e87d0c57e78..cded9c988b3 100644
--- a/pkgs/os-specific/linux/chromium-os/vm_protos/default.nix
+++ b/pkgs/os-specific/linux/chromium-os/vm_protos/default.nix
@@ -7,6 +7,11 @@ common-mk {
   nativeBuildInputs = [ go-protobuf ];
   buildInputs = [ grpc openssl protobuf ];
 
+  platform2Patches = [
+    ./0003-common-mk-add-goproto_library-source_relative-opt.patch
+    ./0004-vm_tools-proto-set-go_package-correctly.patch
+  ];
+
   NIX_CFLAGS_COMPILE = [
     "-Wno-error=array-bounds"
     "-Wno-error=deprecated-declarations"