Skip to content

Building and installing HHVM on OSX 10.9

Korvin Szanto edited this page Dec 13, 2015 · 78 revisions

CheckList

  • CMake >= 3.0.2
  • Using ranlib from /opt/local/bin/ranlib or /usr/bin/ranlib
  • GCC 4.8
  • Boost 1.55+ and is compiled with GCC 4.8
  • JeMalloc compiled with patch.
  • OCaml 3/4 (hack requirement)

Install with MacPorts

Install MacPorts

https://www.macports.org/install.php

Install Pre-built Packages

You may download the pre-built packages here:

http://packages.corneltek.com/pkg

Or add http://packages.corneltek.com/ to your archive_sites.conf

Install Dependencies

port install -vsn boost configure.compiler=macports-gcc-4.8
port install binutils oniguruma5 autoconf automake cmake libvpx \
        libelf tbb libevent pcre \
        libxslt mysql55-connector-cpp \
        elftoolchain google-glog libzip \
        protobuf-c protobuf-cpp ncurses

Install jemalloc with patch

wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
tar xvf jemalloc-3.6.0.tar.bz2
cd jemalloc-3.6.0
 
cat <<END | patch -p0 src/jemalloc.c
diff --git a/src/jemalloc.c b/src/jemalloc.c
index bc350ed..8959959 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -1312,7 +1312,6 @@ je_valloc(size_t size)
 #define        is_malloc_(a) malloc_is_ ## a
 #define        is_malloc(a) is_malloc_(a)
 
-#if ((is_malloc(je_malloc) == 1) && defined(__GLIBC__) && !defined(__UCLIBC__))
 /*
  * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
  * to inconsistently reference libc's malloc(3)-compatible functions
@@ -1325,6 +1324,7 @@ je_valloc(size_t size)
 JEMALLOC_EXPORT void (* __free_hook)(void *ptr) = je_free;
 JEMALLOC_EXPORT void *(* __malloc_hook)(size_t size) = je_malloc;
 JEMALLOC_EXPORT void *(* __realloc_hook)(void *ptr, size_t size) = je_realloc;
+#ifdef JEMALLOC_OVERRIDE_MEMALIGN
 JEMALLOC_EXPORT void *(* __memalign_hook)(size_t alignment, size_t size) =
     je_memalign;
 #endif
END
mv bin/pprof bin/jemalloc-prof
./configure --disable-debug --prefix=/opt/local --with-jemalloc-prefix=
sudo make install

Instructions for building HHVM

git clone --branch HHVM-3.2 --recursive git://github.com/facebook/hhvm.git
cd hhvm
prefix=/opt/local
git submodule update --force --recursive
cmake . \
    -Wno-dev \
    -DCMAKE_CXX_COMPILER=$(which g++-mp-4.8) \
    -DCMAKE_C_COMPILER=$(which gcc-mp-4.8) \
    -DCMAKE_ASM_COMPILER=$(which gcc-mp-4.8) \
    -DLIBIBERTY_LIB=$prefix/lib/gcc48/x86_64/libiberty.a \
    -DCMAKE_PREFIX_PATH=$prefix \
    -DCMAKE_INSTALL_PREFIX=$prefix \
    -DCMAKE_INCLUDE_PATH="$prefix/include/gcc48/c++/parallel:$prefix/include:/usr/include" \
    -DCMAKE_LIBRARY_PATH="$prefix/lib:/usr/lib" \
    -DLIBDWARF_LIBRARIES=$prefix/lib/elftoolchain/libdwarf.3.dylib \
    -DLIBDWARF_INCLUDE_DIRS=$prefix/include/elftoolchain \
    -DLIBEVENT_LIB=$prefix/lib/libevent.dylib \
    -DLIBEVENT_INCLUDE_DIR=$prefix/include \
    -DLIBVPX_INCLUDE_DIRS=$prefix/include \
    -DFREETYPE_INCLUDE_DIRS=$prefix/include/freetype2 \
    -DFREETYPE_LIBRARIES=$prefix/lib/libfreetype.dylib \
    -DLIBSQLITE3_INCLUDE_DIR=$prefix/include \
    -DLIBSQLITE3_LIBRARY=$prefix/lib/libsqlite3.0.dylib \
    -DJEMALLOC_INCLUDE_DIR=$prefix/include \
    -DJEMALLOC_LIB=$prefix/lib/libjemalloc.dylib \
    -DLibYaml_INCLUDE_DIRS=$prefix/include \
    -DMYSQL_INCLUDE_DIR=$prefix/include/mysql55/mysql \
    -DMYSQL_LIB=$prefix/lib/mysql55/mysql/libmysqlclient.dylib \
    -DBOOST_INCLUDEDIR=$prefix/include \
    -DBOOST_LIBRARYDIR=$prefix/lib \
    -DBoost_USE_STATIC_LIBS=ON \
    -DPCRE_INCLUDE_DIR=$prefix/include \
    -DPCRE_LIBRARY=$prefix/lib/libpcre.dylib && make -j4

Install with Homebrew

Install homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Tap additional repositories

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap hhvm/homebrew-hhvm

Install master HHVM version

brew update
brew install hhvm --HEAD

Install by hand

Install homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Tap additional repositories

brew tap homebrew/versions

Install dependencies

brew install freetype gettext cmake git libtool mcrypt oniguruma re2c     \
             autoconf libelf readline automake mysql-connector-c pcre     \
             gd icu4c libmemcached pkg-config tbb imagemagick binutils    \
             curl imap-uw libxslt libevent sqlite homebrew/versions/gcc48 \
             openssl gawk
brew install --build-from-source --cc=gcc-4.8 glog boost

Install some packages that are not (yet) part of homebrew:

brew install \
  https://gist.github.com/slbmeh/9059260/raw/1cbf0f6f5639b4a066395bedb702cdd6bd895d15/libdwarf.rb \
  https://gist.github.com/sgolemon/8fdc7e2afcd73a960b9c/raw/1211e21151ed3443dbc027e5383fb49e9eb1ab91/jemallocfb.rb

Get HHVM

git clone --recursive git://github.com/facebook/hhvm.git

Build HHVM

cd hhvm
cmake . \
    -DCMAKE_CXX_COMPILER=$(brew --prefix gcc48)/bin/g++-4.8 \
    -DCMAKE_C_COMPILER=$(brew --prefix gcc48)/bin/gcc-4.8 \
    -DCMAKE_ASM_COMPILER=$(brew --prefix gcc48)/bin/gcc-4.8 \
    -DLIBIBERTY_LIB=$(brew --prefix gcc48)/lib/x86_64/libiberty-4.8.a \
    -DCMAKE_INCLUDE_PATH="/usr/local/include:/usr/include" \
    -DCMAKE_LIBRARY_PATH="/usr/local/lib:/usr/lib" \
    -DLIBEVENT_LIB=$(brew --prefix libevent)/lib/libevent.dylib \
    -DLIBEVENT_INCLUDE_DIR=$(brew --prefix libevent)/include \
    -DICU_INCLUDE_DIR=$(brew --prefix icu4c)/include \
    -DICU_LIBRARY=$(brew --prefix icu4c)/lib/libicuuc.dylib \
    -DICU_I18N_LIBRARY=$(brew --prefix icu4c)/lib/libicui18n.dylib \
    -DICU_DATA_LIBRARY=$(brew --prefix icu4c)/lib/libicudata.dylib \
    -DREADLINE_INCLUDE_DIR=$(brew --prefix readline)/include \
    -DREADLINE_LIBRARY=$(brew --prefix readline)/lib/libreadline.dylib \
    -DCURL_INCLUDE_DIR=$(brew --prefix curl)/include \
    -DCURL_LIBRARY=$(brew --prefix curl)/lib/libcurl.dylib \
    -DBOOST_INCLUDEDIR=$(brew --prefix boost)/include \
    -DBOOST_LIBRARYDIR=$(brew --prefix boost)/lib \
    -DBoost_USE_STATIC_LIBS=ON \
    -DJEMALLOC_INCLUDE_DIR=$(brew --prefix jemallocfb)/include \
    -DJEMALLOC_LIB=$(brew --prefix jemallocfb)/lib/libjemalloc.dylib \
    -DLIBINTL_LIBRARIES=$(brew --prefix gettext)/lib/libintl.dylib \
    -DLIBINTL_INCLUDE_DIR=$(brew --prefix gettext)/include \
    -DLIBDWARF_LIBRARIES=$(brew --prefix libdwarf)/lib/libdwarf.3.dylib \
    -DLIBDWARF_INCLUDE_DIRS=$(brew --prefix libdwarf)/include \
    -DLIBMAGICKWAND_INCLUDE_DIRS=$(brew --prefix imagemagick)/include/ImageMagick-6 \
    -DLIBMAGICKWAND_LIBRARIES=$(brew --prefix imagemagick)/lib/libMagickWand-6.Q16.dylib \
    -DMYSQL_INCLUDE_DIR=$(brew --prefix mysql-connector-c)/include \
    -DMYSQL_LIB=$(brew --prefix mysql-connector-c)/lib \
    -DFREETYPE_INCLUDE_DIRS=$(brew --prefix freetype)/include/freetype2 \
    -DFREETYPE_LIBRARIES=$(brew --prefix freetype)/lib/libfreetype.dylib \
    -DLIBMEMCACHED_LIBRARY=$(brew --prefix libmemcached)/lib/libmemcached.dylib \
    -DLIBMEMCACHED_INCLUDE_DIR=$(brew --prefix libmemcached)/include \
    -DLIBELF_LIBRARIES=$(brew --prefix libelf)/lib/libelf.a \
    -DLIBELF_INCLUDE_DIRS=$(brew --prefix libelf)/include/libelf \
    -DLIBGLOG_LIBRARY=$(brew --prefix glog)/lib/libglog.dylib \
    -DLIBGLOG_INCLUDE_DIR=$(brew --prefix glog)/include \
    -DOPENSSL_SSL_LIBRARY=$(brew --prefix openssl)/lib/libssl.dylib \
    -DOPENSSL_INCLUDE_DIR=$(brew --prefix openssl)/include \
    -DOPENSSL_CRYPTO_LIBRARY=$(brew --prefix openssl)/lib/libcrypto.dylib \
    -DPCRE_LIBRARY=$(brew --prefix pcre)/lib \
    -DPCRE_INCLUDE_DIR=$(brew --prefix pcre)/include \
    -DTBB_INSTALL_DIR=$(brew --prefix tbb) \
    -DLIBSQLITE3_INCLUDE_DIR=$(brew --prefix sqlite)/include \
    -DLIBSQLITE3_LIBRARY=$(brew --prefix sqlite)/lib/libsqlite3.0.dylib
make -j4

Trouble shooting

If you see errors like this


Linking CXX executable hhvm
duplicate symbol _main in:
    CMakeFiles/hhvm.dir/main.cpp.o
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCXXCompilerId.cpp.o)
duplicate symbol _main in:
    CMakeFiles/hhvm.dir/main.cpp.o
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCCompilerId.c.o)
duplicate symbol _info_compiler in:
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCXXCompilerId.cpp.o)
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCCompilerId.c.o)
duplicate symbol _info_platform in:
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCXXCompilerId.cpp.o)
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCCompilerId.c.o)
duplicate symbol _info_arch in:
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCXXCompilerId.cpp.o)
    ../runtime/ext/libhphp_runtime_ext.a(CMakeCCompilerId.c.o)
ld: 5 duplicate symbols for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [hphp/hhvm/hhvm] Error 1
make[1]: *** [hphp/hhvm/CMakeFiles/hhvm.dir/all] Error 2

At the end of compilation, you should upgrade your cmake to 3.0.2, and run:

git clean -fx
cmake .....
make

If you see errors like this

Linking CXX executable hhvm
Undefined symbols for architecture x86_64:
  "boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > const&)", referenced from:

during the make -j4 try uninstalling and reinstalling Boost.

Unistall Boost

brew remove boost

Reinstall Boost

brew install --build-from-source --cc=gcc-4.8 boost

Then re-run the make

make -j4
Clone this wiki locally