Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions buildscripts/kokoro/unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ ARCH="$ARCH" buildscripts/make_dependencies.sh
# Set properties via flags, do not pollute gradle.properties
GRADLE_FLAGS="${GRADLE_FLAGS:-}"
GRADLE_FLAGS+=" -PtargetArch=$ARCH"

# For universal binaries on macOS, signal Gradle to use universal flags.
if [[ "$(uname -s)" == "Darwin" ]]; then
GRADLE_FLAGS+=" -PbuildUniversal=true"
fi
GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false"
GRADLE_FLAGS+=" -PfailOnWarnings=true"
GRADLE_FLAGS+=" -PerrorProne=true"
Expand Down
8 changes: 7 additions & 1 deletion buildscripts/make_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ else
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
if [[ "$(uname -s)" == "Darwin" ]]; then
cmake .. \
-DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DABSL_INTERNAL_AT_LEAST_CXX17=0 \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-B. || exit 1
elif [[ "$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 \
Expand Down
6 changes: 6 additions & 0 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ model {
cppCompiler.args "--std=c++14"
addEnvArgs("CXXFLAGS", cppCompiler.args)
addEnvArgs("CPPFLAGS", cppCompiler.args)
if (project.hasProperty('buildUniversal') &&
project.getProperty('buildUniversal').toBoolean() &&
osdetector.os == "osx") {
cppCompiler.args "-arch", "arm64", "-arch", "x86_64"
linker.args "-arch", "arm64", "-arch", "x86_64"
}
if (osdetector.os == "osx") {
cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++"
linker.args "-framework", "CoreFoundation"
Expand Down
20 changes: 10 additions & 10 deletions compiler/check-artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ checkArch ()
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
elif [[ "$ARCH" == aarch_64 ]]; then
assertEq "$format" "arm64" $LINENO
else
fail "Unsupported arch: $ARCH"
# For macOS, we now build a universal binary. We check that both
# required architectures are present.
format="$(lipo -archs "$1")"
echo "Architectures found: $format"
if ! echo "$format" | grep -q "x86_64"; then
fail "Universal binary is missing x86_64 architecture."
fi
if ! echo "$format" | grep -q "arm64"; then
fail "Universal binary is missing arm64 architecture."
fi
echo "Universal binary check successful."
else
fail "Unsupported system: $OS"
fi
Expand Down