|
| 1 | +# Copyright (c) 2025 Ember |
| 2 | +# |
| 3 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + |
| 7 | +#!/bin/bash |
| 8 | +set -e |
| 9 | + |
| 10 | +############################################### |
| 11 | +# Install build tools |
| 12 | +# Already pre-installed: (git, cmake, ninja) |
| 13 | +############################################### |
| 14 | +# Force xcode 16.3 or it'll default to 16.0 |
| 15 | +LATEST_XCODE="/Applications/Xcode_16.3.app/Contents/Developer" |
| 16 | +CURRENT_XCODE=$(xcode-select -p) |
| 17 | + |
| 18 | +if [ "$CURRENT_XCODE" != "$LATEST_XCODE" ]; then |
| 19 | + echo "Switching Xcode from $CURRENT_XCODE to $LATEST_XCODE" |
| 20 | + sudo xcode-select -s "$LATEST_XCODE" |
| 21 | +else |
| 22 | + echo "Using the correct Xcode: $LATEST_XCODE" |
| 23 | +fi |
| 24 | + |
| 25 | +brew update |
| 26 | +brew upgrade |
| 27 | +brew install llvm |
| 28 | + |
| 29 | +############################################################# |
| 30 | +# Install dependencies through homebrew |
| 31 | +# (Github macOS runner already come with openssl and zlib) |
| 32 | +############################################################# |
| 33 | +brew install boost |
| 34 | +brew install botan |
| 35 | +brew install mysql-client |
| 36 | +brew install pcre |
| 37 | +brew install flatbuffers |
| 38 | + |
| 39 | +####################################### |
| 40 | +# Install MySQL Connector/C++ |
| 41 | +####################################### |
| 42 | +CACHE_TARBALL="dependencies/mysql-connector.tar.gz" |
| 43 | + |
| 44 | +if [ -f "$CACHE_TARBALL" ]; then |
| 45 | + echo "Cached MySQL Connector tarball found." |
| 46 | +else |
| 47 | + echo "Downloading MySQL Connector/C++ Library from Oracle..." |
| 48 | + sudo mkdir -p dependencies |
| 49 | + sudo wget https://dev.mysql.com/get/Downloads/Connector-C++/mysql-connector-c++-9.3.0-macos15-arm64.tar.gz -O "$CACHE_TARBALL" |
| 50 | +fi |
| 51 | + |
| 52 | +echo "Extracting MySQL Connector tarball..." |
| 53 | +sudo mkdir -p /usr/local/lib/cmake/mysql-concpp |
| 54 | +sudo tar -zxf "$CACHE_TARBALL" -C /usr/local/lib/cmake/mysql-concpp --strip-components=1 |
| 55 | + |
| 56 | +echo "Installing headers and libraries..." |
| 57 | +sudo mkdir -p /usr/local/include/mysql-concpp |
| 58 | +sudo cp -r /usr/local/lib/cmake/mysql-concpp/include/. /usr/local/include/mysql-concpp/ |
| 59 | +sudo cp -r /usr/local/lib/cmake/mysql-concpp/lib64/. /usr/local/lib/ |
| 60 | +echo "MySQL Connector/C++ installed." |
| 61 | + |
| 62 | +echo "Patching MySQL Connector dependencies to reference absolute OpenSSL paths..." |
| 63 | +for libfile in /usr/local/lib/libmysqlcppconn*.dylib; do |
| 64 | + if [ -f "$libfile" ]; then |
| 65 | + sudo install_name_tool -change libssl.3.dylib /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib "$libfile" |
| 66 | + sudo install_name_tool -change libcrypto.3.dylib /opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib "$libfile" |
| 67 | + echo "Patched $libfile" |
| 68 | + fi |
| 69 | +done |
| 70 | + |
| 71 | +############################### |
| 72 | +# Configure and Build Ember |
| 73 | +############################### |
| 74 | +echo "=== Configuring project with CMake ===" |
| 75 | + |
| 76 | +# Set the DYLD_LIBRARY_PATH for all subsequent build and runtime steps. |
| 77 | +export DYLD_LIBRARY_PATH="$(brew --prefix openssl@3)/lib:$DYLD_LIBRARY_PATH" |
| 78 | +echo "DYLD_LIBRARY_PATH set to: $DYLD_LIBRARY_PATH" |
| 79 | + |
| 80 | +C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" |
| 81 | +CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" |
| 82 | + |
| 83 | +CMAKE_C_FLAGS="-isystem /opt/homebrew/opt/llvm/include/c++/v1 -isysroot $(xcrun --show-sdk-path)" |
| 84 | +CMAKE_CXX_FLAGS="-isystem /opt/homebrew/opt/llvm/include/c++/v1 -isysroot $(xcrun --show-sdk-path)" |
| 85 | + |
| 86 | +BUILD_OPTIONAL_TOOLS=-1 |
| 87 | +DISABLE_THREADS=0 |
| 88 | +BUILD_DIR="build" |
| 89 | +INSTALL_DIR="./build/bin" |
| 90 | +BUILD_TYPE="Debug" |
| 91 | + |
| 92 | +cmake -S . -B ${BUILD_DIR} \ |
| 93 | + -DCMAKE_C_COMPILER=${C_COMPILER} \ |
| 94 | + -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \ |
| 95 | + -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" \ |
| 96 | + -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ |
| 97 | + -DCMAKE_OSX_SYSROOT=$(xcrun --show-sdk-path) \ |
| 98 | + -DBUILD_OPT_TOOLS=${BUILD_OPTIONAL_TOOLS} \ |
| 99 | + -DDISABLE_EMBER_THREADS=${DISABLE_THREADS} \ |
| 100 | + -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} |
| 101 | + |
| 102 | +echo "Building and installing the project..." |
| 103 | +cmake --build ${BUILD_DIR} --target install --config ${BUILD_TYPE} |
| 104 | + |
| 105 | +############################################### |
| 106 | +# Run the unit_tests for regression control |
| 107 | +############################################### |
| 108 | +echo "=== Switching to installed directory and running tests ===" |
| 109 | +cd ${INSTALL_DIR} |
| 110 | +if [ -x "./unit_tests" ]; then |
| 111 | + echo "Running installed test executable..." |
| 112 | + # openssl is linked dynamically so we need to point the unit_tests to the library |
| 113 | + sudo install_name_tool -change libssl.3.dylib "$(brew --prefix openssl@3)/lib/libssl.3.dylib" ./unit_tests |
| 114 | + sudo install_name_tool -change libcrypto.3.dylib "$(brew --prefix openssl@3)/lib/libcrypto.3.dylib" ./unit_tests |
| 115 | + sudo -E ./unit_tests |
| 116 | +else |
| 117 | + echo "Error: Installed test executable not found in ${INSTALL_DIR}. Aborting." |
| 118 | + exit 1 |
| 119 | +fi |
| 120 | + |
| 121 | +echo "=== Build, install, and test complete ===" |
0 commit comments