Upgrade Protobuf C++ to 22.5 (#11961)

This commit is contained in:
Kannan J 2025-05-23 06:54:14 +00:00 committed by GitHub
parent 9406d3b2a0
commit 46485c8b62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 208 additions and 68 deletions

View File

@ -44,11 +44,11 @@ This section is only necessary if you are making changes to the code
generation. Most users only need to use `skipCodegen=true` as discussed above.
### Build Protobuf
The codegen plugin is C++ code and requires protobuf 21.7 or later.
The codegen plugin is C++ code and requires protobuf 22.5 or later.
For Linux, Mac and MinGW:
```
$ PROTOBUF_VERSION=21.7
$ PROTOBUF_VERSION=22.5
$ curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz
$ tar xzf protobuf-all-$PROTOBUF_VERSION.tar.gz
$ cd protobuf-$PROTOBUF_VERSION

View File

@ -27,7 +27,11 @@ RUN mkdir -p "$ANDROID_HOME/cmdline-tools" && \
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest" && \
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses
RUN curl -Ls https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz | \
tar xz -C /var/local
# Install Maven
RUN curl -Ls https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz | \
tar xz -C /var/local
ENV PATH /var/local/apache-maven-3.8.8/bin:$PATH
ENV PATH /var/local/cmake-3.26.3-linux-x86_64/bin:/var/local/apache-maven-3.8.8/bin:$PATH

View File

@ -10,5 +10,11 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
g++-aarch64-linux-gnu \
g++-powerpc64le-linux-gnu \
openjdk-8-jdk \
pkg-config \
&& \
rm -rf /var/lib/apt/lists/*
RUN curl -Ls https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz | \
tar xz -C /var/local
ENV PATH /var/local/cmake-3.26.3-linux-x86_64/bin:$PATH

View File

@ -9,5 +9,11 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
curl \
g++-s390x-linux-gnu \
openjdk-8-jdk \
pkg-config \
&& \
rm -rf /var/lib/apt/lists/*
RUN curl -Ls https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz | \
tar xz -C /var/local
ENV PATH /var/local/cmake-3.26.3-linux-x86_64/bin:$PATH

View File

@ -7,8 +7,8 @@ set -exu -o pipefail
cd github/grpc-java
export LDFLAGS=-L/tmp/protobuf/lib
export CXXFLAGS=-I/tmp/protobuf/include
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
export LD_LIBRARY_PATH=/tmp/protobuf/lib
export OS_NAME=$(uname)

View File

@ -9,9 +9,6 @@ BASE_DIR="$(pwd)"
cd "$BASE_DIR/github/grpc-java"
export LDFLAGS=-L/tmp/protobuf/lib
export CXXFLAGS=-I/tmp/protobuf/include
export LD_LIBRARY_PATH=/tmp/protobuf/lib
export OS_NAME=$(uname)
cat <<EOF >> gradle.properties
@ -30,10 +27,18 @@ unzip -qd "${ANDROID_HOME}/cmdline-tools" cmdline.zip
rm cmdline.zip
mv "${ANDROID_HOME}/cmdline-tools/cmdline-tools" "${ANDROID_HOME}/cmdline-tools/latest"
(yes || true) | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses
curl -Ls https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.tar.gz | \
tar xz -C /tmp
export PATH=/tmp/cmake-3.26.3-linux-x86_64/bin:$PATH
# Proto deps
buildscripts/make_dependencies.sh
sudo apt-get update && sudo apt-get install pkg-config
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
export LD_LIBRARY_PATH=/tmp/protobuf/lib
# Build Android with Java 11, this adds it to the PATH
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
# Unset any existing JAVA_HOME env var to stop Gradle from using it
@ -98,6 +103,7 @@ cd $BASE_DIR/github/grpc-java
./gradlew clean
git checkout HEAD^
./gradlew --stop # use a new daemon to build the previous commit
GRADLE_FLAGS="${GRADLE_FLAGS} -PskipCodegen=true" # skip codegen for build from previous commit since it wasn't built with --std=c++14 when making this change
./gradlew publishToMavenLocal $GRADLE_FLAGS
cd examples/android/helloworld/
../../gradlew build $GRADLE_FLAGS

View File

@ -51,9 +51,9 @@ fi
export GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
# Make protobuf discoverable by :grpc-compiler
export LD_LIBRARY_PATH=/tmp/protobuf/lib
export LDFLAGS=-L/tmp/protobuf/lib
export CXXFLAGS="-I/tmp/protobuf/include"
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
export LIBRARY_PATH=/tmp/protobuf/lib
./gradlew grpc-compiler:clean $GRADLE_FLAGS

View File

@ -2,7 +2,7 @@
# Location of the continuous shell script in repository.
build_file: "grpc-java/buildscripts/kokoro/windows.bat"
timeout_mins: 45
timeout_mins: 90
# We always build mvn artifacts.
action {

View File

@ -15,19 +15,21 @@ set ESCWORKSPACE=%WORKSPACE:\=\\%
@rem Clear JAVA_HOME to prevent a different Java version from being used
set JAVA_HOME=
set PATH=C:\Program Files\OpenJDK\openjdk-11.0.12_7\bin;%PATH%
mkdir grpc-java-helper32
cd grpc-java-helper32
call "%VS140COMNTOOLS%\vsvars32.bat" || exit /b 1
call "%VS170COMNTOOLS%\..\..\VC\Auxiliary\Build\vcvars32.bat" || exit /b 1
call "%WORKSPACE%\buildscripts\make_dependencies.bat" || exit /b 1
cd "%WORKSPACE%"
SET TARGET_ARCH=x86_32
SET FAIL_ON_WARNINGS=true
SET VC_PROTOBUF_LIBS=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\build\\Release
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\build\\include
SET PROTOBUF_VER=22.5
SET PKG_CONFIG_PATH=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\lib\\pkgconfig
SET VC_PROTOBUF_LIBS=/LIBPATH:%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\lib
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper32\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\include
call :Get_Libs
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE% -PskipAndroid=true
SET GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
@ -50,3 +52,32 @@ IF NOT %GRADLEEXIT% == 0 (
cmd.exe /C "%WORKSPACE%\gradlew.bat --stop"
cmd.exe /C "%WORKSPACE%\gradlew.bat %GRADLE_FLAGS% -Dorg.gradle.parallel=false -PrepositoryDir=%WORKSPACE%\artifacts clean grpc-compiler:build grpc-compiler:publish" || exit /b 1
goto :eof
:Get_Libs
SetLocal EnableDelayedExpansion
set "libs_list="
for /f "tokens=*" %%a in ('pkg-config --libs protobuf') do (
for %%b in (%%a) do (
set lib=%%b
set libfirst2char=!lib:~0,2!
if !libfirst2char!==-l (
@rem remove the leading -l
set lib=!lib:~2!
@rem remove spaces
set lib=!lib: =!
@rem Because protobuf is specified as libprotobuf and elsewhere
if !lib! NEQ protobuf (
set lib=!lib!.lib
if "!libs_list!"=="" (
set libs_list=!lib!
) else (
set libs_list=!libs_list!,!lib!
)
)
)
)
)
EndLocal & set "VC_PROTOBUF_LIBS=%VC_PROTOBUF_LIBS%,%libs_list%"
exit /b 0

View File

@ -14,19 +14,21 @@ set ESCWORKSPACE=%WORKSPACE:\=\\%
@rem Clear JAVA_HOME to prevent a different Java version from being used
set JAVA_HOME=
set PATH=C:\Program Files\OpenJDK\openjdk-11.0.12_7\bin;%PATH%
mkdir grpc-java-helper64
cd grpc-java-helper64
call "%VS140COMNTOOLS%\..\..\VC\bin\amd64\vcvars64.bat" || exit /b 1
call "%VS170COMNTOOLS%\..\..\VC\Auxiliary\Build\vcvars64.bat" || exit /b 1
call "%WORKSPACE%\buildscripts\make_dependencies.bat" || exit /b 1
cd "%WORKSPACE%"
SET TARGET_ARCH=x86_64
SET FAIL_ON_WARNINGS=true
SET VC_PROTOBUF_LIBS=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\build\\Release
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\build\\include
SET PROTOBUF_VER=22.5
SET PKG_CONFIG_PATH=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\lib\\pkgconfig
SET VC_PROTOBUF_LIBS=/LIBPATH:%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\lib
SET VC_PROTOBUF_INCLUDE=%ESCWORKSPACE%\\grpc-java-helper64\\protobuf-%PROTOBUF_VER%\\build\\protobuf-%PROTOBUF_VER%\\include
call :Get_Libs
SET GRADLE_FLAGS=-PtargetArch=%TARGET_ARCH% -PfailOnWarnings=%FAIL_ON_WARNINGS% -PvcProtobufLibs=%VC_PROTOBUF_LIBS% -PvcProtobufInclude=%VC_PROTOBUF_INCLUDE% -PskipAndroid=true
SET GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
@ -34,3 +36,32 @@ SET GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'"
cmd.exe /C "%WORKSPACE%\gradlew.bat --stop"
cmd.exe /C "%WORKSPACE%\gradlew.bat %GRADLE_FLAGS% -Dorg.gradle.parallel=false -PrepositoryDir=%WORKSPACE%\artifacts grpc-compiler:clean grpc-compiler:build grpc-compiler:publish" || exit /b 1
goto :eof
:Get_Libs
SetLocal EnableDelayedExpansion
set "libs_list="
for /f "tokens=*" %%a in ('pkg-config --libs protobuf') do (
for %%b in (%%a) do (
set lib=%%b
set libfirst2char=!lib:~0,2!
if !libfirst2char!==-l (
@rem remove the leading -l
set lib=!lib:~2!
@rem remove spaces
set lib=!lib: =!
@rem Because protobuf is specified as libprotobuf and elsewhere
if !lib! NEQ protobuf (
set lib=!lib!.lib
if "!libs_list!"=="" (
set libs_list=!lib!
) else (
set libs_list=!libs_list!,!lib!
)
)
)
)
)
EndLocal & set "VC_PROTOBUF_LIBS=%VC_PROTOBUF_LIBS%,%libs_list%"
exit /b 0

View File

@ -1,12 +1,16 @@
set PROTOBUF_VER=21.7
set CMAKE_NAME=cmake-3.3.2-win32-x86
choco install -y pkgconfiglite
choco install -y openjdk --version=17.0
set PATH=%PATH%;"c:\Program Files\OpenJDK\jdk-17\bin"
set PROTOBUF_VER=22.5
set ABSL_VERSION=20230125.4
set CMAKE_NAME=cmake-3.26.3-windows-x86_64
if not exist "protobuf-%PROTOBUF_VER%\build\Release\" (
call :installProto || exit /b 1
)
echo Compile gRPC-Java with something like:
echo -PtargetArch=x86_32 -PvcProtobufLibs=%cd%\protobuf-%PROTOBUF_VER%\build\Release -PvcProtobufInclude=%cd%\protobuf-%PROTOBUF_VER%\build\include
echo -PtargetArch=x86_32 -PvcProtobufLibPath=%cd%\protobuf-%PROTOBUF_VER%\build\protobuf-%PROTOBUF_VER%\lib -PvcProtobufInclude=%cd%\protobuf-%PROTOBUF_VER%\build\protobuf-%PROTOBUF_VER%\include -PvcProtobufLibs=insert-list-of-libs-from-pkg-config-output-here
goto :eof
@ -20,25 +24,35 @@ if not exist "%CMAKE_NAME%" (
set PATH=%PATH%;%cd%\%CMAKE_NAME%\bin
:hasCmake
@rem GitHub requires TLSv1.2, and for whatever reason our powershell doesn't have it enabled
powershell -command "$ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/archive/v%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
powershell -command "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/google/protobuf/releases/download/v%PROTOBUF_VER%/protobuf-%PROTOBUF_VER%.zip -OutFile protobuf.zip }" || exit /b 1
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('protobuf.zip', '.') }" || exit /b 1
del protobuf.zip
powershell -command "$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'stop'; & { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; iwr https://github.com/abseil/abseil-cpp/archive/refs/tags/%ABSL_VERSION%.zip -OutFile absl.zip }" || exit /b 1
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('absl.zip', '.') }" || exit /b 1
del absl.zip
rmdir protobuf-%PROTOBUF_VER%\third_party\abseil-cpp
move abseil-cpp-%ABSL_VERSION% protobuf-%PROTOBUF_VER%\third_party\abseil-cpp
mkdir protobuf-%PROTOBUF_VER%\build
pushd protobuf-%PROTOBUF_VER%\build
@rem Workaround https://github.com/protocolbuffers/protobuf/issues/10174
powershell -command "(Get-Content ..\cmake\extract_includes.bat.in) -replace '\.\.\\', '' | Out-File -encoding ascii ..\cmake\extract_includes.bat.in"
@rem cmake does not detect x86_64 from the vcvars64.bat variables.
@rem If vcvars64.bat has set PLATFORM to X64, then inform cmake to use the Win64 version of VS
if "%PLATFORM%" == "X64" (
@rem Note the space
SET CMAKE_VSARCH= Win64
@rem If vcvars64.bat has set PLATFORM to X64, then inform cmake to use the Win64 version of VS, likewise for x32
if "%PLATFORM%" == "x64" (
SET CMAKE_VSARCH=-A x64
) else if "%PLATFORM%" == "x86" (
@rem -A x86 doesn't work: https://github.com/microsoft/vcpkg/issues/15465
SET CMAKE_VSARCH=-DCMAKE_GENERATOR_PLATFORM=WIN32
) else (
SET CMAKE_VSARCH=
)
cmake -Dprotobuf_BUILD_TESTS=OFF -G "Visual Studio %VisualStudioVersion:~0,2%%CMAKE_VSARCH%" .. || exit /b 1
msbuild /maxcpucount /p:Configuration=Release /verbosity:minimal libprotoc.vcxproj || exit /b 1
call extract_includes.bat || exit /b 1
for /f "tokens=4 delims=\" %%a in ("%VCINSTALLDIR%") do (
SET VC_YEAR=%%a
)
for /f "tokens=1 delims=." %%a in ("%VisualStudioVersion%") do (
SET visual_studio_major_version=%%a
)
cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=%cd%\protobuf-%PROTOBUF_VER% -DCMAKE_PREFIX_PATH=%cd%\protobuf-%PROTOBUF_VER% -G "Visual Studio %visual_studio_major_version% %VC_YEAR%" %CMAKE_VSARCH% .. || exit /b 1
cmake --build . --config Release --target install || exit /b 1
popd
goto :eof
@ -49,3 +63,4 @@ powershell -command "$ErrorActionPreference = 'stop'; & { iwr https://cmake.org/
powershell -command "$ErrorActionPreference = 'stop'; & { Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('cmake.zip', '.') }" || exit /b 1
del cmake.zip
goto :eof

View File

@ -3,13 +3,17 @@
# Build protoc
set -evux -o pipefail
PROTOBUF_VERSION=21.7
PROTOBUF_VERSION=22.5
ABSL_VERSION=20230125.4
CMAKE_VERSION=3.26.3
# ARCH is x86_64 bit unless otherwise specified.
ARCH="${ARCH:-x86_64}"
DOWNLOAD_DIR=/tmp/source
INSTALL_DIR="/tmp/protobuf-cache/$PROTOBUF_VERSION/$(uname -s)-$ARCH"
BUILDSCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
mkdir -p $DOWNLOAD_DIR
cd "$DOWNLOAD_DIR"
# Start with a sane default
NUM_CPU=4
@ -26,27 +30,46 @@ if [ -f ${INSTALL_DIR}/bin/protoc ]; then
echo "Not building protobuf. Already built"
# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
else
if [[ ! -d "$DOWNLOAD_DIR"/protobuf-"${PROTOBUF_VERSION}" ]]; then
curl -Ls https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-all-${PROTOBUF_VERSION}.tar.gz | tar xz -C $DOWNLOAD_DIR
fi
pushd $DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}
# install here so we don't need sudo
if [[ "$ARCH" == x86* ]]; then
./configure CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} --disable-shared \
--prefix="$INSTALL_DIR"
elif [[ "$ARCH" == aarch* ]]; then
./configure --disable-shared --host=aarch64-linux-gnu --prefix="$INSTALL_DIR"
elif [[ "$ARCH" == ppc* ]]; then
./configure --disable-shared --host=powerpc64le-linux-gnu --prefix="$INSTALL_DIR"
elif [[ "$ARCH" == s390* ]]; then
./configure --disable-shared --host=s390x-linux-gnu --prefix="$INSTALL_DIR"
elif [[ "$ARCH" == loongarch* ]]; then
./configure --disable-shared --host=loongarch64-unknown-linux-gnu --prefix="$INSTALL_DIR"
if [[ ! -d "protobuf-${PROTOBUF_VERSION}" ]]; then
curl -Ls "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz" | tar xz
curl -Ls "https://github.com/abseil/abseil-cpp/archive/refs/tags/${ABSL_VERSION}.tar.gz" | tar xz
rmdir "protobuf-$PROTOBUF_VERSION/third_party/abseil-cpp"
mv "abseil-cpp-$ABSL_VERSION" "protobuf-$PROTOBUF_VERSION/third_party/abseil-cpp"
fi
# the same source dir is used for 32 and 64 bit builds, so we need to clean stale data first
make clean
make V=0 -j$NUM_CPU
make install
rm -rf "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
mkdir "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
pushd "$DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}/build"
# install here so we don't need sudo
if [[ "$ARCH" == x86* ]]; then
CFLAGS=-m${ARCH#*_} CXXFLAGS=-m${ARCH#*_} cmake .. \
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
-B. || exit 1
else
if [[ "$ARCH" == aarch_64 ]]; then
GCC_ARCH=aarch64-linux-gnu
elif [[ "$ARCH" == ppcle_64 ]]; then
GCC_ARCH=powerpc64le-linux-gnu
elif [[ "$ARCH" == s390_64 ]]; then
GCC_ARCH=s390x-linux-gnu
elif [[ "$ARCH" == loongarch_64 ]]; then
GCC_ARCH=loongarch64-unknown-linux-gnu
else
echo "Unknown architecture: $ARCH"
exit 1
fi
cmake .. \
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
-Dcrosscompile_ARCH="$GCC_ARCH" \
-DCMAKE_TOOLCHAIN_FILE=$BUILDSCRIPTS_DIR/toolchain.cmake \
-B. || exit 1
fi
export CMAKE_BUILD_PARALLEL_LEVEL="$NUM_CPU"
cmake --build . || exit 1
cmake --install . || exit 1
[ -d "$INSTALL_DIR/lib64" ] && mv "$INSTALL_DIR/lib64" "$INSTALL_DIR/lib"
popd
fi
@ -60,7 +83,8 @@ ln -s "$INSTALL_DIR" /tmp/protobuf
cat <<EOF
To compile with the build dependencies:
export LDFLAGS=-L/tmp/protobuf/lib
export CXXFLAGS=-I/tmp/protobuf/include
export LDFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --libs protobuf)"
export CXXFLAGS="$(PKG_CONFIG_PATH=/tmp/protobuf/lib/pkgconfig pkg-config --cflags protobuf)"
export LIBRARY_PATH=/tmp/protobuf/lib
export LD_LIBRARY_PATH=/tmp/protobuf/lib
EOF

View File

@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER "${crosscompile_ARCH}-gcc")
set(CMAKE_CXX_COMPILER "${crosscompile_ARCH}-g++")
set(CMAKE_FIND_ROOT_PATH "/usr/${crosscompile_ARCH}/")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -100,19 +100,20 @@ model {
all {
if (toolChain in Gcc || toolChain in Clang) {
cppCompiler.define("GRPC_VERSION", version)
cppCompiler.args "--std=c++0x"
cppCompiler.args "--std=c++14"
addEnvArgs("CXXFLAGS", cppCompiler.args)
addEnvArgs("CPPFLAGS", cppCompiler.args)
if (osdetector.os == "osx") {
cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++"
linker.args "-framework", "CoreFoundation"
addLibraryIfNotLinked('protoc', linker.args)
addLibraryIfNotLinked('protobuf', linker.args)
} else if (osdetector.os == "windows") {
linker.args "-static", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++",
"-s"
} else if (osdetector.arch == "ppcle_64") {
linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-Wl,-Bdynamic", "-lpthread", "-s"
} else {
} else if (osdetector.arch == "ppcle_64") {
linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-Wl,-Bdynamic", "-lpthread", "-s"
} else {
// Link protoc, protobuf, libgcc and libstdc++ statically.
// Link other (system) libraries dynamically.
// Clang under OSX doesn't support these options.
@ -126,10 +127,12 @@ model {
cppCompiler.args "/EHsc", "/MT"
if (rootProject.hasProperty('vcProtobufInclude')) {
cppCompiler.args "/I${rootProject.vcProtobufInclude}"
}
linker.args "libprotobuf.lib", "libprotoc.lib"
}
linker.args.add("libprotoc.lib")
linker.args.add("libprotobuf.lib")
if (rootProject.hasProperty('vcProtobufLibs')) {
linker.args "/LIBPATH:${rootProject.vcProtobufLibs}"
String libsList = rootProject.property('vcProtobufLibs') as String
libsList.split(',').each() { lib -> linker.args.add(lib) }
}
}
}
@ -242,9 +245,10 @@ def checkArtifacts = tasks.register("checkArtifacts") {
if (ret.exitValue != 0) {
throw new GradleException("dumpbin exited with " + ret.exitValue)
}
def dlls = os.toString() =~ /Image has the following dependencies:\s+(.*)\s+Summary/
if (dlls[0][1] != "KERNEL32.dll") {
throw new Exception("unexpected dll deps: " + dlls[0][1]);
def dlls_match_results = os.toString() =~ /Image has the following dependencies:([\S\s]*)Summary/
def dlls = dlls_match_results[0][1].trim().split("\\s+").sort()
if (dlls != ["KERNEL32.dll", "dbghelp.dll"]) {
throw new Exception("unexpected dll deps: " + dlls);
}
os.reset()
ret = exec {

View File

@ -114,7 +114,7 @@ checkDependencies ()
white_list="KERNEL32\.dll\|msvcrt\.dll\|USER32\.dll"
elif [[ "$OS" == linux ]]; then
dump_cmd='objdump -x '"$1"' | grep "NEEDED"'
white_list="libpthread\.so\.0\|libstdc++\.so\.6\|libc\.so\.6"
white_list="libpthread\.so\.0\|libstdc++\.so\.6\|libc\.so\.6\|librt\.so\.1\|libm\.so\.6"
if [[ "$ARCH" == x86_32 ]]; then
white_list="${white_list}\|libm\.so\.6"
elif [[ "$ARCH" == x86_64 ]]; then

View File

@ -25,6 +25,7 @@ import io.grpc.okhttp.internal.ConnectionSpec;
import io.grpc.okhttp.internal.TlsVersion;
import java.net.Socket;
import java.util.List;
import java.util.Locale;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@ -95,6 +96,9 @@ public class UtilsTest {
assertEquals("5000", socketOptions.others.get("SO_SNDBUF"));
assertEquals("true", socketOptions.others.get("SO_KEEPALIVE"));
assertEquals("true", socketOptions.others.get("SO_OOBINLINE"));
assertEquals("8", socketOptions.others.get("IP_TOS"));
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (!osName.startsWith("windows")) {
assertEquals("8", socketOptions.others.get("IP_TOS"));
}
}
}