Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Jing Vincent Yan <yyan82@bloomberg.net>
  • Loading branch information
kaikulimu committed Aug 3, 2023
1 parent cc5e65a commit 9e3c449
Showing 1 changed file with 55 additions and 27 deletions.
82 changes: 55 additions & 27 deletions bin/build-darwin.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# This script buildd BlazingMQ and all of its dependencies.
# This script builds BlazingMQ and all of its dependencies.
#
# Required prerequisites:
# - git
Expand All @@ -11,21 +11,23 @@
# - pkg-config
# - Homebrew


set -e
set -u
set -x
[ -z $BASH ] || shopt -s expand_aliases


# :: Set some initial constants :::::::::::::::::::::::::::::::::::::::::::::::
DIR_ROOT="${DIR_ROOT:-`pwd`}"

DIR_THIRDPARTY="${DIR_ROOT}/thirdparty"
mkdir -p "${DIR_THIRDPARTY}"

DIR_BUILD="${DIR_BUILD:-${DIR_ROOT}/build}"
mkdir -p "${DIR_BUILD}"

# :: Download source-code of our dependencies :::::::::::::::::::::::::::::::::
if [ ! -d "${DIR_ROOT}/blazingmq" ]; then
git clone https://github.com/bloomberg/blazingmq.git
fi

# :: Clone dependencies :::::::::::::::::::::::::::::::::::::::::::::::::::::::
if [ ! -d "${DIR_THIRDPARTY}/bde-tools" ]; then
git clone https://github.com/bloomberg/bde-tools "${DIR_THIRDPARTY}/bde-tools"
fi
Expand All @@ -36,36 +38,49 @@ if [ ! -d "${DIR_THIRDPARTY}/ntf-core" ]; then
git clone https://github.com/bloomberg/ntf-core.git "${DIR_THIRDPARTY}/ntf-core"
fi

DIR_BUILD="${DIR_ROOT}/blazingmq/cmake.bld/`uname`"
mkdir -p ${DIR_BUILD}


# :: Install required packages ::::::::::::::::::::::::::::::::::::::::::::::::

# Build and install BDE
# Refer to https://bloomberg.github.io/bde/library_information/build.html
PATH="${DIR_THIRDPARTY}/bde-tools/bin:$PATH"

pushd ${DIR_THIRDPARTY}/bde
eval `bbs_build_env -u opt_64_cpp17 -b "${DIR_BUILD}/bde"`
bbs_build configure --prefix="${DIR_ROOT}"
bbs_build build --prefix=""${DIR_ROOT}
bbs_build --install_dir="/" --prefix="${DIR_ROOT}" install
eval `bbs_build_env unset`
popd

# Build and install NTF
pushd ${DIR_THIRDPARTY}/ntf-core
./configure --prefix "${DIR_ROOT}" --output "${DIR_BUILD}/ntf"
make
make install
popd
if [ ! -e "${DIR_BUILD}/bde/.complete" ]; then
pushd "${DIR_THIRDPARTY}/bde"
eval `bbs_build_env -u opt_64_cpp17 -b "${DIR_BUILD}/bde"`
bbs_build configure --prefix="${DIR_ROOT}"
bbs_build build --prefix="${DIR_ROOT}"
bbs_build --install_dir="/" --prefix="${DIR_ROOT}" install
eval `bbs_build_env unset`
popd
touch "${DIR_BUILD}/bde/.complete"
fi

if [ ! -e "${DIR_BUILD}/ntf/.complete" ]; then
# Build and install NTF
pushd "${DIR_THIRDPARTY}/ntf-core"
./configure --prefix "${DIR_ROOT}" --output "${DIR_BUILD}/ntf"
make -j 16
make install
popd
touch "${DIR_BUILD}/ntf/.complete"
fi


# Build other dependencies
brew install flex bison google-benchmark zlib

# Determine paths based on Intel vs Apple Silicon CPU
if [ $(uname -p) == 'arm' ]; then
BREW_PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:/opt/homebrew/opt/zlib/lib/pkgconfig"
FLEX_ROOT="/opt/homebrew/opt/flex"
else
BREW_PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/opt/zlib/lib/pkgconfig"
FLEX_ROOT="/usr/local/opt/flex"
fi


# :: Build the BMQ repo :::::::::::::::::::::::::::::::::::::::::::::::::::::::
# :: Build the BlazingMQ repo :::::::::::::::::::::::::::::::::::::::::::::::::
CMAKE_OPTIONS="\
-DBUILD_BITNESS=64 \
-DCMAKE_BUILD_TYPE=Debug \
Expand All @@ -75,8 +90,21 @@ CMAKE_OPTIONS="\
-DCMAKE_PREFIX_PATH=${DIR_ROOT} \
-DCMAKE_TOOLCHAIN_FILE=${DIR_THIRDPARTY}/bde-tools/BdeBuildSystem/toolchains/darwin/gcc-default.cmake \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DFLEX_ROOT=${FLEX_ROOT}"

PKG_CONFIG_PATH="${DIR_ROOT}/lib/pkgconfig:/opt/homebrew/lib/pkgconfig:/opt/homebrew/opt/zlib/lib/pkgconfig" \
cmake -B "${DIR_BUILD}/blazingmq" -S "${DIR_ROOT}/blazingmq" ${CMAKE_OPTIONS} -DFLEX_ROOT=/opt/homebrew/opt/flex
PKG_CONFIG_PATH="${DIR_ROOT}/lib/pkgconfig:${BREW_PKG_CONFIG_PATH}" \
cmake -B "${DIR_BUILD}/blazingmq" -S "${DIR_ROOT}" ${CMAKE_OPTIONS}
make -C "${DIR_BUILD}/blazingmq" -j 16

echo broker is here: "${DIR_BUILD}/blazingmq/src/applications/bmqbrkr/bmqbrkr.tsk"
echo to run the broker: "cd ${DIR_BUILD}/blazingmq/src/applications/bmqbrkr ; ./run"
echo tool is here: "${DIR_BUILD}/blazingmq/src/applications/bmqtool/bmqtool.tsk"

SELF_HOST_ADDRESS="127.0.0.1 `hostname`"
if ! (grep -q "$SELF_HOST_ADDRESS" /etc/hosts > /dev/null);
then
echo "Warning: self hostname `hostname` not found in /etc/hosts"
echo "It might be necessary to add it manually to launch bmqbrkr:"
echo "sudo bash -c \"echo \\\"$SELF_HOST_ADDRESS\\\" >> /etc/hosts\""
fi

0 comments on commit 9e3c449

Please sign in to comment.