Skip to content

Commit

Permalink
resolve incorrect cpu arch selection for cibuildwheels (#453)
Browse files Browse the repository at this point in the history
* resolve incorrect cpu arch selection for cibuildwheels via explicit set of archflags
* fix to block musllinux on x86
  • Loading branch information
AndrewAnnex committed Jul 28, 2022
1 parent a575ca0 commit bb78544
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/publish-to-test-and-live-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ jobs:
- config: {"name": "Windows", "os": "windows-latest", "arch": "AMD64"}
name: Build SpiceyPy 🌶️ 🥧 Python 🐍 wheels for ${{ matrix.config.os }} ${{ matrix.config.arch }}
env:
CSPICE_CACHE: 0
CIBW_ARCHS: ${{ matrix.config.arch }}
MACOSX_DEPLOYMENT_TARGET: "10.11"
runs-on: ${{ matrix.config.os }}
steps:
- name: Checkout 🌶️ 🥧
uses: actions/checkout@v2
- name: Setup 🔬🍦🏗️
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1.4.1
- name: set additional environment variables
if: runner.name == 'macOS' && runner.arch == 'arm64'
run: |
echo "CIBW_ARCHS_MACOS=arm64" >> $GITHUB_ENV
echo "ARCHFLAGS='-arch arm64'" >> $GITHUB_ENV
- name: Set up QEMU for arm64 builds
if: matrix.config.arch == 'aarch64'
uses: docker/setup-qemu-action@v1
Expand All @@ -71,7 +76,7 @@ jobs:
uses: actions/cache@v2
with:
path: /project/src/spiceypy/utils/libcspice.so
key: ${{ matrix.config.os }}-${{ matrix.config.arch }}-${{ hashFiles('get_spice.py') }}-${{ hashFiles('setup.cfg') }}
key: ${{ env.CSPICE_CACHE }}-${{ matrix.config.os }}-${{ matrix.config.arch }}-${{ hashFiles('get_spice.py') }}-${{ hashFiles('setup.cfg') }}
- name: Set up Python 🐍 3.9
uses: actions/setup-python@v2
with:
Expand All @@ -82,10 +87,12 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -r ci-requirements.txt
python -m pip install cibuildwheel==2.3.1
python -m pip install cibuildwheel==2.8.1
- name: Build wheels for SpiceyPy 🌶️ 🥧
timeout-minutes: 120
run: |
env | grep CIBW
env | grep ARCH
python -m cibuildwheel --output-dir wheelhouse
- name: Check dists
run: |
Expand Down
51 changes: 30 additions & 21 deletions get_spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
CSPICE_NO_PATCH = "CSPICE_NO_PATCH"

host_OS = platform.system()
host_arch = platform.machine()
# Check if platform is supported
os_supported = host_OS in ("Linux", "Darwin", "FreeBSD", "Windows")
# Get platform is Unix-like OS or not
Expand All @@ -98,6 +99,10 @@
cspice_dir = os.environ.get(CSPICE_SRC_DIR, os.path.join(root_dir, "cspice"))
# and make a global tmp cspice directory
tmp_cspice_root_dir = None
# if we need to cross compile or compile for arm64
is_macos_arm = host_OS == "Darwin" and (
host_arch == "arm64" or os.environ.get("ARCHFLAGS", "") == "-arch arm64"
)
# versions
spice_version = "N0067"
spice_num_v = "67"
Expand Down Expand Up @@ -125,17 +130,13 @@ class GetCSPICE(object):
_dists = {
# system arch distribution name extension
# -------- ---------- ------------------------- ---------
("Darwin", "32bit"): ("MacIntel_OSX_AppleC_32bit", "tar.Z"),
("Darwin", "64bit"): ("MacIntel_OSX_AppleC_64bit", "tar.Z"),
("Darwin", "64bit"): ("MacM1_OSX_clang_64bit", "tar.Z"),
("cygwin", "32bit"): ("PC_Cygwin_GCC_32bit", "tar.Z"),
("cygwin", "64bit"): ("PC_Cygwin_GCC_64bit", "tar.Z"),
("FreeBSD", "32bit"): ("PC_Linux_GCC_32bit", "tar.Z"),
("FreeBSD", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"),
("Linux", "32bit"): ("PC_Linux_GCC_32bit", "tar.Z"),
("Linux", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"),
("Windows", "32bit"): ("PC_Windows_VisualC_32bit", "zip"),
("Windows", "64bit"): ("PC_Windows_VisualC_64bit", "zip"),
("Darwin", "x86_64", "64bit"): ("MacIntel_OSX_AppleC_64bit", "tar.Z"),
("Darwin", "arm64", "64bit"): ("MacM1_OSX_clang_64bit", "tar.Z"),
("cygwin", "x86_64", "64bit"): ("PC_Cygwin_GCC_64bit", "tar.Z"),
("FreeBSD", "x86_64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"),
("Linux", "x86_64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"),
("Linux", "aarch64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"),
("Windows", "x86_64", "64bit"): ("PC_Windows_VisualC_64bit", "zip"),
}

def __init__(self, version=spice_version, dst=None):
Expand Down Expand Up @@ -197,19 +198,28 @@ def _distribution_info(self):

print("Gathering information...")
system = platform.system()
processor = platform.processor()
machine = platform.machine()

# Cygwin system is CYGWIN-NT-xxx.
system = "cygwin" if "CYGWIN" in system else system
cpu_bits = "64bit" if sys.maxsize > 2 ** 32 else "32bit"

processor = platform.processor()
machine = "64bit" if sys.maxsize > 2 ** 32 else "32bit"
machine2 = platform.machine()
if machine in ("x86", "x86_64", "AMD64", "i686"):
machine = "x86_64"

if is_macos_arm:
print("either running on apple arm64 or cross-compiling")
machine = "arm64"

print("SYSTEM: ", system)
print("PROCESSOR:", processor)
print("MACHINE: ", machine, machine2)
print("MACHINE: ", cpu_bits, machine)

if machine in ("i386", "x86_32") or cpu_bits == "32bit":
raise RuntimeError("32bit bit builds are not supported")

return self._dists[(system, machine)]
return self._dists[(system, machine, cpu_bits)]

def _download(self):
"""Support function that encapsulates the OpenSSL transfer of the CSPICE
Expand Down Expand Up @@ -286,9 +296,7 @@ def apply_patches() -> None:
f"0001-patch-for-n66-dskx02.c{iswin}.patch",
f"0002-patch-for-n66-subpnt.c{iswin}.patch",
]
if (
host_OS == "Darwin"
): # todo is this only needed for M1 or is it for any macos
if is_macos_arm:
patches.append("0004_inquire_unistd.patch")
for p in patches:
try:
Expand Down Expand Up @@ -341,15 +349,16 @@ def build_cspice() -> str:
global cspice_dir, host_OS
if is_unix:
libname = f"libcspice.so"
target = "-target arm64-apple-macos11" if is_macos_arm else ""
if host_OS == "Darwin":
extra_flags = f"-dynamiclib -install_name @rpath/{libname}"
else:
extra_flags = f"-shared -Wl,-soname,{libname}"
destination = cspice_dir
os.chdir(destination)
cmds = [
"gcc -Iinclude -c -fPIC -O2 -ansi ./cspice/src/cspice/*.c",
f"gcc {extra_flags} -fPIC -O2 -lm *.o -o {libname}",
f"gcc {target} -Iinclude -c -fPIC -O2 -ansi ./cspice/src/cspice/*.c",
f"gcc {target} {extra_flags} -fPIC -O2 -lm *.o -o {libname}",
]
elif host_OS == "Windows":
destination = os.path.join(cspice_dir, "cspice", "src", "cspice")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ build-frontend = "build"
before-build = "python {project}/get_spice.py"
# Only build on CPython 3.9
build = "cp39-*"
# Skip 32-bit builds and pypy
skip = ["*-win32", "*-manylinux_i686", "*-musllinux_i686", "pypy*", "pp*", "*-musllinux_aarch64"]
# Skip 32-bit builds, pypy, and musllinux
skip = ["*-win32", "*-manylinux_i686", "*-musllinux_i686", "pypy*", "pp*", "*-musllinux_aarch64", "*-musllinux_x86_64"]
# other options
build-verbosity = 2
before-test = [
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = spiceypy
version = attr: spiceypy.__version__
description = A Python Wrapper for the NAIF CSPICE Toolkit
long_description = file: README.rst
long_description_content_type = text/x-rst
author = Andrew Annex
author_email = ama6fy@virginia.edu
maintainer = Andrew Annex
Expand Down

0 comments on commit bb78544

Please sign in to comment.