From 107b12d7762b4998fb6f72ac60197536f4f2e520 Mon Sep 17 00:00:00 2001 From: Lee Avital Date: Thu, 29 Aug 2024 15:32:18 -0400 Subject: [PATCH] Download all dependencies (protoc, gogo) Adds a `rake setup_gogo` task which will clone gogo into a new toolchains directory (which is git ignored). On every run of codegen, we'll checkout a pinned version of gogo and rebuild it. This should be pretty fast as long as gogo is already checked out. This PR also adds a new 'toolchains' location where all dependencies are cached. Before we were jumbling a bunch of dependencies into /tmp. This led to a weird case where we were accidentally (?) using a new protobuf compiler with a legacy .proto library (for stuff like google.Duration). This is now explicit. The structure of the new toolchains is described in the Rakefile --- .gitignore | 6 ++- Rakefile | 143 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 104 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 6d888f88..a94ba100 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,8 @@ # jetbrains IDE directory /.idea/ -vendor/ \ No newline at end of file +vendor/ + +# build time dependencies that are either downloaded or +# built during codegen +toolchains/ diff --git a/Rakefile b/Rakefile index 829bc440..ac648755 100644 --- a/Rakefile +++ b/Rakefile @@ -1,25 +1,71 @@ -# # Rakefile for agent-payload -# + +# where all toolchains (protobuf compilers, protobuf plugins,etc) are stored +toolchain_dir=File.join(File.dirname(__FILE__), "toolchains") + +# binaries +toolchain_bin_dir=File.join(toolchain_dir, "bin") + +# include path for the legacy and main protobuf compilers respectively +toolchain_include_dir=File.join(toolchain_dir, "include", "proto") +toolchain_legacy_include_dir=File.join(toolchain_dir, "include", "proto_legacy") # we use an older version of protoc for logs and metrics protoc_legacy_version="3.5.1" -protoc_legacy_binary="/tmp/protoc#{protoc_legacy_version}" +protoc_legacy_binary=File.join(toolchain_bin_dir, "protoc" + protoc_legacy_version) protoc_version="21.12" -protoc_binary="/tmp/protoc#{protoc_version}" +protoc_binary=File.join(toolchain_bin_dir, "protoc" + protoc_version) -gogo_dir="/tmp/gogo" -protoc_gen_go_dir="/tmp/protoc-gen-go" +gogo_tag = "v1.3.2" +gogo_dir=File.join(toolchain_dir, "gogo") +gogo_include = "#{toolchain_dir}/gogo/src:#{toolchain_dir}/gogo/src/github.com/gogo/protobuf/protobuf" +gogo_bin = File.join(toolchain_bin_dir, "gogo-bin-#{gogo_tag}") protoc_jsonschema_version="73d5723" +### toolchains is meant to store a cache of all binary dependencies needed to build the agent-payload. +### this rakefile will download those dependencies on the fly if needed. +### the structure of toolchains is as follows: +### /toolchains +### /toolchains/bin -- contains any binaries used for building +### /toolchains/bin/protoc21.12 -- the new protobuf compiler +### /toolchains/bin/protoc3.5.1 -- the legacy protobuf compiler +### /toolchains/bin/protoc-gen-go -- the go code generator for protoc +### /toolchains/bin/protoc-gen-XXX -- other protobuf generators (vtproto, java, etc.) +### /toolchains/include -- contains any protobuf library files for common types (like proto.Duration) +### /toolchains/includes/proto -- protobuf libraries bundled with the new protobuf compiler +### /toolchains/includes/proto_legacy -- protobuf libraries bundled with the legacy protobuf compiler +### => /toolchains/gogo -- temp directory used to build the gogo_faster generator namespace :codegen do + task :clean do + sh "rm -rf #{gogo_dir}" + sh "rm -rf #{toolchain_dir}" + end - task :install_protoc do - if `bash -c "protoc --version"` != "libprotoc ${protoc_legacy_version}" + task :setup_gogo => ['install_protoc_all'] do + if ! Dir.exist?(gogo_dir) then + directory "#{gogo_dir}/src/github.com/gogo" + sh "git clone https://github.com/gogo/protobuf.git #{gogo_dir}/src/github.com/gogo/protobuf" + else + puts "gogo already cloned into #{gogo_dir}" + end + + Dir.chdir("#{gogo_dir}/src/github.com/gogo/protobuf") do + sh "git checkout #{gogo_tag}" + sh "PATH=$PATH:/tmp GOBIN=#{toolchain_bin_dir} GOPATH=#{gogo_dir} make clean install" + end + end + + + task 'install_protoc_all' => ['install_protoc', 'install_protoc_legacy'] + + task :install_protoc_legacy do + if `bash -c "#{protoc_legacy_binary} --version"` != "libprotoc ${protoc_version}" sh <<-EOF /bin/bash < ['install_protoc', 'setup_gogo'] do - task :protoc => ['install_protoc'] do sh <<-EOF /bin/bash <