Skip to content

Commit

Permalink
Mac now build with UE embedded OpenSSL
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomoravec authored Jun 25, 2019
1 parent ead2259 commit a7d6aea
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions Setup.command
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GRPC_FOLDER_NAME=grpc
GRPC_ROOT="${SCRIPT_DIR}/${GRPC_FOLDER_NAME}"

CMAKE_BUILD_DIR="${GRPC_ROOT}/.build"

DEPS=(git automake autoconf libtool make strip clang++ go)
###############################################################################

echo "SCRIPT_DIR=${SCRIPT_DIR}"
echo "GRPC_ROOT=${GRPC_ROOT}"

UE_ROOT=${UE_ROOT:-"/var/lib/jenkins/UE_4.20.2-release"}

if [ ! -d "$UE_ROOT" ]; then
echo "UE_ROOT directory ${UE_ROOT} does not exist, please set correct UE_ROOT"
exit 1
fi;

# Check if all tools are installed
for i in ${DEPS[@]}; do
if [ ! "$(which ${i})" ];then
Expand Down Expand Up @@ -85,21 +94,16 @@ mkdir -p $PROTOBUF_SRC_DIR
cp -R "${GRPC_ROOT}/include" $HEADERS_DIR
cp -R "${GRPC_ROOT}/third_party/protobuf/src" $PROTOBUF_SRC_DIR

# # Build protobuf
PROTOBUF_ROOT=$GRPC_ROOT/third_party/protobuf
echo "PROTOBUF_ROOT=${PROTOBUF_ROOT}"

(cd $PROTOBUF_ROOT && ./autogen.sh)
(cd $PROTOBUF_ROOT && ./configure --disable-shared) # --disable-shared makes protoc static
(cd $PROTOBUF_ROOT && make)

# Export vars (don't know why, but grpc's Makefile does not export therse variables)
export PATH=$PROTOBUF_ROOT/src:$PATH
export LDFLAGS="-L${PROTOBUF_ROOT}/src/.libs -lprotobuf"
export CXXFLAGS="-I${PROTOBUF_ROOT}/src"

# Build GRPC
(cd $GRPC_ROOT && make static)
# Build all
if [ -d "${CMAKE_BUILD_DIR}" ]; then
printf '%s\n' "Removing old ${CMAKE_BUILD_DIR}"
rm -rf "${CMAKE_BUILD_DIR}"
fi
mkdir -p ${CMAKE_BUILD_DIR} && cd ${CMAKE_BUILD_DIR}
echo "BUILD STARTED!"
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES=Release -Dprotobuf_BUILD_TESTS=OFF -DgRPC_ZLIB_PROVIDER=package -DZLIB_INCLUDE_DIR=${UE_ROOT}/Engine/Source/ThirdParty/zlib/v1.2.8/include/Mac -DZLIB_LIBRARY_DEBUG=${UE_ROOT}/Engine/Source/ThirdParty/zlib/v1.2.8/lib/Mac/libz.a -DZLIB_LIBRARY_RELEASE=${UE_ROOT}/Engine/Source/ThirdParty/zlib/v1.2.8/lib/Mac/libz.a -DgRPC_SSL_PROVIDER=package -DLIB_EAY_LIBRARY_DEBUG=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Debug/libcrypto.a -DLIB_EAY_LIBRARY_RELEASE=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Release/libcrypto.a -DLIB_EAY_DEBUG=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Debug/libcrypto.a -DLIB_EAY_RELEASE=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Release/libcrypto.a -DOPENSSL_INCLUDE_DIR=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/include/Mac -DSSL_EAY_DEBUG=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Debug/libssl.a -DSSL_EAY_LIBRARY_DEBUG=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Debug/libssl.a -DSSL_EAY_LIBRARY_RELEASE=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Release/libssl.a -DSSL_EAY_RELEASE=${UE_ROOT}/Engine/Source/ThirdParty/OpenSSL/1.0.2g/lib/Mac/Release/libssl.a
make
cd ${SCRIPT_DIR}

# Copy artifacts
LIBS_DIR="${SCRIPT_DIR}/GrpcLibraries"
Expand All @@ -108,13 +112,8 @@ BIN_DIR="${SCRIPT_DIR}/GrpcPrograms"
echo "LIBS_DIR is ${LIBS_DIR}"
echo "BIN_DIR is ${BIN_DIR}"

if [ $(uname) != 'Darwin' ]; then
ARCH_LIBS_DIR="${LIBS_DIR}/"$(uname)
ARCH_BIN_DIR="${BIN_DIR}/"$(uname)
else
ARCH_LIBS_DIR="${LIBS_DIR}/Mac"
ARCH_BIN_DIR="${BIN_DIR}/Mac"
fi
ARCH_LIBS_DIR="${LIBS_DIR}/Mac"
ARCH_BIN_DIR="${BIN_DIR}/Mac"

echo "ARCH_LIBS_DIR is ${ARCH_LIBS_DIR}"
echo "ARCH_BIN_DIR is ${ARCH_BIN_DIR}"
Expand All @@ -133,37 +132,32 @@ fi
mkdir -p $ARCH_LIBS_DIR
mkdir -p $ARCH_BIN_DIR

SRC_LIBS_FOLDER_GRPC=$GRPC_ROOT/libs/opt
SRC_LIBS_FOLDER_PROTOBUF=$PROTOBUF_ROOT/src/.libs

# Force recursively copy
if [ -d "$SRC_LIBS_FOLDER_PROTOBUF" ]; then
echo "Copying protobuf libraries from ${SRC_LIBS_FOLDER_PROTOBUF} to ${ARCH_LIBS_DIR}"
(cd $SRC_LIBS_FOLDER_PROTOBUF && find . -name '*.a' -exec cp -vf '{}' $ARCH_LIBS_DIR ";")
fi

if [ -d "$SRC_LIBS_FOLDER_GRPC" ]; then
echo "Copying grpc libraries from ${SRC_LIBS_FOLDER_GRPC} to ${ARCH_LIBS_DIR}"
(cd $SRC_LIBS_FOLDER_GRPC && find . -name '*.a' -exec cp -vf '{}' $ARCH_LIBS_DIR ";")
SRC_LIBS_FOLDER=${CMAKE_BUILD_DIR}
echo "SRC_LIBS_FOLDER=${SRC_LIBS_FOLDER}"
if [ -d "$SRC_LIBS_FOLDER" ]; then
echo "Copying grpc libraries from ${SRC_LIBS_FOLDER} to ${ARCH_LIBS_DIR}"
(cd $SRC_LIBS_FOLDER && find . -name '*.a' -exec cp -vf '{}' $ARCH_LIBS_DIR ";")
fi

# Strip all symbols from libraries
(cd $ARCH_LIBS_DIR && strip -S *.a)

# Copy binaries (plugins & protoc)
echo "Copying executables to ${ARCH_BIN_DIR}"
(cp -a "${GRPC_ROOT}/bins/opt/." $ARCH_BIN_DIR)
(cp "${PROTOBUF_ROOT}/src/protoc" $ARCH_BIN_DIR)
cp ${SRC_LIBS_FOLDER}/grpc_cpp_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_csharp_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_node_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_objective_c_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_php_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_python_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/grpc_ruby_plugin ${ARCH_BIN_DIR}/
cp ${SRC_LIBS_FOLDER}/third_party/protobuf/protoc ${ARCH_BIN_DIR}/

# This seems to be a hack, should modify (cp -a "${GRPC_ROOT}/bins/opt/." $BIN_DIR) to copy only files, bot dirs
(cd $ARCH_BIN_DIR && rm -rf protobuf)

#
# Build go support
GOROOT_DIR="${GRPC_ROOT}/go_packages"
GOPROTO_DIR="${GOROOT_DIR}/src/github.com/golang/protobuf"

echo "Building golang support in ${GOPROTO_DIR}"

if [ ! -d "${GOPROTO_DIR}" ]; then
(cd $GRPC_ROOT && git clone $GOSUPPORT_REMOTE_ORIGIN $GOPROTO_DIR)
else
Expand All @@ -173,13 +167,11 @@ fi
# Add gopath with protobuf libs
export GOPATH=$GOROOT_DIR

#
# Run go build
(cd "${GOPROTO_DIR}/protoc-gen-go" && go build)
(cp "${GOPROTO_DIR}/protoc-gen-go/protoc-gen-go" $ARCH_BIN_DIR)

# Finally, strip binaries (programs)
(cd $ARCH_BIN_DIR && strip -S *)

# Copy source
echo 'BUILD DONE!'

0 comments on commit a7d6aea

Please sign in to comment.