You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/04 21:35:42 UTC

[GitHub] [pulsar] zbentley opened a new pull request, #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

zbentley opened a new pull request, #15436:
URL: https://github.com/apache/pulsar/pull/15436

   Fixes https://github.com/apache/pulsar/issues/15402
   
   
   ### Motivation
   
   Building Python client wheels on MacOS is troublesome on some combinations of architecture/python version. Specifically, Python 3.7 is the most widely used version of Python 3, but it does not support building "universal" binary wheels (wheels which contain both ARM and Intel-architecture binary artifacts).
   
   Additionally, building Python from source on MacOS is troublesome and prone to breakage in older (or future) MacOS versions.
   
   As a result, the wheel building Bash automation refrains from creating 3.7 wheels on ARM, and otherwise special-cases 3.7 in a few different ways.
   
   Two tools are available to help with these issues which the Pulsar client build system does not currently make use of:
   - The [pyenv](https://github.com/pyenv/pyenv) project is a widely used means of getting around "python has trouble building from source" on many systems, including MacOS systems. They maintain a curated list of patches (mostly to Python's build system rather than Python itself) to allow it to build well on all sorts of environments. They also provide tooling for semi-hermetic "virtual python environments" (distinct from [virtualenvs](https://docs.python.org/3/library/venv.html) in that they encapsulate a separate Python _interpreter_, rather than just a set of dependencies). Using those environments, it's possible to build and install multiple versions of Python and switch between them.
   - The [rosetta](https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment) translation system on ARM Macs allows those Macs to run binaries (including compiler toolchains) for both the ARM and x86 architecture.
   
   ### Modifications
   
   This PR alters the wheel creation script in a few ways:
   - The MacOS SDK (the stdlib and system headers/libraries) is now looked up using the standard `xcrun` command rather than via hardcoded and templated path.
   - Python versions iterated over in the script are also qualified with their architecture--x86, arm, or universal.
   - The OpenSSL version that is built for the Pulsar client to link against is also used by Python builds.
   - `pyenv` is installed (via git master checkout) in the wheel building scratch environment. `git clone` is Pyenv's suggested installation mechanism, since many of their patches land in `master` before they are available in pyenv package artifacts via e.g. Homebrew or dpkg repositories.
   - `pyenv` is used to install Pythons, rather than a direct download-and-compile.  Appropriate flags are set/unset for each python/architecture "tuple". For example, for 3.7, only native-architecture, non-universal wheels can be created, so its build/install is run twice, one with an ARM architecture and once with x86. **Note that this means that arm64 python37 builds will fail on Intel Macs**; the Rosetta translation layer used to allow ARM macs to run the Intel build system does not reverse, and so the `arch` command's invocation will fail for that permutation on an Intel mac. I suggest that Intel mac compiling users comment that permutation out of the `PYTHON_VERSIONS` list.
   - Within each pyenv, the `pip`, `setuptools`, and `wheel` packages are updated to their latest versions supported on the corresponding Python.
   - Pyenv is also used to invoke `bdist_wheel` at the end, providing added assurance that wheel creation executes against the desired versions of resources.
   
   ### Verifying this change
   
   I suggest the following test plan:
   
   1. On a Mac running MacOS 11 or better, ensure `cmake` and the SDK are installed. Also install `pyenv` in a separate distribution for testing via `brew install pyenv`.
   1. If your test system is an Intel Mac, comment out the python37/arm64 entry from the PYTHON_VERSIONS list in this PR's file.
   1. Run `bash build-python-wheels.sh`
   1. Ensure that the expected wheel artifacts corresponding to the listed Python versions are created in the `pulsar-client-cpp/python/dist` directory.
   1. For each packaged version of Python, do `pyenv install $PYTHON_VERSION` to make that Python globally available on your Mac. You should *not* use the pyenv-installed pythons created by the wheel builder script.
   1. For each python, do `pyenv global $PYTHON_VERSION`; ensure `python --version` reports the correct string.
   1. For each python, do `python -mpip install --upgrade pip; python -mpip install --upgrade setuptools wheel`.
   1. For each python, find the corresponding wheel file in `dist/` and do `python -mpip install /path/to/pulsar-client-wheel.whl`. Ensure it installs successfully.
   1. Ensure that only system-avaialble or relative linker paths are available via `otool -L $(python -c 'import _pulsar; print(_pulsar.__file__)')`.
   1. Run the python Pulsar client test suite against a running instance of Pulsar, and ensure all tests pass.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): sort of
     - The public API: no
     - The schema: no
     - The default values of configurations: no
     - The wire protocol: no
     - The rest endpoints: no
     - The admin cli options: no
     - Anything that affects deployment: client libraries
   
   ### Documentation
   
   Need to update docs? 
   
   - [x] `no-need-doc` 
   The wheel creation process is unchanged externally.
     


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1238612681

   @zbentley Please provide a correct documentation label for your PR.
   Instructions see [Pulsar Documentation Label Guide](https://docs.google.com/document/d/1Qw7LHQdXWBW9t2-r-A7QdFDBwmZh6ytB4guwMoXHqc0).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] merlimat commented on a diff in pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
merlimat commented on code in PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#discussion_r865406568


##########
pulsar-client-cpp/python/build-mac-wheels.sh:
##########
@@ -41,77 +42,36 @@ CURL_VERSION=7.61.0
 ROOT_DIR=$(git rev-parse --show-toplevel)
 cd "${ROOT_DIR}/pulsar-client-cpp"
 
-
 # Compile and cache dependencies
 CACHE_DIR=~/.pulsar-mac-wheels-cache
 mkdir -p $CACHE_DIR
 
+if [ ! -d $CACHE_DIR/pyenv ]; then
+  git clone https://github.com/pyenv/pyenv.git $CACHE_DIR/pyenv
+fi
+PYENV=$CACHE_DIR/pyenv/bin/pyenv
+
 cd $CACHE_DIR
 
 PREFIX=$CACHE_DIR/install
 
-###############################################################################
-for line in "${PYTHON_VERSIONS[@]}"; do
-    read -r -a PY <<< "$line"
-    PYTHON_VERSION=${PY[0]}
-    PYTHON_VERSION_LONG=${PY[1]}
-
-    if [ ! -f Python-${PYTHON_VERSION_LONG}/.done ]; then
-      echo "Building Python $PYTHON_VERSION_LONG"
-      curl -O -L https://www.python.org/ftp/python/${PYTHON_VERSION_LONG}/Python-${PYTHON_VERSION_LONG}.tgz
-      tar xfz Python-${PYTHON_VERSION_LONG}.tgz
-
-      PY_PREFIX=$CACHE_DIR/py-$PYTHON_VERSION
-      pushd Python-${PYTHON_VERSION_LONG}
-          if [ $PYTHON_VERSION = '3.7' ]; then
-              UNIVERSAL_ARCHS='intel-64'
-              PY_CFLAGS=" -arch x86_64"
-          else
-              UNIVERSAL_ARCHS='universal2'
-          fi
-
-          CFLAGS="-fPIC -O3 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -I${PREFIX}/include ${PY_CFLAGS}" \
-              LDFLAGS=" ${PY_CFLAGS} -L${PREFIX}/lib" \
-              ./configure --prefix=$PY_PREFIX --enable-shared --enable-universalsdk --with-universal-archs=${UNIVERSAL_ARCHS}
-          make -j16
-          make install
-
-          curl -O -L https://files.pythonhosted.org/packages/27/d6/003e593296a85fd6ed616ed962795b2f87709c3eee2bca4f6d0fe55c6d00/wheel-0.37.1-py2.py3-none-any.whl
-          $PY_PREFIX/bin/pip3 install wheel-*.whl
+export CXXFLAGS=
+export PKG_CONFIG_PATH=
 
-          touch .done
-      popd
-    else
-      echo "Using cached Python $PYTHON_VERSION_LONG"
-    fi
-done
-
-
-###############################################################################
-if [ ! -f zlib-${ZLIB_VERSION}/.done ]; then
-    echo "Building ZLib"
-    curl -O -L https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
-    tar xvfz zlib-$ZLIB_VERSION.tar.gz
-    pushd zlib-$ZLIB_VERSION
-      CFLAGS="-fPIC -O3 -arch arm64 -arch x86_64 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" ./configure --prefix=$PREFIX
-      make -j16
-      make install
-      touch .done
-    popd
-else
-    echo "Using cached ZLib"
-fi
+export SDKROOT=$(xcrun --show-sdk-path)
+export CFLAGS="-DOPENSSL_NO_SSL3 -I${SDKROOT}/usr/include -I${PREFIX}/include"
+export CPPFLAGS="$CFLAGS"
+export LDFLAGS="-L${SDKROOT}/usr/lib -L${PREFIX}/lib"
 
 ###############################################################################
 if [ ! -f openssl-OpenSSL_${OPENSSL_VERSION}.done ]; then
     echo "Building OpenSSL"
     curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION}.tar.gz
-    # -arch arm64 -arch x86_64
     tar xvfz OpenSSL_${OPENSSL_VERSION}.tar.gz
     mv openssl-OpenSSL_${OPENSSL_VERSION} openssl-OpenSSL_${OPENSSL_VERSION}-arm64
     pushd openssl-OpenSSL_${OPENSSL_VERSION}-arm64
       CFLAGS="-fPIC -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \
-          ./Configure --prefix=$PREFIX no-shared darwin64-arm64-cc
+          ./Configure --openssldir=$PREFIX --prefix=$PREFIX no-shared darwin64-arm64-cc
       make -j8
       make install

Review Comment:
   This could be `install_sw` too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1155900371

   The pr had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] zbentley commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta

Posted by GitBox <gi...@apache.org>.
zbentley commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1238411430

   @merlimat `pyenv` proved not to be worth it (and was responsible for the locale issues we encountered). This PR and its description have been updated to use rosetta but not pyenv to improve the build reproducibility. PTAL.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1272199266

   The pr had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta

Posted by GitBox <gi...@apache.org>.
tisonkun commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1313910934

   Closed. This looks good but the code has been moved to https://github.com/apache/pulsar-client-python.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] merlimat commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
merlimat commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1119112471

   @zbentley I'm getting errors in building Python 3.7 with Pyenv through the script: 
   
   ```
   BUILD FAILED (OS X 12.3.1 using python-build 2.3.0-1-g867f34b5)
   
   Inspect or clean up the working tree at /var/folders/q6/sh01_cr95z7f13gwk1thn3y00000gn/T/python-build.20220505154848.25738
   Results logged to /var/folders/q6/sh01_cr95z7f13gwk1thn3y00000gn/T/python-build.20220505154848.25738.log
   
   Last 10 log lines:
   		case upgrade in \
   			upgrade) ensurepip="--upgrade" ;; \
   			install|*) ensurepip="" ;; \
   		esac; \
   		DYLD_LIBRARY_PATH=/var/folders/q6/sh01_cr95z7f13gwk1thn3y00000gn/T/python-build.20220505154848.25738/Python-3.7.13 ./python.exe -E -m ensurepip \
   			$ensurepip --root=/ ; \
   	fi
   dyld[40040]: missing symbol called
   /bin/sh: line 1: 40040 Abort trap: 6           DYLD_LIBRARY_PATH=/var/folders/q6/sh01_cr95z7f13gwk1thn3y00000gn/T/python-build.20220505154848.25738/Python-3.7.13 ./python.exe -E -m ensurepip $ensurepip --root=/
   make: *** [install] Error 134
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] zbentley commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
zbentley commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1179461133

   @dave2wave, @merlimat and I paired on this awhile ago and had isolated build-repro issues down to something related to Python locale preventing Pyenv pythons from building on Matteo's setup. I can try a few "see what sticks" standard-issue fixes like LC_ALL exports etc. to see if that unblocks him and/or others. 
   
   To do more than that, I need more info about specific build failures on builders' machines in order to give confidence in these changes; I'm happy to collaborate here or synchronously via Zoom; feel free to reach out to zac at klaviyo.com if interested.
   
   Others on this thread: have you had luck (good or bad) building with these changes? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] dave2wave commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
dave2wave commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1179363318

   @merlimat - Any reason not to Squash and Merge? (once the CI passes?)
   
   @eolivelli - i've noticed that @zbentley is active with on Pulsar in the Homebrew project.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1226692276

   The pr had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] zbentley commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
zbentley commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1127029644

   Interesting; that's a new one on me (and on google). As with most things pyenv, it's (over)sensitive to workstation environments and so novel failure modes often crop up when used on machines that are configured to build other software.
   
    A couple things to try:
   * The presence of `python.exe` is a little weird. Some parts of the python-build system use that, but it shows up a lot in your output. Are you by chance running a case-insensitive MacOS filesystem (this is somewhat rare these days). What version of MacOS are you running, what `arch`, and what FS (`diskutil info / | grep -i personality`)?
   * Make sure you don't have anything er ... unusual being inherited from your system environment. Pyenv's not terribly hermetic when run by default (are you running it via the build-wheels script on that branch, or normally on your shell?).
   * Try removing `--with-openssl=$PREFIX` from this line and building again: https://github.com/apache/pulsar/pull/15436/files#diff-5644e2b9669a87858353608a740e7980b50b7161ce9cd84a3b800ec1c53a0999R205
   * Try building with `PYENV_DEBUG=1` and post resulting logs/error output.
   * Add `-k` to your `pyenv install` stanza so it keeps the build dir around. That'll allow you to re-run the failing commands with various changes/debugging rather than rebuilding Python each time. Once you've done that, the tmpdir pyenv uses should not be deleted once it's done. You can `export TMPDIR=/stable/path` to make it predictable. Then, try these:
   * Try with faulthandler; if the partially-built python is something you can reproduce that issue by hand with (e.g. you can re-run that ensurepip command after the build fails and it still reproduces the dyld error), add `-X faulthandler`, so like `....python.exe -X faulthandler -E -m ensurepip`.
   * Try figuring out what module is breaking it. `python -c 'import _ssl'; python -c 'import struct'; python -c 'import ctypes'` are some common build failure symptoms (ctypes you already had issues with).
   * If that fails, try dtruss: `sudo dtruss /path/to/pyenv/python -E -m ensurepip` and post output.
   
   Basically, we're trying to find what it wants to link to that it isn't finding.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tisonkun closed pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta

Posted by GitBox <gi...@apache.org>.
tisonkun closed pull request #15436: [python] [build system] Improve MacOS Wheel Building with Rosetta
URL: https://github.com/apache/pulsar/pull/15436


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] zbentley commented on pull request #15436: [python] [build system] Improve MacOS Wheel Building with Pyenv and Rosetta

Posted by GitBox <gi...@apache.org>.
zbentley commented on PR #15436:
URL: https://github.com/apache/pulsar/pull/15436#issuecomment-1120076870

   @merlimat when convenient could you attach one of the pyenv build log files mentioned in the error snippet you posted?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org