Skip to content

Commit 8ad6cdd

Browse files
mkruskal-googledeannagarcia
authored andcommitted
Modify release artifacts for protoc to statically link system libraries.
Closes #12063 PiperOrigin-RevId: 513034570
1 parent 5926dc4 commit 8ad6cdd

File tree

12 files changed

+38
-35
lines changed

12 files changed

+38
-35
lines changed

.bazelrc

-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ build:msan --copt=-fsanitize-memory-use-after-dtor
1717
build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1
1818
build:msan --copt=-DMEMORY_SANITIZER=1
1919

20-
# Use our instrumented LLVM libc++ in Kokoro.
21-
build:kokoro-msan --config=msan
22-
build:kokoro-msan --linkopt=-L/opt/libcxx_msan/lib
23-
build:kokoro-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib
24-
build:kokoro-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++
25-
26-
2720
build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread
2821
build:tsan --copt=-DTHREAD_SANITIZER=1
2922

.github/workflows/test_cpp.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ jobs:
1717
- { name: Optimized, flags: --config=opt }
1818
- { name: Debug, flags: --config=dbg }
1919
- { name: ASAN, flags: --config=asan }
20-
- { name: MSAN, flags: --config=kokoro-msan }
20+
- { name: MSAN, flags: --config=docker-msan }
2121
- { name: TSAN, flags: --config=tsan }
2222
- { name: UBSAN, flags: --config=ubsan }
2323
- { name: No-RTTI, flags: --cxxopt=-fno-rtti }
2424
include:
2525
# Set defaults
26-
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:dbd2f15fb69734d72c3fd10cb819bbe2ce4890acf49e9a2f9403983fe48e8807
26+
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:309dae3122031447d714414814d262e5f31cb93c0e248e9c02f9d8cdafd7e3b9
2727
- targets: //pkg/... //src/... @com_google_protobuf_examples//...
2828

2929
# Override cases with custom images
3030
- config: { name: "TCMalloc" }
31-
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:9d975616c3fd44d5a091aeb60ee94f37e22fb367d471d258fc18cb4a2387c943"
31+
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:4df3b4749e787ba0a671ec0b783d0f1ba05f60be4c9e9fd72c875550a0cde1ea"
3232
targets: "//src/..."
3333
- config: { name: "aarch64" }
3434
targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test"
35-
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b"
35+
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-508417e5215994ade7585d28ba3aad681a25fa5d"
3636
- config: { name: "Bazel4" }
3737
targets: "//src/..."
38-
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:4.2.3-3b71de326b62f67bf754c4dc4016d6a2fa9dd664"
38+
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:4.2.3-6361b3a6e5c97e9951d03a4de28542fc45f1adab"
3939
name: Linux ${{ matrix.config.name }}
4040
runs-on: ubuntu-latest
4141
steps:

.github/workflows/test_csharp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Run tests
2121
uses: ./.github/actions/bazel-docker
2222
with:
23-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:3.1.415-6.0.100-65526ea124d1034eac33e7c37cc6d65c5bef054f
23+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:3.1.415-6.0.100-508417e5215994ade7585d28ba3aad681a25fa5d
2424
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
2525
bazel-cache: csharp_linux
2626
bazel: test //csharp/... --action_env=DOTNET_CLI_TELEMETRY_OPTOUT=1 --test_env=DOTNET_CLI_HOME=/home/bazel

.github/workflows/test_java.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
targets: //java/... //java/internal:java_version
2929
- name: aarch64
3030
version: 'aarch64'
31-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b
31+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-508417e5215994ade7585d28ba3aad681a25fa5d
3232
targets: //java/... //src/google/protobuf/compiler:protoc_aarch64_test
3333

3434
name: Linux ${{ matrix.name }}

.github/workflows/test_php.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Run tests
4646
uses: ./.github/actions/docker
4747
with:
48-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:${{ matrix.version }}-6e95c0e221e4bd52e3b4dc1398c6336985196931
48+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:${{ matrix.version }}-508417e5215994ade7585d28ba3aad681a25fa5d
4949
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
5050
command: ${{ matrix.command }}
5151

@@ -80,6 +80,7 @@ jobs:
8080
id: cross-compile
8181
uses: ./.github/actions/cross-compile-protoc
8282
with:
83+
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-6361b3a6e5c97e9951d03a4de28542fc45f1adab
8384
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
8485
architecture: linux-i386
8586

@@ -111,6 +112,7 @@ jobs:
111112
id: cross-compile
112113
uses: ./.github/actions/cross-compile-protoc
113114
with:
115+
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-6361b3a6e5c97e9951d03a4de28542fc45f1adab
114116
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
115117
architecture: linux-aarch64
116118

.github/workflows/test_python.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
targets: //python/... //python:aarch64_test
2828
# TODO(b/262628111) Enable this once conformance tests are fixed.
2929
flags: --define=use_fast_cpp_protos=true --test_tag_filters=-conformance
30-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b
30+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-508417e5215994ade7585d28ba3aad681a25fa5d
3131

3232
name: Linux ${{ matrix.type }} ${{ matrix.version }}
3333
runs-on: ubuntu-latest
@@ -39,7 +39,7 @@ jobs:
3939
- name: Run tests
4040
uses: ./.github/actions/bazel-docker
4141
with:
42-
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:{0}-65526ea124d1034eac33e7c37cc6d65c5bef054f', matrix.version) }}
42+
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:{0}-508417e5215994ade7585d28ba3aad681a25fa5d', matrix.version) }}
4343
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
4444
bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }}
4545
bazel: test ${{ matrix.targets }} ${{ matrix.flags }} --test_env=KOKORO_PYTHON_VERSION

.github/workflows/test_ruby.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run tests
3535
uses: ./.github/actions/bazel-docker
3636
with:
37-
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-75e79f791b96e056086f43ace729cf3ebf9a9f5d', matrix.ruby, matrix.bazel) }}
37+
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-508417e5215994ade7585d28ba3aad681a25fa5d', matrix.ruby, matrix.bazel) }}
3838
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
3939
bazel-cache: ruby_linux/${{ matrix.ruby }}_${{ matrix.bazel }}
4040
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION
@@ -52,6 +52,7 @@ jobs:
5252
id: cross-compile
5353
uses: ./.github/actions/cross-compile-protoc
5454
with:
55+
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-6361b3a6e5c97e9951d03a4de28542fc45f1adab
5556
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
5657
architecture: linux-aarch64
5758

@@ -125,7 +126,7 @@ jobs:
125126
- name: Run tests
126127
uses: ./.github/actions/bazel-docker
127128
with:
128-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-${{ matrix.bazel }}-75e79f791b96e056086f43ace729cf3ebf9a9f5d
129+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-${{ matrix.bazel }}-508417e5215994ade7585d28ba3aad681a25fa5d
129130
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
130131
bazel-cache: ruby_install/${{ matrix.ruby }}_${{ matrix.bazel }}
131132
bash: >

BUILD.bazel

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
44
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
55
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
66
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
7-
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
7+
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
88
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
99

1010
licenses(["notice"])
@@ -168,7 +168,21 @@ alias(
168168
cc_binary(
169169
name = "protoc",
170170
copts = COPTS,
171-
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
171+
linkopts = LINK_OPTS,
172+
visibility = ["//visibility:public"],
173+
deps = ["//src/google/protobuf/compiler:protoc_lib"],
174+
)
175+
176+
cc_binary(
177+
name = "protoc_static",
178+
copts = COPTS,
179+
linkopts = LINK_OPTS,
180+
features = select({
181+
# This isn't possible on mac because there is no static library for lcrt0.o
182+
"@platforms//os:osx": [],
183+
# When cross-compiling we need to statically link all C++ libraries.
184+
"//conditions:default": ["fully_static_link"],
185+
}),
172186
visibility = ["//visibility:public"],
173187
deps = ["//src/google/protobuf/compiler:protoc_lib"],
174188
)

build_defs/cpp_opts.bzl

-7
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,3 @@ LINK_OPTS = select({
4141
"-lm",
4242
],
4343
})
44-
45-
# When cross-compiling for Windows we need to statically link pthread and the C++ library.
46-
PROTOC_LINK_OPTS = select({
47-
"//build_defs:config_win32": ["-static"],
48-
"//build_defs:config_win64": ["-static"],
49-
"//conditions:default": [],
50-
})

ci/common.bazelrc

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1
1919
build:msan --copt=-DMEMORY_SANITIZER=1
2020

2121
# Use our instrumented LLVM libc++ in Kokoro.
22-
build:kokoro-msan --config=msan
23-
build:kokoro-msan --linkopt=-L/opt/libcxx_msan/lib
24-
build:kokoro-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib
25-
build:kokoro-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++
22+
build:docker-msan --config=msan
23+
build:docker-msan --linkopt=-L/opt/libcxx_msan/lib --linkopt=-lc++abi
24+
build:docker-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib
25+
build:docker-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++
2626

2727

2828
build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread

pkg/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Please refer to our official github site for more installation instructions:
5959

6060
pkg_files(
6161
name = "protoc_files",
62-
srcs = ["//:protoc"],
62+
srcs = ["//:protoc_static"],
6363
attributes = pkg_attributes(mode = "0555"),
6464
prefix = "bin/",
6565
visibility = ["//visibility:private"],

src/google/protobuf/compiler/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load(
1111
)
1212
load("@rules_proto//proto:defs.bzl", "proto_library")
1313
load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
14-
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
14+
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
1515

1616
proto_library(
1717
name = "plugin_proto",
@@ -123,7 +123,7 @@ cc_library(
123123
cc_binary(
124124
name = "protoc_nowkt",
125125
copts = COPTS,
126-
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
126+
linkopts = LINK_OPTS,
127127
visibility = [
128128
"//src/google/protobuf:__pkg__",
129129
],

0 commit comments

Comments
 (0)