Skip to content

Commit

Permalink
Build wheels for more platforms (#50)
Browse files Browse the repository at this point in the history
Enable i686 and aarch64 builds for Linux, and universal2 builds for
macOS. Caught a couple portability problems in the process.

I made a mighty effort trying to get musl and Windows working
along the way but failed; musl is broken because of a bad interaction
with cgo and is probably beyond fixing short of patching the Go
compiler. Windows is suffering from what looks like garden-variety
linker errors and is probably salvagable, but I probably need someone
who knows more about building wheels on Windows to explain what I've
done wrong before I'll be able to fix it.
  • Loading branch information
jordemort authored Apr 28, 2022
1 parent 8ddf11e commit e97b433
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 60 deletions.
61 changes: 27 additions & 34 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,57 @@ jobs:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
#os: [ubuntu-latest, windows-latest, macos-latest]
# Windows isn't working right now: https://github.com/caketop/python-starlark-go/issues/4
# os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v2
name: Install Python
with:
python-version: '3.10'
- uses: actions/setup-go@v2
if: runner.os != 'Linux'

- name: Install dependencies
run: |
python -m pip install --upgrade -r development.txt
python -m pip install cibuildwheel==2.4.0
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/[email protected]

- name: Install Visual C++ for Python 2.7
if: runner.os == 'Windows'
- name: Build sdist
if: runner.os == 'Linux'
run: |
choco install vcpython27 -f -y
choco install golang -f -y
choco install mingw -f -y
python setup.py sdist
- name: Build Linux wheels and sdist
- name: Build Linux wheels
if: runner.os == 'Linux'
uses: pypa/[email protected]
env:
CIBW_BEFORE_ALL: 'pwd && ls && chmod +x ./scripts/setup-linux.sh && ./scripts/setup-linux.sh'
CIBW_BEFORE_ALL: 'sh ./scripts/install-go.sh'
CIBW_BUILD: cp37-* cp38-* cp39-* cp310-*
CIBW_SKIP: "cp35-* *-win32 *-manylinux_i686 *-manylinux_aarch64 *-manylinux_ppc64le *-manylinux_s390x *-musllinux_*"
run: |
python setup.py sdist
python3 -m cibuildwheel --output-dir wheelhouse
CIBW_SKIP: "*-musllinux_*"
CIBW_ARCHS: x86_64 i686 aarch64

- name: Build macOS wheels
if: runner.os == 'macOS'
uses: pypa/[email protected]
env:
CIBW_BEFORE_ALL: 'pwd && ls && chmod +x ./scripts/setup-macos.sh && ./scripts/setup-macos.sh'
CIBW_BUILD: cp37-* cp38-* cp39-* cp310-*
CIBW_SKIP: "cp35-* *-win32 *-manylinux_i686 *-manylinux_aarch64 *-manylinux_ppc64le *-manylinux_s390x *-musllinux_*"
run: |
python3 -m cibuildwheel --output-dir wheelhouse
CIBW_ARCHS: x86_64 universal2

- name: Build Windows wheels
if: runner.os == 'Windows'
uses: pypa/[email protected]
env:
CIBW_BUILD: cp37-* cp38-* cp39-* cp310-*
CIBW_SKIP: "cp35-* *-win32 *-manylinux_i686 *-manylinux_aarch64 *-manylinux_ppc64le *-manylinux_s390x *-musllinux_*"
run: |
go version
python -m cibuildwheel --output-dir wheelhouse
CIBW_BUILD: cp38-* cp39-* cp310-*
CIBW_SKIP: cp37-*

- uses: actions/upload-artifact@v2
with:
path: |
./wheelhouse/*.whl
./dist/*.tar.gz
# - name: Publish sdist
# if: runner.os == 'Linux'
Expand All @@ -73,11 +71,6 @@ jobs:
# twine check ./dist/*.tar.gz
# twine upload --skip-existing ./dist/*

# - uses: actions/upload-artifact@v2
# with:
# path: |
# ./wheelhouse/*.whl
# ./dist/*.tar.gz

# - name: Publish wheels
# env:
Expand Down
10 changes: 7 additions & 3 deletions python_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func Starlark_new(pytype *C.PyTypeObject, args *C.PyObject, kwargs *C.PyObject)
}
}

self.state_id = C.ulong(stateId)
STATE[stateId] = &StarlarkState{Globals: starlark.StringDict{}, Mutex: sync.RWMutex{}}
self.state_id = C.uint64_t(stateId)
STATE[stateId] = &StarlarkState{Globals: starlark.StringDict{}, Mutex: sync.RWMutex{}, Print: nil}
return self
}

Expand Down Expand Up @@ -145,7 +145,11 @@ func Starlark_dealloc(self *C.Starlark) {
defer STATE_MUTEX.Unlock()

stateId := uint64(self.state_id)
state := STATE[stateId]
state, ok := STATE[stateId]

if !ok {
panic(fmt.Errorf("Unknown state: %d (%d)", stateId, self.state_id))
}

state.Mutex.Lock()
defer state.Mutex.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions python_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

//export Starlark_get_print
func Starlark_get_print(self *C.Starlark, closure *C.void) *C.PyObject {
func Starlark_get_print(self *C.Starlark, closure unsafe.Pointer) *C.PyObject {
state := rlockSelf(self)
if state == nil {
return nil
Expand All @@ -26,7 +26,7 @@ func Starlark_get_print(self *C.Starlark, closure *C.void) *C.PyObject {
}

//export Starlark_set_print
func Starlark_set_print(self *C.Starlark, value *C.PyObject, closure *C.void) C.int {
func Starlark_set_print(self *C.Starlark, value *C.PyObject, closure unsafe.Pointer) C.int {
if value == C.Py_None {
value = nil
}
Expand Down
40 changes: 40 additions & 0 deletions scripts/install-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

set -ex

GO_VERSION=1.18.1

if [ -e /etc/alpine-release ] && [ -z "$BASH_VERSION" ]; then
apk add bash curl git go
exit 0
fi

if [ -z "$BASH_VERSION" ]; then
exec bash "$0"
fi

set -eou pipefail

if [ -e /etc/debian_version ]; then
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y curl git
fi

install_go() {
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0

# shellcheck disable=SC1090
. ~/.asdf/asdf.sh

asdf plugin add golang
asdf install golang "$GO_VERSION"

ln -s ~/.asdf/installs/golang/${GO_VERSION}/go/bin/go /usr/local/bin/go
ln -s ~/.asdf/installs/golang/${GO_VERSION}/go/bin/gofmt /usr/local/bin/gofmt
}

(install_go)

go version

env | sort
10 changes: 0 additions & 10 deletions scripts/setup-linux.sh

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/setup-macos.sh

This file was deleted.

3 changes: 2 additions & 1 deletion starlark.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef PYTHON_STARLARK_GO_H
#define PYTHON_STARLARK_GO_H

#include <stdint.h>
#include <stdlib.h>
#define PY_SSIZE_T_CLEAN
#undef Py_LIMITED_API
#include <Python.h>

/* Starlark object */
typedef struct Starlark {
PyObject_HEAD unsigned long state_id;
PyObject_HEAD uint64_t state_id;
} Starlark;

/* Helpers for Cgo, which can't handle varargs or macros */
Expand Down

0 comments on commit e97b433

Please sign in to comment.