Created
February 3, 2022 14:46
-
-
Save dokipen/2077ce7e941f64d17691490b72cb4ea2 to your computer and use it in GitHub Desktop.
Crappy Makefile to build a pulsar-client whl for py3.7.12, M1 python, pulsar-2.9.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BUILD_DIR=$(shell pwd) | |
ARCH=$(shell uname -m) | |
VERSION=$(shell sw_vers -productVersion | sed 's/\.[0-9]/_0/') | |
PYTHON_VERSION=3.7 | |
PYTHON_PATCH_VERSION=3.7.12 | |
PYTHON_POSTFIX=m | |
PYTHON_WHL_VERSION=cp$(subst .,,$(PYTHON_VERSION))-cp$(subst .,,$(PYTHON_VERSION))$(PYTHON_POSTFIX) | |
PYTHON_BASE=$(HOME)/.pyenv/versions/$(PYTHON_PATCH_VERSION) | |
PYTHON_LIBRARIES=$(PYTHON_BASE)/lib | |
PYTHON_INCLUDE_DIR=$(PYTHON_BASE)/include/python$(PYTHON_VERSION)$(PYTHON_POSTFIX) | |
BOOST_VERSION=1.76.0 | |
BOOST_NAME=boost_$(subst .,_,$(BOOST_VERSION)) | |
BOOST_URL=https://boostorg.jfrog.io/artifactory/main/release/$(BOOST_VERSION)/source/$(BOOST_NAME).tar.bz2 | |
BOOST_SHA256=f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41 | |
BOOST_INSTALL_PREFIX=/usr/local | |
PULSAR_VERSION=2.9.1 | |
PULSAR_URL=https://github.com/apache/pulsar/archive/refs/tags/v$(PULSAR_VERSION).zip | |
PULSAR_SRC=pulsar-$(PULSAR_VERSION) | |
PULSAR_CPP=$(PULSAR_SRC)/pulsar-client-cpp | |
PULSAR_PY=$(PULSAR_CPP)/python | |
PULSAR_WHL=pulsar_client-$(PULSAR_VERSION)-$(PYTHON_WHL_VERSION)-macosx_$(VERSION)_$(ARCH).whl | |
PULSAR_SHA256SUM="27d96563f8ddf672bb6c5d4d3988aaaad0daff5270aca3f16584a7ad5a4e9c11" | |
.PHONY: unpack clean build-boost-python install-boost-python | |
dist/$(PULSAR_WHL): $(PULSAR_PY)/dist/$(PULSAR_WHL) | |
cp $< $@ | |
dist/pulsar-v$(PULSAR_VERSION).zip: dist | |
curl -Ls $(PULSAR_URL) -o $@ | |
# Random file from zip | |
$(PULSAR_CPP)/CMakeLists.txt: dist/pulsar-v$(PULSAR_VERSION).zip | |
sha256sum -c <<<"$(PULSAR_SHA256SUM) $<" | |
unzip -u $< -d . | |
touch $@ | |
# Not sure why boost can't figure out the GTEST and GMOCK paths | |
$(PULSAR_PY)/dist/$(PULSAR_WHL): $(PULSAR_CPP)/CMakeLists.txt | |
pushd $(PULSAR_CPP) && \ | |
cmake . \ | |
-Wno-dev \ | |
-DLINK_STATIC=ON \ | |
-DBUILD_PYTHON_WRAPPER=ON \ | |
-DBUILD_TESTS=ON \ | |
-DPYTHON_LIBRARIES=$(PYTHON_LIBRARIES) \ | |
-DPYTHON_INCLUDE_DIR=$(PYTHON_INCLUDE_DIR) \ | |
-DBUILD_PERF_TOOLS=OFF && \ | |
make -j$(shell nproc) _pulsar && \ | |
popd && \ | |
pushd $(PULSAR_PY) && \ | |
pip install wheel && \ | |
python setup.py bdist_wheel | |
# cmake/FindBoost doesn't look for the a64 prefix, so we symlink them without it. | |
install-boost: | |
mkdir -p $(BOOST_INSTALL_PREFIX)/lib/cmake | |
cd $(BOOST_NAME) && \ | |
cp -a install-boost/* $(BOOST_INSTALL_PREFIX) && \ | |
cd $(BOOST_INSTALL_PREFIX)/lib && \ | |
ln -fs libboost_python37-mt-a64.a libboost_python37-mt.a&& \ | |
ln -fs libboost_python37-a64.a libboost_python37.a | |
build-boost: $(BOOST_NAME)/project-config.jam | |
$(BOOST_NAME)/project-config.jam: $(BOOST_NAME)/user-config.jam $(BOOST_NAME)/b2 | |
cd $(BOOST_NAME) && \ | |
./b2 \ | |
--build-dir=build-boost \ | |
--stagedir=stage-boost \ | |
--libdir=install-boost/lib \ | |
--prefix=install-boost \ | |
--python=$(PYTHON_VERSION) \ | |
--sNO_LZMA=1 \ | |
--sNO_ZSTD=1 \ | |
-d2 \ | |
-j8 \ | |
--layout=tagged=1.66 \ | |
--user-config=user-config.jam \ | |
install \ | |
threading=multi,single \ | |
link=shared,static \ | |
cxxflags=-std=c++14 \ | |
cxxflags=-stdlib=libc++ \ | |
linkflags=-stdlib=libc++ | |
touch $(BOOST_NAME)/project-config.jam | |
$(BOOST_NAME)/user-config.jam: hacks/user-config.jam $(BOOST_NAME) | |
cp $< $@ | |
$(BOOST_NAME)/b2: $(BOOST_NAME)/bootstrap.sh | |
cd $(BOOST_NAME) && \ | |
sed -i.bak 's/\ using python/#using python/' bootstrap.sh && \ | |
./bootstrap.sh \ | |
--prefix=$(BOOST_INSTALL_PREFIX) \ | |
--libdir=$(BOOST_INSTALL_PREFIX)/lib \ | |
--with-python=python3.7 \ | |
--with-python-root=$(HOME)/.pyenv/versions/3.7.12 \ | |
--with-icu=/opt/homebrew/opt/icu4c \ | |
--without-libraries=mpi | |
$(BOOST_NAME)/bootstrap.sh: $(BOOST_NAME) | |
$(BOOST_NAME): dist/boost-$(BOOST_VERSION).tar.bz2 | |
sha256sum -c <<<"$(BOOST_SHA256) $<" | |
tar xfj $< | |
touch $@ | |
dist/boost-$(BOOST_VERSION).tar.bz2: dist | |
curl -Ls $(BOOST_URL) -o $@ | |
build dist: | |
mkdir -p $@ | |
clean: | |
rm -rf dist build $(PULSAR_SRC) $(BOOST_NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment