diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 8f27939642..0f964d5939 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -45,8 +45,25 @@ jobs: strategy: fail-fast: false # Don't cancel all jobs if one fails. matrix: - # TODO: add macos once we are building Darwin wheels. - os: [ubuntu-18.04, ubuntu-latest, windows-latest] + include: + # Linux and Mac use the limited API, so all Python versions will use a single wheel. + # As a result we can just test the oldest and newest supported Python versions and assume + # this gives us sufficient test coverage. + - { os: ubuntu-18.04, python-version: "3.7", architecture: x64 } + - { os: macos-10.15, python-version: "3.7", architecture: x64 } + - { os: ubuntu-20.04, python-version: "3.10", architecture: x64 } + - { os: macos-12, python-version: "3.10", architecture: x64 } + # Windows uses the full API up until Python 3.10, so each of these + # jobs tests a distinct binary wheel. + # TODO(b/231485326): fix the win32 wheels to load properly. + # - { os: windows-2019, python-version: "3.7", architecture: x86 } + # - { os: windows-2019, python-version: "3.8", architecture: x86 } + # - { os: windows-2019, python-version: "3.9", architecture: x86 } + # - { os: windows-2019, python-version: "3.10", architecture: x86 } + - { os: windows-2019, python-version: "3.7", architecture: x64 } + - { os: windows-2019, python-version: "3.8", architecture: x64 } + - { os: windows-2019, python-version: "3.9", architecture: x64 } + - { os: windows-2019, python-version: "3.10", architecture: x64 } runs-on: ${{ matrix.os }} defaults: run: @@ -59,7 +76,8 @@ jobs: path: wheels - uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} - name: Setup Python venv run: | python -m pip install --upgrade pip @@ -67,7 +85,11 @@ jobs: # Windows uses 'Scripts' instead of 'bin' source env/bin/activate || source env/Scripts/activate echo "VIRTUAL ENV:" $VIRTUAL_ENV - - name: Install Wheels + - name: Install tzdata + run: pip install tzdata + # Only needed on Windows, Linux ships with tzdata. + if: ${{ contains(matrix.os, 'windows') }} + - name: Install Protobuf Wheels run: pip install -vvv --no-index --find-links wheels protobuf protobuftests - name: Test that module is importable run: python -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)' diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index b868f86e45..acc3e1834e 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -71,6 +71,11 @@ config_setting( values = {"cpu": "osx-x86_64"}, ) +config_setting( + name = "osx-aarch64_cpu", + values = {"cpu": "osx-aarch_64"}, +) + config_setting( name = "win32_cpu", values = {"cpu": "win32"}, @@ -93,7 +98,8 @@ py_wheel( platform = select({ ":x86_64_cpu": "manylinux2014_x86_64", ":aarch64_cpu": "manylinux2014_aarch64", - ":osx-x86_64_cpu": "macosx_10_9_universal", + ":osx-x86_64_cpu": "macosx_10_9_x86_64", + ":osx-aarch64_cpu": "macosx_10_9_arm64", ":win32_cpu": "win32", ":win64_cpu": "win_amd64", "//conditions:default": "any", @@ -161,6 +167,8 @@ py_dist( "win64": "310", "linux-x86_64": "37", "linux-aarch_64": "37", + "osx-aarch_64": "37", + "osx-x86_64": "37", }, tags = ["manual"], ) diff --git a/python/py_extension.bzl b/python/py_extension.bzl index 2b43e43ffd..8b175a8e7a 100644 --- a/python/py_extension.bzl +++ b/python/py_extension.bzl @@ -1,5 +1,6 @@ -"""Macro to support py_extension -""" +"""Macro to support py_extension """ + +load("@bazel_skylib//lib:selects.bzl", "selects") def py_extension(name, srcs, copts, deps = []): """Creates a C++ library to extend python @@ -15,8 +16,8 @@ def py_extension(name, srcs, copts, deps = []): name = name + "_binary", srcs = srcs, copts = copts + ["-fvisibility=hidden"], - linkopts = select({ - "//python/dist:osx-x86_64_cpu": ["-undefined", "dynamic_lookup"], + linkopts = selects.with_or({ + ("//python/dist:osx-x86_64_cpu", "//python/dist:osx-aarch64_cpu"): ["-undefined", "dynamic_lookup"], "//conditions:default": [], }), linkshared = True, diff --git a/python/python_api.h b/python/python_api.h index e8a8fcf818..80496cb4ee 100644 --- a/python/python_api.h +++ b/python/python_api.h @@ -49,10 +49,11 @@ // Python 3.10, In practice it has been stable since Python 3.1. // https://bugs.python.org/issue41784 // -// On Linux, ELF lets us get away with using this function with the limited -// API prior to 3.10. +// On Linux/ELF and macOS/Mach-O, we can get away with using this function with +// the limited API prior to 3.10. -#if defined(__linux__) && defined(Py_LIMITED_API) && Py_LIMITED_API < 0x03100000 +#if (defined(__linux__) || defined(__APPLE__)) && defined(Py_LIMITED_API) && \ + Py_LIMITED_API < 0x03100000 PyAPI_FUNC(const char*) PyUnicode_AsUTF8AndSize(PyObject* unicode, Py_ssize_t* size); #endif