Skip to content

Commit

Permalink
Avoid re-downloading and rebuilding gogo every time we run codegen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leeavital committed Aug 29, 2024
1 parent 22f3ea6 commit ecba6e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/setup-go@v3
with:
go-version-file: "/home/runner/work/agent-payload/agent-payload/go/src/github.com/DataDog/agent-payload/go.mod"
- run: rake codegen
- run: rake codegen --trace
env:
GOPATH: "/home/runner/work/agent-payload/agent-payload/go"
- name: Check for diffs
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
# jetbrains IDE directory
/.idea/

vendor/
vendor/

# build time dependencies that are either downloaded or
# built during codegen
toolchains/
53 changes: 33 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,38 @@

protoc_binary="protoc"
protoc_version="3.5.1"
gogo_dir="/tmp/gogo"
gogo_dir=Dir.pwd + "/toolchains/gogo"
gogo_bin=Dir.pwd + "/toolchains/gogo-bin-v1.3.2"
protoc_binary_2="protoc"
protoc_version_2="21.12"
protoc_gen_go_dir="/tmp/protoc-gen-go"
protoc_jsonschema_version="73d5723"


namespace :codegen do
task :clean do
sh "rm -rf #{gogo_dir}"
end

task :setup_gogo => ['install_protoc'] do
if ! Dir.exist?(gogo_dir) then
sh "mkdir -p #{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
sh <<-EOD
# Install v1.3.2
cd #{gogo_dir}/src/github.com/gogo/protobuf
git checkout v1.3.2
PATH=$PATH:/tmp GOBIN=#{gogo_bin} GOPATH=#{gogo_dir} make clean install
EOD
end


task :install_protoc do
task 'install_protoc' => ['install_protoc_2', 'install_protoc_3']

task :install_protoc_3 => ['codegen:install_protoc_2'] do
if `bash -c "protoc --version"` != "libprotoc ${protoc_version}"
protoc_binary="/tmp/protoc#{protoc_version}"
sh <<-EOF
Expand All @@ -32,6 +54,10 @@ namespace :codegen do
BASH
EOF
end
end


task :install_protoc_2 do
if `bash -c "protoc --version"` != "libprotoc ${protoc_version_2}"
protoc_binary_2="/tmp/protoc#{protoc_version_2}"
sh <<-EOF
Expand All @@ -49,40 +75,27 @@ BASH
fi
BASH
EOF
end
end
end

task :protoc => ['install_protoc'] do
task :protoc => ['install_protoc', 'setup_gogo'] do
sh <<-EOF
/bin/bash <<BASH
set -euo pipefail
export GO111MODULE=auto
rm -rf #{gogo_dir}
rm -rf /tmp/gogo-bin-*
mkdir -p #{gogo_dir}/src/github.com/gogo
git clone https://github.com/gogo/protobuf.git #{gogo_dir}/src/github.com/gogo/protobuf
# Install v1.3.2
pushd #{gogo_dir}/src/github.com/gogo/protobuf
git checkout v1.3.2
GOBIN=/tmp/gogo-bin-v1.3.2 GOPATH=#{gogo_dir} make clean install
popd
echo "Generating logs proto"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src --java_out=java proto/logs/agent_logs_payload.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src --java_out=java proto/logs/agent_logs_payload.proto
echo "Generating metrics proto (go)"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src proto/metrics/agent_payload.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofast_out=$GOPATH/src proto/metrics/agent_payload.proto
echo "Generating metrics proto (python)"
#{protoc_binary} --proto_path=#{gogo_dir}/src:$GOPATH/src:./proto/metrics --python_out=python agent_payload.proto
echo "Generating process proto (go)"
PATH=/tmp/gogo-bin-v1.3.2 #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofaster_out=$GOPATH/src proto/process/*.proto
PATH=#{gogo_bin} #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gogofaster_out=$GOPATH/src proto/process/*.proto
GOPATH=#{protoc_gen_go_dir} go install github.com/leeavital/protoc-gen-gostreamer@v0.1.0
PATH=#{protoc_gen_go_dir}/bin #{protoc_binary} --proto_path=$GOPATH/src:#{gogo_dir}/src:. --gostreamer_out=$GOPATH/src proto/process/*.proto
Expand Down

0 comments on commit ecba6e7

Please sign in to comment.