Skip to content

Commit ee4eca9

Browse files
authored
Build protoc from source (#1876)
## Motivation In a recent addition, we included changes to provide `protoc` as a binary target from the official releases from the upstream `protobuf` repository. While this solved one of the largest issues in our ecosystem where folks currently needed to install `protoc` through a system package manager, it also introduced another set of problems that binary targets bring with them. ## Modifications This PR adds `protobuf` and `abseil-cpp` as a submodule to this project and includes a new target that builds both together from source. It includes the minimal set of files from both to successfully build `protoc` and also passes the right compiler and linker flags to build those warning free. ## Result We are no longer using a binary target for `protoc` but instead build it from source which alleviates the problems that we introduced with the binary target.
1 parent 03a26d1 commit ee4eca9

12 files changed

Lines changed: 577 additions & 336 deletions

.github/scripts/draft_release_protoc_artifactbundle.sh

Lines changed: 0 additions & 143 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,59 +34,22 @@ jobs:
3434
- version: "5.10"
3535
# No "hook", see https://github.com/apple/swift-protobuf/issues/1560 for the
3636
# current issue with using -warnings-as-errors on linux.
37-
# protobuf_git can reference a commit, tag, or branch
38-
# commit: "commits/6935eae45c99926a000ecbef0be20dfd3d159e71"
39-
# tag: "ref/tags/v3.11.4"
40-
# branch: "ref/heads/main"
41-
protobuf_git: ["ref/heads/main"]
4237
container:
4338
image: swift:${{ matrix.swift.version }}
4439
steps:
4540
- name: Checkout
4641
uses: actions/checkout@v4
4742
with:
48-
path: swift-protobuf
43+
submodules: true
4944
- name: Update and install dependencies
5045
# dependencies from https://github.com/protocolbuffers/protobuf/blob/main/src/README.md
51-
# this step is run before get-sha because we need curl and jq for get-sha
52-
run: apt-get update && apt-get install -y curl make g++ cmake jq
53-
- name: Get Protobuf Commit SHA
54-
id: get-sha
55-
run: |
56-
set -eu
57-
url="https://api.github.com/repos/protocolbuffers/protobuf/git/${{ matrix.protobuf_git }}"
58-
case ${{ matrix.protobuf_git }} in
59-
ref/*)
60-
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .object.sha )" >> $GITHUB_OUTPUT
61-
;;
62-
commits/*)
63-
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .sha )" >> $GITHUB_OUTPUT
64-
;;
65-
esac
46+
run: apt-get update && apt-get install -y make g++ cmake
6647
- name: Build
67-
working-directory: swift-protobuf
6848
run: make build ${{ matrix.swift.hook }}
6949
- name: Test runtime
70-
working-directory: swift-protobuf
7150
run: make test-runtime ${{ matrix.swift.hook }}
72-
- name: Cache protobuf
73-
id: cache-protobuf
74-
uses: actions/cache@v4
75-
with:
76-
path: protobuf
77-
# NOTE: for refs that can float like 'main' the cache might be out of date!
78-
key: ${{ runner.os }}-${{ matrix.swift.version}}-protobuf-${{ steps.get-sha.outputs.sha }}
79-
- name: Checkout protobuf repo
80-
if: steps.cache-protobuf.outputs.cache-hit != 'true'
81-
uses: actions/checkout@v4
82-
with:
83-
repository: protocolbuffers/protobuf
84-
ref: ${{ steps.get-sha.outputs.sha }}
85-
submodules: true
86-
path: protobuf
8751
- name: Build protobuf
88-
if: steps.cache-protobuf.outputs.cache-hit != 'true'
89-
working-directory: protobuf
52+
working-directory: Sources/protobuf/protobuf
9053
# https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md#c-version
9154
run: |
9255
mkdir cmake_build
@@ -101,17 +64,13 @@ jobs:
10164
NUM_CPUS=$(getconf _NPROCESSORS_ONLN)
10265
make -j "${NUM_CPUS}" protoc conformance_test_runner
10366
- name: Test plugin
104-
working-directory: swift-protobuf
105-
run: make test-plugin PROTOC=../protobuf/cmake_build/protoc
67+
run: make test-plugin PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
10668
- name: Test conformance
107-
working-directory: swift-protobuf
108-
run: make test-conformance CONFORMANCE_TEST_RUNNER=../protobuf/cmake_build/conformance_test_runner
69+
run: make test-conformance CONFORMANCE_TEST_RUNNER=Sources/protobuf/protobuf/cmake_build/conformance_test_runner
10970
- name: Test SPM plugin
110-
working-directory: swift-protobuf
111-
run: make test-spm-plugin PROTOC=../protobuf/cmake_build/protoc
71+
run: make test-spm-plugin PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
11272
- name: Compilation Tests
113-
working-directory: swift-protobuf
114-
run: make compile-tests PROTOC=../protobuf/cmake_build/protoc
73+
run: make compile-tests PROTOC=Sources/protobuf/protobuf/cmake_build/protoc
11574

11675
api-breakage:
11776
name: Api Breakage Compared to main branch
@@ -128,6 +87,7 @@ jobs:
12887
uses: actions/checkout@v4
12988
with:
13089
fetch-depth: 0
90+
submodules: true
13191
- name: Mark the workspace as safe
13292
# https://github.com/actions/checkout/issues/766
13393
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
@@ -146,6 +106,8 @@ jobs:
146106
steps:
147107
- name: Checkout
148108
uses: actions/checkout@v4
109+
with:
110+
submodules: true
149111
- name: Mark the workspace as safe
150112
# https://github.com/actions/checkout/issues/766
151113
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
@@ -167,11 +129,17 @@ jobs:
167129
matrix:
168130
sanitizer: ["address", "thread"]
169131
swiftpm_config: ["debug", "release"]
132+
exclude: # Excluded due to a clang crasher that is fixed in a more recent clang https://github.com/llvm/llvm-project/issues/95928
133+
- sanitizer: "address"
134+
swiftpm_config: "debug"
170135
container:
171136
# Test on the latest Swift release.
172137
image: swift:latest
173138
steps:
174139
- uses: actions/checkout@v4
140+
with:
141+
submodules: true
142+
175143
- name: Test
176144
run: |
177145
set -eu
@@ -201,5 +169,7 @@ jobs:
201169
image: swift:latest
202170
steps:
203171
- uses: actions/checkout@v4
172+
with:
173+
submodules: true
204174
- name: Build
205175
run: FuzzTesting/do_build.sh --${{ matrix.swiftpm_config }}-only --run-regressions

.github/workflows/check_upstream_protos.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v4
1919
with:
20-
path: swift-protobuf
21-
- name: Checkout protobufbuffers/protobuf
22-
uses: actions/checkout@v4
23-
with:
24-
repository: protocolbuffers/protobuf
25-
path: protobuf
20+
submodules: true
2621
- name: Check Upstream Proto Files
27-
working-directory: swift-protobuf
2822
run: make check-proto-files

.github/workflows/draft_release_protoc_artifactbundle.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/regular_conformance.yml

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,53 +36,18 @@ jobs:
3636
# which is also what would be desired, so we don't bother listing explicit ones.
3737
swift:
3838
- "6.2"
39-
# protobuf_git can reference a commit, tag, or branch
40-
# commit: "commits/6935eae45c99926a000ecbef0be20dfd3d159e71"
41-
# tag: "ref/tags/v3.11.4"
42-
# branch: "ref/heads/main"
43-
protobuf_git: ["ref/heads/main"]
4439
container:
4540
image: swift:${{ matrix.swift }}
4641
steps:
4742
- name: Checkout
4843
uses: actions/checkout@v4
4944
with:
50-
path: swift-protobuf
45+
submodules: true
5146
- name: Update and install dependencies
5247
# dependencies from https://github.com/protocolbuffers/protobuf/blob/main/src/README.md
53-
# this step is run before get-sha because we need curl and jq for get-sha
54-
run: apt-get update && apt-get install -y curl make g++ cmake jq
55-
- name: Get Protobuf Commit SHA
56-
id: get-sha
57-
run: |
58-
set -eu
59-
url="https://api.github.com/repos/protocolbuffers/protobuf/git/${{ matrix.protobuf_git }}"
60-
case ${{ matrix.protobuf_git }} in
61-
ref/*)
62-
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .object.sha )" >> $GITHUB_OUTPUT
63-
;;
64-
commits/*)
65-
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .sha )" >> $GITHUB_OUTPUT
66-
;;
67-
esac
68-
- name: Cache protobuf
69-
id: cache-protobuf
70-
uses: actions/cache@v4
71-
with:
72-
path: protobuf
73-
# NOTE: for refs that can float like 'main' the cache might be out of date!
74-
key: ${{ runner.os }}-${{ matrix.swift }}-protobuf-${{ steps.get-sha.outputs.sha }}
75-
- name: Checkout protobuf repo
76-
if: steps.cache-protobuf.outputs.cache-hit != 'true'
77-
uses: actions/checkout@v4
78-
with:
79-
repository: protocolbuffers/protobuf
80-
ref: ${{ steps.get-sha.outputs.sha }}
81-
submodules: true
82-
path: protobuf
48+
run: apt-get update && apt-get install -y make g++ cmake
8349
- name: Build protobuf
84-
if: steps.cache-protobuf.outputs.cache-hit != 'true'
85-
working-directory: protobuf
50+
working-directory: Sources/protobuf/protobuf
8651
# https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md#c-version
8752
run: |
8853
mkdir cmake_build
@@ -97,5 +62,4 @@ jobs:
9762
NUM_CPUS=$(getconf _NPROCESSORS_ONLN)
9863
make -j "${NUM_CPUS}" protoc conformance_test_runner
9964
- name: Test conformance
100-
working-directory: swift-protobuf
101-
run: make test-conformance CONFORMANCE_TEST_RUNNER=../protobuf/cmake_build/conformance_test_runner
65+
run: make test-conformance CONFORMANCE_TEST_RUNNER=Sources/protobuf/protobuf/cmake_build/conformance_test_runner

0 commit comments

Comments
 (0)