Skip to content

Commit

Permalink
Modify release artifacts for protoc to statically link system libraries.
Browse files Browse the repository at this point in the history
Closes #12063

PiperOrigin-RevId: 512742784
  • Loading branch information
mkruskal-google authored and copybara-github committed Feb 28, 2023
1 parent 462964e commit 68bcd12
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 37 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ jobs:
- { name: No-RTTI, flags: --cxxopt=-fno-rtti }
include:
# Set defaults
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:dbd2f15fb69734d72c3fd10cb819bbe2ce4890acf49e9a2f9403983fe48e8807
- image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:309dae3122031447d714414814d262e5f31cb93c0e248e9c02f9d8cdafd7e3b9
- targets: //pkg/... //src/... @com_google_protobuf_examples//...

# Override cases with custom images
- config: { name: "TCMalloc" }
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:9d975616c3fd44d5a091aeb60ee94f37e22fb367d471d258fc18cb4a2387c943"
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:4df3b4749e787ba0a671ec0b783d0f1ba05f60be4c9e9fd72c875550a0cde1ea"
targets: "//src/..."
- config: { name: "aarch64" }
targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test"
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b"
targets: "//src/... //src/google/protobuf/compiler:protoc_aarch64_test --linkopt=\"-static\""
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-eb065d690a4832bb0abc630b13f1a690242bf0ae"
- config: { name: "Bazel4" }
targets: "//src/..."
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:4.2.3-3b71de326b62f67bf754c4dc4016d6a2fa9dd664"
image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:4.2.3-ed17d84c969effa6cbf32f533bed71c8109f5a3f"
name: Linux ${{ matrix.config.name }}
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:3.1.415-6.0.100-65526ea124d1034eac33e7c37cc6d65c5bef054f
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/csharp:3.1.415-6.0.100-eb065d690a4832bb0abc630b13f1a690242bf0ae
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: csharp_linux
bazel: test //csharp/... --action_env=DOTNET_CLI_TELEMETRY_OPTOUT=1 --test_env=DOTNET_CLI_HOME=/home/bazel
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
include:
- name: OpenJDK 11
version: '11'
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-aec4d74f2eb6938fc53ef7d9a79a4bf2da24abc1
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-ed17d84c969effa6cbf32f533bed71c8109f5a3f
targets: //java/... //java/internal:java_version
- name: OpenJDK 17
version: '17'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:17-65526ea124d1034eac33e7c37cc6d65c5bef054f
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:17-eb065d690a4832bb0abc630b13f1a690242bf0ae
targets: //java/... //java/internal:java_version
- name: aarch64
version: 'aarch64'
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-eb065d690a4832bb0abc630b13f1a690242bf0ae
targets: //java/... //src/google/protobuf/compiler:protoc_aarch64_test

name: Linux ${{ matrix.name }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test_php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/docker@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:${{ matrix.version }}-6e95c0e221e4bd52e3b4dc1398c6336985196931
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/php:${{ matrix.version }}-eb065d690a4832bb0abc630b13f1a690242bf0ae
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: ${{ matrix.command }}

Expand Down Expand Up @@ -80,6 +80,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-ed17d84c969effa6cbf32f533bed71c8109f5a3f
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-i386

Expand Down Expand Up @@ -111,6 +112,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-ed17d84c969effa6cbf32f533bed71c8109f5a3f
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-aarch64

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
targets: //python/... //python:aarch64_test
# TODO(b/262628111) Enable this once conformance tests are fixed.
flags: --define=use_fast_cpp_protos=true --test_tag_filters=-conformance
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-e863f8ec6b1dfe41f7dc573bac9c8072a0a68b1b
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:aarch64-eb065d690a4832bb0abc630b13f1a690242bf0ae

name: Linux ${{ matrix.type }} ${{ matrix.version }}
runs-on: ubuntu-latest
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v1
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:{0}-65526ea124d1034eac33e7c37cc6d65c5bef054f', matrix.version) }}
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:{0}-eb065d690a4832bb0abc630b13f1a690242bf0ae', matrix.version) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }}
bazel: test ${{ matrix.targets }} ${{ matrix.flags }} --test_env=KOKORO_PYTHON_VERSION
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v1
with:
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-75e79f791b96e056086f43ace729cf3ebf9a9f5d', matrix.ruby, matrix.bazel) }}
image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-{1}-eb065d690a4832bb0abc630b13f1a690242bf0ae', matrix.ruby, matrix.bazel) }}
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_linux/${{ matrix.ruby }}_${{ matrix.bazel }}
bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION
Expand All @@ -52,6 +52,7 @@ jobs:
id: cross-compile
uses: protocolbuffers/protobuf-ci/cross-compile-protoc@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-ed17d84c969effa6cbf32f533bed71c8109f5a3f
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
architecture: linux-aarch64

Expand Down Expand Up @@ -124,7 +125,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bazel-docker@v1
with:
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-${{ matrix.bazel }}-75e79f791b96e056086f43ace729cf3ebf9a9f5d
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-${{ matrix.bazel }}-eb065d690a4832bb0abc630b13f1a690242bf0ae
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-cache: ruby_install/${{ matrix.ruby }}_${{ matrix.bazel }}
bash: >
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")

licenses(["notice"])
Expand Down Expand Up @@ -168,7 +168,7 @@ alias(
cc_binary(
name = "protoc",
copts = COPTS,
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
linkopts = LINK_OPTS,
visibility = ["//visibility:public"],
deps = ["//src/google/protobuf/compiler:protoc_lib"],
)
Expand Down
7 changes: 0 additions & 7 deletions build_defs/cpp_opts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,3 @@ LINK_OPTS = select({
"-lm",
],
})

# When cross-compiling for Windows we need to statically link pthread and the C++ library.
PROTOC_LINK_OPTS = select({
"//build_defs:config_win32": ["-static"],
"//build_defs:config_win64": ["-static"],
"//conditions:default": [],
})
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ load(
)
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS")

proto_library(
name = "plugin_proto",
Expand Down Expand Up @@ -123,7 +123,7 @@ cc_library(
cc_binary(
name = "protoc_nowkt",
copts = COPTS,
linkopts = LINK_OPTS + PROTOC_LINK_OPTS,
linkopts = LINK_OPTS,
visibility = [
"//src/google/protobuf:__pkg__",
],
Expand Down
1 change: 1 addition & 0 deletions toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def _impl(ctx):
flags = [
"-B" + ctx.attr.linker_path,
"-lstdc++",
"-lm",
"--target=" + ctx.attr.target_full_name,
] + ctx.attr.extra_linker_flags,
),
Expand Down
30 changes: 18 additions & 12 deletions toolchain/toolchains.bazelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
build:cross_config --crosstool_top=//toolchain:clang_suite
build:cross_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

build:linux-aarch_64 --config=cross_config --cpu=linux-aarch_64
build:linux-aarch64 --config=cross_config --cpu=linux-aarch_64
build:linux-ppcle_64 --config=cross_config --cpu=linux-ppcle_64
build:linux-ppc64le --config=cross_config --cpu=linux-ppcle_64
build:linux-s390_64 --config=cross_config --cpu=linux-s390_64
build:linux-x86_32 --config=cross_config --cpu=linux-x86_32
build:linux-i386 --config=cross_config --cpu=linux-x86_32
build:linux-x86_64 --config=cross_config --cpu=linux-x86_64
build:osx-aarch_64 --config=cross_config --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-aarch_64
build:osx-x86_64 --config=cross_config --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-x86_64
build:win32 --config=cross_config --cpu=win32
build:win64 --config=cross_config --cpu=win64
# When cross-compiling we need to statically link all C++ libraries.
build:cross_linux --config=cross_config --linkopt="-static"
build:cross_windows --config=cross_config --linkopt="-static"
# This isn't possible on mac because there is no static library for lcrt0.o
build:cross_osx --config=cross_config

build:linux-aarch_64 --config=cross_linux --cpu=linux-aarch_64
build:linux-aarch64 --config=cross_linux --cpu=linux-aarch_64
build:linux-ppcle_64 --config=cross_linux --cpu=linux-ppcle_64
build:linux-ppc64le --config=cross_linux --cpu=linux-ppcle_64
build:linux-s390_64 --config=cross_linux --cpu=linux-s390_64
build:linux-x86_32 --config=cross_linux --cpu=linux-x86_32
build:linux-i386 --config=cross_linux --cpu=linux-x86_32
build:linux-x86_64 --config=cross_linux --cpu=linux-x86_64
build:osx-aarch_64 --config=cross_osx --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-aarch_64
build:osx-x86_64 --config=cross_osx --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-x86_64
build:win32 --config=cross_windows --cpu=win32
build:win64 --config=cross_windows --cpu=win64

0 comments on commit 68bcd12

Please sign in to comment.