Merge commit '36bca61764984ff5395653cf8377ec5daa71b709' as 'libs/protobuf'

This commit is contained in:
Henry Winkel
2022-10-22 14:46:58 +02:00
2186 changed files with 838730 additions and 0 deletions

View File

@@ -0,0 +1,247 @@
#!/bin/bash
# Builds protoc executable into target/<OS>/<ARCH>/protoc.exe; optionally builds
# protoc plugins into target/<OS>/<ARCH>/protoc-gen-*.exe
#
# Usage: ./build-protoc.sh <OS> <ARCH> <TARGET>
#
# <TARGET> can be "protoc" or "protoc-gen-javalite". Supported <OS> <ARCH>
# combinations:
# HOST <OS> <ARCH> <COMMENT>
# cygwin windows x86_32 Requires: i686-w64-mingw32-gcc
# cygwin windows x86_64 Requires: x86_64-w64-mingw32-gcc
# linux linux aarch_64 Requires: g++-aarch64-linux-gnu
# linux linux x86_32
# linux linux x86_64
# linux windows x86_32 Requires: i686-w64-mingw32-gcc
# linux windows x86_64 Requires: x86_64-w64-mingw32-gcc
# macos osx x86_32
# macos osx x86_64
# mingw windows x86_32
# mingw windows x86_64
OS=$1
ARCH=$2
BAZEL_TARGET=$3
if [[ $# < 3 ]]; then
echo "Not enough arguments provided."
exit 1
fi
if [[ $BAZEL_TARGET != protoc ]]; then
echo "Target ""$BAZEL_TARGET"" invalid."
exit 1
fi
# Under Cygwin, bash doesn't have these in PATH when called from Maven which
# runs in Windows version of Java.
export PATH="/bin:/usr/bin:$PATH"
############################################################################
# Helper functions
############################################################################
E_PARAM_ERR=98
E_ASSERT_FAILED=99
# Usage:
fail()
{
echo "ERROR: $1"
echo
exit $E_ASSERT_FAILED
}
# Usage: assertEq VAL1 VAL2 $LINENO
assertEq ()
{
lineno=$3
if [ -z "$lineno" ]; then
echo "lineno not given"
exit $E_PARAM_ERR
fi
if [[ "$1" != "$2" ]]; then
echo "Assertion failed: \"$1\" == \"$2\""
echo "File \"$0\", line $lineno" # Give name of file and line number.
exit $E_ASSERT_FAILED
fi
}
# Checks the artifact is for the expected architecture
# Usage: checkArch <path-to-protoc>
checkArch ()
{
echo
echo "Checking file format ..."
if [[ "$OS" == windows || "$OS" == linux ]]; then
format="$(objdump -f "$1" | grep -o "file format .*$" | grep -o "[^ ]*$")"
echo Format=$format
if [[ "$OS" == linux ]]; then
host_machine="$(uname -m)";
if [[ "$ARCH" == x86_32 ]]; then
assertEq $format "elf32-i386" $LINENO
elif [[ "$ARCH" == x86_64 ]]; then
assertEq $format "elf64-x86-64" $LINENO
elif [[ "$ARCH" == aarch_64 ]]; then
assertEq $format "elf64-little" $LINENO
elif [[ "$ARCH" == s390_64 ]]; then
if [[ $host_machine == s390x ]];then
assertEq $format "elf64-s390" $LINENO
else
assertEq $format "elf64-big" $LINENO
fi
elif [[ "$ARCH" == ppcle_64 ]]; then
if [[ $host_machine == ppc64le ]];then
assertEq $format "elf64-powerpcle" $LINENO
else
assertEq $format "elf64-little" $LINENO
fi
else
fail "Unsupported arch: $ARCH"
fi
else
# $OS == windows
if [[ "$ARCH" == x86_32 ]]; then
assertEq $format "pei-i386" $LINENO
elif [[ "$ARCH" == x86_64 ]]; then
assertEq $format "pei-x86-64" $LINENO
else
fail "Unsupported arch: $ARCH"
fi
fi
elif [[ "$OS" == osx ]]; then
format="$(file -b "$1" | grep -o "[^ ]*$")"
echo Format=$format
if [[ "$ARCH" == x86_32 ]]; then
assertEq $format "i386" $LINENO
elif [[ "$ARCH" == x86_64 ]]; then
assertEq $format "x86_64" $LINENO
else
fail "Unsupported arch: $ARCH"
fi
else
fail "Unsupported system: $OS"
fi
echo
}
# Checks the dependencies of the artifact. Artifacts should only depend on
# system libraries.
# Usage: checkDependencies <path-to-protoc>
checkDependencies ()
{
if [[ "$OS" == windows ]]; then
dump_cmd='objdump -x '"$1"' | fgrep "DLL Name"'
white_list="KERNEL32\.dll\|msvcrt\.dll"
elif [[ "$OS" == linux ]]; then
host_machine="$(uname -m)";
dump_cmd='ldd '"$1"
if [[ "$ARCH" == x86_32 ]]; then
white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux\.so\.2"
elif [[ "$ARCH" == x86_64 ]]; then
white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux-x86-64\.so\.2"
elif [[ "$ARCH" == s390_64 ]]; then
if [[ $host_machine != s390x ]];then
dump_cmd='objdump -p '"$1"' | grep NEEDED'
fi
white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|libz\.so\.1\|ld64\.so\.1"
elif [[ "$ARCH" == ppcle_64 ]]; then
if [[ $host_machine != ppc64le ]];then
dump_cmd='objdump -p '"$1"' | grep NEEDED'
fi
white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|libz\.so\.1\|ld64\.so\.2"
elif [[ "$ARCH" == aarch_64 ]]; then
dump_cmd='objdump -p '"$1"' | grep NEEDED'
white_list="libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux-aarch64\.so\.1"
fi
elif [[ "$OS" == osx ]]; then
dump_cmd='otool -L '"$1"' | fgrep dylib'
white_list="libz\.1\.dylib\|libstdc++\.6\.dylib\|libSystem\.B\.dylib"
fi
if [[ -z "$white_list" || -z "$dump_cmd" ]]; then
fail "Unsupported platform $OS-$ARCH."
fi
echo "Checking for expected dependencies ..."
eval $dump_cmd | grep -i "$white_list" || fail "doesn't show any expected dependencies"
echo "Checking for unexpected dependencies ..."
eval $dump_cmd | grep -i -v "$white_list"
ret=$?
if [[ $ret == 0 ]]; then
fail "found unexpected dependencies (listed above)."
elif [[ $ret != 1 ]]; then
fail "Error when checking dependencies."
fi # grep returns 1 when "not found", which is what we expect
echo "Dependencies look good."
echo
}
############################################################################
echo "Building protoc, OS=$OS ARCH=$ARCH TARGET=$BAZEL_TARGET"
BAZEL_ARGS=("--dynamic_mode=off" "--compilation_mode=opt" "--copt=-g0" "--copt=-fpic")
if [[ "$OS" == windows ]]; then
BAZEL_TARGET="${BAZEL_TARGET}.exe"
fi
if [[ "$(uname)" == CYGWIN* ]]; then
assertEq "$OS" windows $LINENO
# Use mingw32 compilers because executables produced by Cygwin compiler
# always have dependency on Cygwin DLL.
if [[ "$ARCH" == x86_64 ]]; then
CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32"
elif [[ "$ARCH" == x86_32 ]]; then
CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-pc-mingw32"
else
fail "Unsupported arch by CYGWIN: $ARCH"
fi
elif [[ "$(uname)" == MINGW32* ]]; then
assertEq "$OS" windows $LINENO
assertEq "$ARCH" x86_32 $LINENO
elif [[ "$(uname)" == MINGW64* ]]; then
assertEq "$OS" windows $LINENO
assertEq "$ARCH" x86_64 $LINENO
elif [[ "$(uname)" == Linux* ]]; then
if [[ "$OS" == linux ]]; then
BAZEL_ARGS+=("--config=linux-$ARCH")
elif [[ "$OS" == windows ]]; then
# Cross-compilation for Windows
if [[ "$ARCH" == x86_64 ]]; then
BAZEL_ARGS+=("--config=win64")
elif [[ "$ARCH" == x86_32 ]]; then
BAZEL_ARGS+=("--config=win32")
else
fail "Unsupported arch: $ARCH"
fi
else
fail "Cannot build $OS on $(uname)"
fi
elif [[ "$(uname)" == Darwin* ]]; then
assertEq "$OS" osx $LINENO
# Make the binary compatible with OSX 10.7 and later
BAZEL_ARGS+=("--config=osx-$ARCH" "--macos_minimum_os=10.7")
else
fail "Unsupported system: $(uname)"
fi
# Nested double quotes are unintuitive, but it works.
cd "$(dirname "$0")"
WORKING_DIR="$(pwd)"
TARGET_FILE="target/$OS/$ARCH/$BAZEL_TARGET.exe"
DOCKER_IMAGE=gcr.io/protobuf-build/bazel/linux@sha256:2bfd061284eff8234f2fcca16d71d43c69ccf3a22206628b54c204a6a9aac277
tmpfile=$(mktemp -u) &&
docker run --cidfile $tmpfile -v $WORKING_DIR/../../..:/workspace $DOCKER_IMAGE \
build //:$BAZEL_TARGET "${BAZEL_ARGS[@]}" &&
mkdir -p $(dirname $TARGET_FILE) &&
docker cp \
`cat $tmpfile`:/workspace/bazel-bin/$BAZEL_TARGET $TARGET_FILE || exit 1
if [[ "$OS" == osx ]]; then
# Since Mac linker doesn't accept "-s", we need to run strip
strip $TARGET_FILE || exit 1
fi
checkArch $TARGET_FILE && checkDependencies $TARGET_FILE

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# This is not the source of truth for release protoc executables, and will soon
# be deprecated.
set -ex
# Change to repo root.
cd $(dirname $0)/../../../..
GIT_REPO_ROOT=$(pwd)
# Initialize any submodules.
git submodule update --init --recursive
# Cross-build for aarch64, ppc64le and s390x. Note: we do these builds first to avoid
# file permission issues. The Docker builds will create directories owned by
# root, which causes problems if we try to add new artifacts to those
# directories afterward.
kokoro/release/protoc/build-protoc.sh linux aarch_64 protoc
kokoro/release/protoc/build-protoc.sh linux ppcle_64 protoc
kokoro/release/protoc/build-protoc.sh linux s390_64 protoc
kokoro/release/protoc/build-protoc.sh linux x86_64 protoc
kokoro/release/protoc/build-protoc.sh linux x86_32 protoc

View File

@@ -0,0 +1,7 @@
build_file: "protobuf/kokoro/release/protoc/linux/build.sh"
action {
define_artifacts {
regex: "**/protoc.exe"
}
}

View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -ex
CXXFLAGS_COMMON="-std=c++14 -DNDEBUG -mmacosx-version-min=10.9"
cd github/protobuf
bazel build //:protoc --dynamic_mode=off
mkdir -p build64/src
cp bazel-bin/protoc build64/src/protoc
file bazel-bin/protoc
otool -L bazel-bin/protoc | grep dylib

View File

@@ -0,0 +1,8 @@
# Configuration for Mac OSX protoc release builds
build_file: "protobuf/kokoro/release/protoc/macos/build.sh"
action {
define_artifacts {
regex: "**/protoc"
}
}

View File

@@ -0,0 +1,35 @@
set generator32=Visual Studio 15
set generator64=Visual Studio 15 Win64
set vcplatform32=win32
set vcplatform64=x64
set configuration=Release
:: VS2017 is installed, but will not be selected by default. This command sets
:: up the environment so that CMake will find and use it:
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
echo Building protoc
cd github\protobuf
echo Update Submodules
echo This is needed because this build uses CMake <3.13.
git submodule update --init --recursive
set ABSL_ROOT_DIR=%cd%\third_party\abseil-cpp
mkdir build32
cd build32
cmake -G "%generator32%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON ..
msbuild protobuf.sln /p:Platform=%vcplatform32% || goto error
cd ..
mkdir build64
cd build64
cmake -G "%generator64%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON ..
msbuild protobuf.sln /p:Platform=%vcplatform64% || goto error
cd ..
goto :EOF
:error
echo Failed!
exit /b %ERRORLEVEL%

View File

@@ -0,0 +1,8 @@
# Configuration for Windows protoc release builds
build_file: "protobuf/kokoro/release/protoc/windows/build.bat"
action {
define_artifacts {
regex: "**/protoc.exe"
}
}