diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a31918f..8792fdb 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -10,8 +10,10 @@ 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: @@ -19,50 +21,46 @@ jobs: 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/setup-qemu-action@v1.2.0 - - 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/cibuildwheel@v2.4.0 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/cibuildwheel@v2.4.0 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/cibuildwheel@v2.4.0 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' @@ -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: diff --git a/python_object.go b/python_object.go index bf7adc7..c568ebb 100644 --- a/python_object.go +++ b/python_object.go @@ -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 } @@ -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() diff --git a/python_print.go b/python_print.go index 3ac3d83..8fb4047 100644 --- a/python_print.go +++ b/python_print.go @@ -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 @@ -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 } diff --git a/scripts/install-go.sh b/scripts/install-go.sh new file mode 100755 index 0000000..849e08b --- /dev/null +++ b/scripts/install-go.sh @@ -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 diff --git a/scripts/setup-linux.sh b/scripts/setup-linux.sh deleted file mode 100755 index e3efdd0..0000000 --- a/scripts/setup-linux.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -xeuo pipefail - -if [ ! -f "/usr/bin/go" ]; then - curl -vvv -L -O https://go.dev/dl/go1.18.1.linux-amd64.tar.gz - tar -xf go1.18.1.linux-amd64.tar.gz - mv go /usr/local - ln -s /usr/local/go/bin/go /usr/bin/go -fi diff --git a/scripts/setup-macos.sh b/scripts/setup-macos.sh deleted file mode 100644 index f058453..0000000 --- a/scripts/setup-macos.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -xeuo pipefail - -if [ ! -f "/usr/local/bin/go" ]; then - curl -vvv -L -O https://go.dev/dl/go1.18.1.darwin-amd64.tar.gz - tar -xf go1.18.1.darwin-amd64.tar.gz - mv go /tmp - ln -s /tmp/go/bin/go /usr/local/bin/go -fi diff --git a/starlark.h b/starlark.h index 07be4d4..d93674a 100644 --- a/starlark.h +++ b/starlark.h @@ -1,6 +1,7 @@ #ifndef PYTHON_STARLARK_GO_H #define PYTHON_STARLARK_GO_H +#include #include #define PY_SSIZE_T_CLEAN #undef Py_LIMITED_API @@ -8,7 +9,7 @@ /* 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 */