Skip to content

Commit dfc5213

Browse files
committed
Cache plugin
1 parent f3f9446 commit dfc5213

File tree

3 files changed

+93
-88
lines changed

3 files changed

+93
-88
lines changed

.github/workflows/CI.yml

Lines changed: 91 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,71 @@ jobs:
2525
components: rustfmt
2626
- run: cargo fmt --all --check
2727

28+
build-protoc-plugin:
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
matrix:
32+
os: [ubuntu-latest, macOS-latest, windows-latest]
33+
outputs:
34+
cache-hit: ${{ steps.cache-plugin.outputs.cache-hit }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Cache protoc plugin
38+
id: cache-plugin
39+
uses: actions/cache@v4
40+
with:
41+
path: ${{ runner.temp }}/protoc-plugin
42+
# The key changes only when plugin source files change
43+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
44+
- name: Install Bazel
45+
# if: steps.cache-plugin.outputs.cache-hit != 'true'
46+
uses: bazel-contrib/setup-bazel@0.15.0
47+
with:
48+
# Avoid downloading Bazel every time.
49+
bazelisk-cache: true
50+
# Store build cache per workflow.
51+
disk-cache: ${{ github.workflow }}
52+
# Share repository cache between workflows.
53+
repository-cache: true
54+
module-root: ./compiler
55+
- name: Build protoc plugin
56+
id: build_step
57+
if: steps.cache-plugin.outputs.cache-hit != 'true'
58+
working-directory: ./compiler
59+
shell: bash
60+
run: |
61+
set -e
62+
# On windows, the "//src" gets converted to "/". Disable this path
63+
# conversion.
64+
export MSYS_NO_PATHCONV=1
65+
export MSYS2_ARG_CONV_EXCL="*"
66+
67+
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
68+
69+
# The target path need to match the cache config
70+
TARGET_PATH="${{ runner.temp }}/protoc-plugin"
71+
mkdir -p "${TARGET_PATH}"
72+
cp bazel-bin/src/protoc-gen-rust-grpc "${TARGET_PATH}"
73+
2874
clippy:
2975
runs-on: ubuntu-latest
76+
needs: build-protoc-plugin
3077
steps:
3178
- uses: actions/checkout@v4
3279
- uses: hecrj/setup-rust-action@v2
3380
with:
3481
components: clippy
3582
- uses: taiki-e/install-action@protoc
36-
- name: Install Bazel
37-
uses: bazel-contrib/setup-bazel@0.15.0
83+
- name: Restore protoc plugin from cache
84+
id: cache-plugin
85+
uses: actions/cache@v4
3886
with:
39-
# Avoid downloading Bazel every time.
40-
bazelisk-cache: true
41-
# Store build cache per workflow.
42-
disk-cache: ${{ github.workflow }}
43-
# Share repository cache between workflows.
44-
repository-cache: true
45-
module-root: ./compiler
46-
- name: Build and protoc plugin and add to PATH
47-
id: build_step
48-
# This runs all commands within the compiler/ directory
49-
working-directory: ./compiler
87+
path: ${{ runner.temp }}/protoc-plugin
88+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
89+
- name: Add protoc plugin to PATH
90+
shell: bash
5091
run: |
51-
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
52-
53-
# Add the output directory to the GitHub PATH for subsequent steps
54-
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH
92+
echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
5593
- uses: Swatinem/rust-cache@v2
5694
- run: cargo clippy --workspace --all-features --all-targets
5795

@@ -66,6 +104,7 @@ jobs:
66104

67105
udeps:
68106
runs-on: ubuntu-latest
107+
needs: build-protoc-plugin
69108
steps:
70109
- uses: actions/checkout@v4
71110
- uses: dtolnay/rust-toolchain@master
@@ -74,25 +113,16 @@ jobs:
74113
- uses: taiki-e/install-action@cargo-hack
75114
- uses: taiki-e/install-action@cargo-udeps
76115
- uses: taiki-e/install-action@protoc
77-
- name: Install Bazel
78-
uses: bazel-contrib/setup-bazel@0.15.0
116+
- name: Restore protoc plugin from cache
117+
id: cache-plugin
118+
uses: actions/cache@v4
79119
with:
80-
# Avoid downloading Bazel every time.
81-
bazelisk-cache: true
82-
# Store build cache per workflow.
83-
disk-cache: ${{ github.workflow }}
84-
# Share repository cache between workflows.
85-
repository-cache: true
86-
module-root: ./compiler
87-
- name: Build and protoc plugin and add to PATH
88-
id: build_step
89-
# This runs all commands within the compiler/ directory
90-
working-directory: ./compiler
120+
path: ${{ runner.temp }}/protoc-plugin
121+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
122+
- name: Add protoc plugin to PATH
123+
shell: bash
91124
run: |
92-
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
93-
94-
# Add the output directory to the GitHub PATH for subsequent steps
95-
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH
125+
echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
96126
- uses: Swatinem/rust-cache@v2
97127
- run: cargo hack udeps --workspace --exclude-features=_tls-any,tls,tls-aws-lc,tls-ring --each-feature
98128
- run: cargo udeps --package tonic --features tls-ring,transport
@@ -104,6 +134,7 @@ jobs:
104134

105135
check:
106136
runs-on: ${{ matrix.os }}
137+
needs: build-protoc-plugin
107138
strategy:
108139
matrix:
109140
os: [ubuntu-latest, macOS-latest, windows-latest]
@@ -114,25 +145,16 @@ jobs:
114145
- uses: hecrj/setup-rust-action@v2
115146
- uses: taiki-e/install-action@cargo-hack
116147
- uses: taiki-e/install-action@protoc
117-
- name: Install Bazel
118-
uses: bazel-contrib/setup-bazel@0.15.0
148+
- name: Restore protoc plugin from cache
149+
id: cache-plugin
150+
uses: actions/cache@v4
119151
with:
120-
# Avoid downloading Bazel every time.
121-
bazelisk-cache: true
122-
# Store build cache per workflow.
123-
disk-cache: ${{ github.workflow }}
124-
# Share repository cache between workflows.
125-
repository-cache: true
126-
module-root: ./compiler
127-
- name: Build and protoc plugin and add to PATH
128-
id: build_step
129-
# This runs all commands within the compiler/ directory
130-
working-directory: ./compiler
152+
path: ${{ runner.temp }}/protoc-plugin
153+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
154+
- name: Add protoc plugin to PATH
155+
shell: bash
131156
run: |
132-
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
133-
134-
# Add the output directory to the GitHub PATH for subsequent steps
135-
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH
157+
echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
136158
- uses: Swatinem/rust-cache@v2
137159
- name: Check features
138160
run: cargo hack check --workspace --no-private --each-feature --no-dev-deps
@@ -165,32 +187,24 @@ jobs:
165187

166188
test:
167189
runs-on: ${{ matrix.os }}
190+
needs: build-protoc-plugin
168191
strategy:
169192
matrix:
170193
os: [ubuntu-latest, macOS-latest, windows-latest]
171194
steps:
172195
- uses: actions/checkout@v4
173196
- uses: hecrj/setup-rust-action@v2
174197
- uses: taiki-e/install-action@protoc
175-
- name: Install Bazel
176-
uses: bazel-contrib/setup-bazel@0.15.0
198+
- name: Restore protoc plugin from cache
199+
id: cache-plugin
200+
uses: actions/cache@v4
177201
with:
178-
# Avoid downloading Bazel every time.
179-
bazelisk-cache: true
180-
# Store build cache per workflow.
181-
disk-cache: ${{ github.workflow }}
182-
# Share repository cache between workflows.
183-
repository-cache: true
184-
module-root: ./compiler
185-
- name: Build and protoc plugin and add to PATH
186-
id: build_step
187-
# This runs all commands within the compiler/ directory
188-
working-directory: ./compiler
202+
path: ${{ runner.temp }}/protoc-plugin
203+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
204+
- name: Add protoc plugin to PATH
205+
shell: bash
189206
run: |
190-
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
191-
192-
# Add the output directory to the GitHub PATH for subsequent steps
193-
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH
207+
echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
194208
- uses: taiki-e/install-action@cargo-hack
195209
- uses: taiki-e/install-action@cargo-nextest
196210
- uses: Swatinem/rust-cache@v2
@@ -210,32 +224,24 @@ jobs:
210224
interop:
211225
name: Interop Tests
212226
runs-on: ${{ matrix.os }}
227+
needs: build-protoc-plugin
213228
strategy:
214229
matrix:
215230
os: [ubuntu-latest, macOS-latest, windows-latest]
216231
steps:
217232
- uses: actions/checkout@v4
218233
- uses: hecrj/setup-rust-action@v2
219234
- uses: taiki-e/install-action@protoc
220-
- name: Install Bazel
221-
uses: bazel-contrib/setup-bazel@0.15.0
235+
- name: Restore protoc plugin from cache
236+
id: cache-plugin
237+
uses: actions/cache@v4
222238
with:
223-
# Avoid downloading Bazel every time.
224-
bazelisk-cache: true
225-
# Store build cache per workflow.
226-
disk-cache: ${{ github.workflow }}
227-
# Share repository cache between workflows.
228-
repository-cache: true
229-
module-root: ./compiler
230-
- name: Build and protoc plugin and add to PATH
231-
id: build_step
232-
# This runs all commands within the compiler/ directory
233-
working-directory: ./compiler
239+
path: ${{ runner.temp }}/protoc-plugin
240+
key: ${{ runner.os }}-protoc-plugin-${{ hashFiles('compiler/src/**', 'compiler/.bazelrc', 'compiler/MODULE.bazel') }}
241+
- name: Add protoc plugin to PATH
242+
shell: bash
234243
run: |
235-
bazel build //src:protoc-gen-rust-grpc --enable_platform_specific_config
236-
237-
# Add the output directory to the GitHub PATH for subsequent steps
238-
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH
244+
echo "${{ runner.temp }}/protoc-plugin" >> $GITHUB_PATH
239245
- uses: Swatinem/rust-cache@v2
240246
- name: Run interop tests
241247
run: ./interop/test.sh

compiler/MODULE.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ git_override(
99
module_name = "hedron_compile_commands",
1010
# Using a commit from a fork to workaround failures while using absl.
1111
# TODO: replace with a commit on the official repo once the following PR is
12-
# merged: https://github.com/hedronvision/bazel-compile-commands-extractor/pull/219
12+
# merged:
13+
# https://github.com/hedronvision/bazel-compile-commands-extractor/pull/219
1314
remote = "https://github.com/mikael-s-persson/bazel-compile-commands-extractor",
1415
commit = "f5fbd4cee671d8d908f37c83abaf70fba5928fc7"
1516
)

compiler/src/grpc_rust_generator.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#ifndef NET_GRPC_COMPILER_RUST_GENERATOR_H_
2626
#define NET_GRPC_COMPILER_RUST_GENERATOR_H_
2727

28-
#include <stdlib.h> // for abort()
29-
3028
#include <google/protobuf/compiler/rust/context.h>
3129
#include <google/protobuf/descriptor.h>
3230
#include <google/protobuf/io/zero_copy_stream.h>

0 commit comments

Comments
 (0)