Skip to content

Commit d3dad7f

Browse files
Merge pull request #11895 from protocolbuffers/merge-main-to-22.x
Merge main to 22.x
2 parents 8efe44f + f24de86 commit d3dad7f

480 files changed

Lines changed: 12004 additions & 11054 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/BUILD.bazel

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This information is extracted from the MacOS runner specs located at:
2+
# https://github.com/actions/runner-images/blob/win19/20230129.2/images/macos/macos-12-Readme.md
3+
xcode_version(
4+
name = "version14_2_14C18",
5+
version = "14.2.14C18",
6+
aliases = ["14C18"],
7+
default_ios_sdk_version = "16.2",
8+
default_tvos_sdk_version = "16.1",
9+
default_macos_sdk_version = "13.1",
10+
default_watchos_sdk_version = "9.1",
11+
)
12+
13+
xcode_version(
14+
name = "version14_1_0_14B47b",
15+
version = "14.1.0.14B47b",
16+
aliases = ["14B47b"],
17+
default_ios_sdk_version = "16.1",
18+
default_tvos_sdk_version = "16.1",
19+
default_macos_sdk_version = "13.0",
20+
default_watchos_sdk_version = "9.1",
21+
)
22+
23+
xcode_config(
24+
name = "host_xcodes",
25+
versions = [":version14_2_14C18", ":version14_1_0_14B47b"],
26+
default = ":version14_1_0_14B47b",
27+
)

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
/kokoro/ @protocolbuffers/protobuf-btr
3535
/third_party/ @protocolbuffers/protobuf-btr
3636
*.bazel @protocolbuffers/protobuf-btr
37+
/.github/ @protocolbuffers/protobuf-btr

.github/actions/bash/action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Non-Bazel Bash Run'
2+
description: 'Run a bash script for Protobuf CI testing with a non-Bazel build system'
3+
inputs:
4+
credentials:
5+
required: true
6+
description: "The GCP credentials to use for reading the docker image"
7+
type: string
8+
command:
9+
required: true
10+
description: A command to run in the docker image
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: Setup Runner
16+
uses: ./.github/actions/internal/setup-runner
17+
18+
- name: Update stale files using Bazel
19+
uses: ./.github/actions/bazel
20+
with:
21+
credentials: ${{ inputs.credentials }}
22+
bazel-cache: regenerate-stale-files
23+
bash: ./regenerate_stale_files.sh $BAZEL_FLAGS
24+
25+
- name: Run
26+
shell: bash
27+
run: ${{ inputs.command }}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: 'Docker Bazel Run'
2+
description: 'Run a Bazel-based docker image for Protobuf CI testing'
3+
inputs:
4+
credentials:
5+
required: true
6+
description: "The GCP credentials to use for reading the docker image"
7+
type: string
8+
image:
9+
required: false
10+
default: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-aec4d74f2eb6938fc53ef7d9a79a4bf2da24abc1
11+
description: "The docker image to use"
12+
type: string
13+
bazel-cache:
14+
required: true
15+
description: >
16+
A unique path for the Bazel cache. This will trigger the generation
17+
of a BAZEL_CACHE environment variable inside the container that provides
18+
the appropriate flags for any bazel command.
19+
type: string
20+
bazel:
21+
required: false
22+
description: "The Bazel command to run"
23+
type: string
24+
bash:
25+
required: false
26+
description: "A bash command to run. $BAZEL_FLAGS will be available to use for bazel runs."
27+
type: string
28+
29+
runs:
30+
using: 'composite'
31+
steps:
32+
- name: Authenticate
33+
id: auth
34+
uses: ./.github/actions/internal/gcloud-auth
35+
with:
36+
credentials: ${{ inputs.credentials }}
37+
38+
- name: Setup Runner
39+
uses: ./.github/actions/internal/setup-runner
40+
41+
- name: Setup Bazel
42+
id: bazel
43+
uses: ./.github/actions/internal/bazel-setup
44+
with:
45+
credentials-file: /workspace/$(basename ${{ steps.auth.outputs.credentials-file }})
46+
bazel-cache: ${{ inputs.bazel-cache }}
47+
48+
- name: Hook up repository Cache
49+
shell: bash
50+
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache='/workspace/${{ env.REPOSITORY_CACHE_PATH }}'" >> $GITHUB_ENV
51+
52+
- name: Validate inputs
53+
if: ${{ (inputs.bash && inputs.bazel) || (!inputs.bash && !inputs.bazel) }}
54+
shell: bash
55+
run: echo "Invalid specification of both non-Bazel and Bazel command"; exit 1
56+
57+
- name: Run Bash Docker
58+
uses: ./.github/actions/internal/docker-run
59+
if: ${{ inputs.bash }}
60+
with:
61+
image: ${{ inputs.image }}
62+
run-flags: --entrypoint "/bin/bash"
63+
command: -l -c "${{ inputs.bash }}"
64+
65+
- name: Run Bazel Docker
66+
uses: ./.github/actions/internal/docker-run
67+
if: ${{ !inputs.bash }}
68+
with:
69+
image: ${{ inputs.image }}
70+
command: ${{ inputs.bazel }} ${{ env.BAZEL_FLAGS }}
71+
72+
- name: Save Bazel repository cache
73+
# Only allow repository cache updates during post-submits.
74+
if: ${{ github.event_name == 'push' }}
75+
uses: ./.github/actions/internal/repository-cache-save

.github/actions/bazel/action.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: 'Docker Bazel Run'
2+
description: 'Run a Bazel-based docker image for Protobuf CI testing'
3+
inputs:
4+
credentials:
5+
required: true
6+
description: The GCP credentials to use for reading the docker image
7+
type: string
8+
bazel-cache:
9+
required: true
10+
description: >
11+
A unique path for the Bazel cache. This will trigger the generation
12+
of a BAZEL_CACHE environment variable inside the container that provides
13+
the appropriate flags for any bazel command.
14+
type: string
15+
version:
16+
required: false
17+
description: A pinned Bazel version to use
18+
default: '5.1.1'
19+
type: string
20+
bazel:
21+
required: false
22+
description: The Bazel command to run
23+
type: string
24+
bash:
25+
required: false
26+
description: >
27+
A bash command to run. $BAZEL_FLAGS and $BAZEL_STARTUP_FLAGS will be
28+
available to use for bazel runs.
29+
type: string
30+
31+
runs:
32+
using: 'composite'
33+
steps:
34+
- name: Authenticate
35+
id: auth
36+
uses: ./.github/actions/internal/gcloud-auth
37+
with:
38+
credentials: ${{ inputs.credentials }}
39+
40+
- name: Setup Runner
41+
uses: ./.github/actions/internal/setup-runner
42+
43+
- name: Setup Bazel
44+
id: bazel
45+
uses: ./.github/actions/internal/bazel-setup
46+
with:
47+
credentials-file: ${{ steps.auth.outputs.credentials-file }}
48+
bazel-cache: ${{ inputs.bazel-cache }}
49+
50+
- name: Get Linux bazelisk path
51+
if: runner.os == 'Linux'
52+
shell: bash
53+
run: echo "BAZELISK_PATH=~/.cache/bazelisk" >> $GITHUB_ENV
54+
55+
- name: Get MacOS bazelisk path
56+
if: runner.os == 'macOS'
57+
shell: bash
58+
run: echo "BAZELISK_PATH=~/Library/Caches/bazelisk" >> $GITHUB_ENV
59+
60+
- name: Get Windows bazelisk path
61+
if: runner.os == 'Windows'
62+
shell: bash
63+
run: echo "BAZELISK_PATH=$LOCALAPPDATA\bazelisk" >> $GITHUB_ENV
64+
65+
- name: Cache Bazelisk
66+
if: ${{ github.event_name == 'push' }}
67+
uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
68+
with:
69+
path: ${{ env.BAZELISK_PATH }}
70+
key: bazel-${{ runner.os }}-${{ inputs.version }}
71+
72+
- name: Restore Bazelisk
73+
if: ${{ github.event_name != 'push' }}
74+
uses: actions/cache/restore@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
75+
with:
76+
path: ${{ env.BAZELISK_PATH }}
77+
key: bazel-${{ runner.os }}-${{ inputs.version }}
78+
79+
- name: Hook up repository Cache
80+
shell: bash
81+
run: echo "BAZEL_FLAGS=$BAZEL_FLAGS --repository_cache=$(pwd)/${{ env.REPOSITORY_CACHE_PATH }}" >> $GITHUB_ENV
82+
83+
- name: Validate inputs
84+
if: ${{ (inputs.bash && inputs.bazel) || (!inputs.bash && !inputs.bazel) }}
85+
shell: bash
86+
run: echo "Invalid specification of both non-Bazel and Bazel command"; exit 1
87+
88+
- name: Pin Bazel version
89+
shell: bash
90+
run: echo "USE_BAZEL_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
91+
92+
- name: Output Bazel version
93+
shell: bash
94+
run: bazelisk version
95+
96+
- name: Run Bash
97+
if: ${{ inputs.bash }}
98+
run: ${{ inputs.bash }}
99+
shell: bash
100+
101+
- name: Run Bazel
102+
if: ${{ !inputs.bash }}
103+
run: >-
104+
bazelisk ${{ steps.bazel.outputs.bazel-startup-flags }}
105+
${{ inputs.bazel }} $BAZEL_FLAGS
106+
shell: bash
107+
108+
- name: Save Bazel repository cache
109+
# Only allow repository cache updates during post-submits.
110+
if: ${{ github.event_name == 'push' }}
111+
uses: ./.github/actions/internal/repository-cache-save

.github/actions/ccache/action.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: 'CCache Setup'
2+
description: 'Run a Bazel-based docker image for Protobuf CI testing'
3+
inputs:
4+
cache-prefix:
5+
required: true
6+
description: A unique prefix to prevent cache pollution
7+
type: string
8+
support-modules:
9+
required: false
10+
description: Whether or not we need to support modules. This can result in extra cache misses.
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: Setup ccache on Windows
16+
if: ${{ runner.os == 'Windows' }}
17+
uses: ./.github/actions/internal/ccache-setup-windows
18+
- name: Setup ccache on Mac
19+
if: ${{ runner.os == 'macOS' }}
20+
shell: bash
21+
run: brew install ccache
22+
23+
- name: Setup fixed path ccache caching
24+
uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4
25+
with:
26+
path: .ccache
27+
# Always push to a cache key unique to this commit.
28+
key: ${{ format('ccache-{0}-{1}-{2}', inputs.cache-prefix, github.ref_name, github.sha) }}
29+
# Select a cache to restore from with the follow order of preference:
30+
# 1) The exact same commit we're running over
31+
# 2) The latest cache from the current ref branch
32+
# 3) The latest push to the base ref of a pull request
33+
restore-keys: |
34+
${{ format('ccache-{0}-{1}-{2}', inputs.cache-prefix, github.ref_name, github.sha) }}
35+
${{ format('ccache-{0}-{1}', inputs.cache-prefix, github.ref_name) }}
36+
${{ format('ccache-{0}-{1}', inputs.cache-prefix, github.base_ref) }}
37+
38+
- name: Configure ccache environment variables
39+
shell: bash
40+
run: |
41+
echo "CCACHE_BASEDIR=${{ github.workspace }}" >> $GITHUB_ENV
42+
echo "CCACHE_DIR=${{ github.workspace }}/.ccache" >> $GITHUB_ENV
43+
echo "CCACHE_COMPRESS=true" >> $GITHUB_ENV
44+
echo "CCACHE_COMPRESSLEVEL=6" >> $GITHUB_ENV
45+
echo "CCACHE_MAXSIZE=600M" >> $GITHUB_ENV
46+
echo "CCACHE_SLOPPINESS=clang_index_store,include_file_ctime,include_file_mtime,file_macro,time_macros" >> $GITHUB_ENV
47+
echo "CCACHE_DIRECT=true" >> $GITHUB_ENV
48+
echo "CCACHE_CMAKE_FLAGS=-Dprotobuf_ALLOW_CCACHE=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $CCACHE_CMAKE_FLAGS" >> $GITHUB_ENV
49+
50+
- name: Enable module support
51+
if: ${{ inputs.support-modules }}
52+
shell: bash
53+
run: |
54+
echo "CCACHE_SLOPPINESS=$CCACHE_SLOPPINESS,modules" >> $GITHUB_ENV
55+
echo "CCACHE_DEPEND=true" >> $GITHUB_ENV
56+
57+
- name: Zero out ccache
58+
if: ${{ runner.os == 'macOS' }}
59+
shell: bash
60+
run: ccache -z
61+
62+
- name: Zero out ccache
63+
if: ${{ runner.os == 'Windows' }}
64+
shell: pwsh
65+
run: ${{ github.workspace }}\ccache.exe -z
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'Cross-compile protoc'
2+
description: 'Produces a cross-compiled protoc binary for a target architecture'
3+
inputs:
4+
credentials:
5+
required: true
6+
description: The GCP credentials to use for reading the docker image
7+
type: string
8+
architecture:
9+
required: true
10+
description: The target architecture to build for
11+
type: string
12+
outputs:
13+
protoc:
14+
description: "Cross-compiled protoc location. Also output to $PROTOC"
15+
value: ${{ steps.output.outputs.protoc }}
16+
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- name: Cross compile protoc for ${{ inputs.architecture }}
21+
uses: ./.github/actions/bazel-docker
22+
with:
23+
credentials: ${{ inputs.credentials }}
24+
bazel-cache: xcompile-protoc/${{ inputs.architecture }}
25+
bash: |
26+
bazel build //:protoc --config=${{ inputs.architecture }} $BAZEL_FLAGS
27+
cp bazel-bin/protoc .
28+
29+
- name: Set protoc environment variable
30+
shell: bash
31+
run: echo "PROTOC=protoc-${{ inputs.architecture }}" >> $GITHUB_ENV
32+
33+
- name: Extract binary
34+
id: output
35+
shell: bash
36+
run: |
37+
mv protoc $PROTOC
38+
echo "protoc=$PROTOC" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)