Skip to content

Commit

Permalink
wheels: more compatibility
Browse files Browse the repository at this point in the history
* Update manylinux images
* FFI now built as a per-platform static library
* Explicitly set minimum macOS deployment target
* Try enabling Windows (as an experiment)
* Disable aarch64-linux, aarch64-windows
  • Loading branch information
donn committed Sep 28, 2024
1 parent 4d45211 commit 95b52f3
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 41 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/_run_cibw_linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# Copyright (C) 2024 Efabless Corporation
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
This runs the cibuildwheel step from the wheels workflow locally.
"""

import os
import yaml
import platform
import subprocess

__dir__ = os.path.dirname(os.path.abspath(__file__))


workflow = yaml.safe_load(open(os.path.join(__dir__, "wheels.yml")))

env = os.environ.copy()

steps = workflow["jobs"]["build_wheels"]["steps"]
cibw_step = None
for step in steps:
if (step.get("uses") or "").startswith("pypa/cibuildwheel"):
cibw_step = step
break

for key, value in cibw_step["env"].items():
if key.endswith("WIN") or key.endswith("MAC"):
continue
env[key] = value

env["CIBW_ARCHS"] = os.getenv("CIBW_ARCHS") or platform.machine()
subprocess.check_call(["cibuildwheel"], env=env)
28 changes: 28 additions & 0 deletions .github/workflows/cibw_before_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
set -e
set -x

# Build-time dependencies
## Linux Docker Images
if command -v yum &> /dev/null; then
yum install -y libffi-devel flex bison
fi

if command -v apk &> /dev/null; then
apk add libffi-dev flex bison
fi

## macOS/Windows Native
## Software installed by default: https://github.com/actions/runner-images

### macOS: flex and bison are already installed on macOS

### Windows: TODO: check if this actually works
if command -v choco &> /dev/null; then
choco install flex bison
end

# Build Static FFI (platform-dependent but not Python version dependent)
cd ffi
./configure --prefix=$PWD/pfx
make install -j$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)
rm -rf ./pfx/lib/libffi.so*
23 changes: 23 additions & 0 deletions .github/workflows/cibw_before_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set -e
set -x

# Build boost
cd ./boost
## Delete the artefacts from previous builds (if any)
rm -rf ./pfx
## Bootstrap bjam
./bootstrap.sh --prefix=./pfx
## Build Boost against current version of Python, only for
## static linkage (Boost is statically linked because system boost packages
## wildly vary in versions, including the libboost_python3 version)
./b2\
-j$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu)\
--prefix=./pfx\
--with-filesystem\
--with-system\
--with-python\
cxxflags="$(python3-config --includes) -std=c++17 -fPIC"\
cflags="$(python3-config --includes) -fPIC"\
link=static\
variant=release\
install
74 changes: 33 additions & 41 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ on:
jobs:
build_wheels:
strategy:
fail-fast: false
matrix:
os: [
# You can't cross-compile on Linux, so might as well do the emulated
# workload on its own
{
name: "Ubuntu 22.04",
family: "linux",
runner: "ubuntu-22.04",
archs: "x86_64",
},
{
name: "Ubuntu 22.04",
family: "linux",
runner: "ubuntu-22.04",
archs: "aarch64",
},
# While you can cross-compile on macOS, this is less of a headache
## Aarch64 is disabled for now: GitHub is committing to EOY
## for free aarch64 runners for open-source projects and
## emulation times out:
## https://github.com/orgs/community/discussions/19197#discussioncomment-10550689
# {
# name: "Ubuntu 22.04",
# family: "linux",
# runner: "ubuntu-22.04",
# archs: "aarch64",
# },
{
name: "macOS 13",
family: "macos",
Expand All @@ -35,13 +37,12 @@ jobs:
runner: "macos-14",
archs: "arm64",
},
# TODO: Make Windows Work
# {
# name: "Windows Server 2019",
# family: "windows",
# runner: "windows-2019",
# archs: "AMD64 ARM64",
# },
{
name: "Windows Server 2019",
family: "windows",
runner: "windows-2019",
archs: "AMD64",
},
]
name: Build Wheels | ${{ matrix.os.name }} | ${{ matrix.os.archs }}
runs-on: ${{ matrix.os.runner }}
Expand All @@ -57,7 +58,11 @@ jobs:
- name: Get Boost Source
run: |
mkdir -p boost
curl -L https://sourceforge.net/projects/boost/files/boost/1.83.0/boost_1_83_0.tar.bz2 | tar --strip-components=1 -xjC boost
curl -L https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-b2-nodocs.tar.gz | tar --strip-components=1 -xzC boost
- name: Get FFI
run: |
mkdir -p ffi
curl -L https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz | tar --strip-components=1 -xzC ffi
- name: Seed Makefile.bak
# For every sed, a .bak is created so it can be copied over Makefile to
# rever the change for the next Python version to be built.
Expand All @@ -79,33 +84,20 @@ jobs:
- name: Build wheels
uses: pypa/cibuildwheel@v2.20.0
env:
# Explaining the build steps:
# 1. Revert previous seds (if any)
# 2. Delete the libboost static archives from previous builds (if any)
# 3. Navigate to boost source extracted in previous GHA step
# 4-5. Build Boost against current version of Python, only for
# static linkage
# (Boost is statically linked because system boost packages
# wildly vary in versions, including the libboost_python3
# version)
# 6-7. Return to package directory and sed the Makefile to point at
# the newly compiled libboost_python
CIBW_SKIP: pp* # The Makefile requires python3-config which is not in pypy
CIBW_ARCHS: ${{ matrix.os.archs }}
CIBW_BUILD_VERBOSITY: "1"
CIBW_BEFORE_ALL_LINUX: yum install -y libffi-devel flex bison || apk add libffi-dev flex bison
CIBW_BEFORE_ALL_MAC: brew install libffi
CIBW_BEFORE_BUILD: |
cp Makefile.bak Makefile &&\
cd ./boost &&\
rm -rf ./pfx &&\
./bootstrap.sh --prefix=./pfx &&\
./b2 --prefix=./pfx --with-filesystem --with-system --with-python cxxflags="$(python3-config --includes) -std=c++17 -fPIC" cflags="$(python3-config --includes) -fPIC" link=static variant=release install &&\
ls ./pfx/lib/libboost_python*.a &&\
cd {package} &&\
sed -i'.bak' -e "1i\\
LINKFLAGS = -L./boost/pfx/lib" -e "1i\\
CXXFLAGS = -I./boost/pfx/include" -e "s@BOOST_PYTHON_LIB ?=@BOOST_PYTHON_LIB = $(ls ./boost/pfx/lib/libboost_python*.a)\nTrash =@" Makefile
# manylinux2014 (default) does not have a modern enough C++ compiler for Yosys
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
CIBW_BEFORE_ALL: bash ./.github/workflows/cibw_before_all.sh
CIBW_ENVIRONMENT: >
CXXFLAGS=-I./boost/pfx/include
LINKFLAGS=-L./boost/pfx/lib
PKG_CONFIG_PATH=./ffi/pfx/lib/pkgconfig
makeFlags='BOOST_PYTHON_LIB=./boost/pfx/lib/libboost_python*.a'
CIBW_ENVIRONMENT_MAC: MACOSX_DEPLOYMENT_TARGET=11
CIBW_BEFORE_BUILD: bash ./.github/workflows/cibw_before_build.sh
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.whl
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ __pycache__
/build
/venv
/boost
/ffi

0 comments on commit 95b52f3

Please sign in to comment.