Skip to content

Commit

Permalink
Fix python wheel builds
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Oct 27, 2022
1 parent bd328d4 commit e9c6fc9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
default: '0'

env:
CIBW_SKIP: pp* cp27-* cp35-* cp36-* cp37-* cp38-macosx_arm64
CIBW_SKIP: pp* *-musllinux* cp27-* cp35-* cp36-* cp37-* cp38-macosx_arm64
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux2014
CIBW_ARCHS_WINDOWS: auto64
Expand Down
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ endif()

if (MSVC)
set(NANOGUI_NATIVE_FLAGS_DEFAULT "")
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
elseif ((APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") OR (CMAKE_CXX_FLAGS MATCHES "arm64"))
# Apple M1 compatibility
set(NANOGUI_NATIVE_FLAGS_DEFAULT "-mcpu=apple-a12")
else()
Expand Down Expand Up @@ -578,16 +578,21 @@ if (NANOGUI_BUILD_PYTHON)
message(STATUS "NanoGUI: building the Python plugin.")
if (NOT TARGET nanobind::module)
if (SKBUILD)
# Constrain FindPython to find the Python version used by scikit-build
set(Python_VERSION "${PYTHON_VERSION_STRING}")

find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" -c
"import nanobind; print(nanobind.get_cmake_dir())"
"${PYTHON_EXECUTABLE}" -c "import nanobind; print(nanobind.cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")

find_package(nanobind CONFIG REQUIRED)
else()
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Allow overriding the nanobind library used to compile NanoGUI
set(NANOGUI_NANOBIND_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext/nanobind"
Expand Down
16 changes: 6 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
NanoGUI
========================================================================================
|docs| |travis| |appveyor|
|docs| |gha|

.. |docs| image:: https://readthedocs.org/projects/nanogui/badge/?version=latest
:target: http://nanogui.readthedocs.org/en/latest/?badge=latest
:alt: Docs

.. |travis| image:: https://travis-ci.org/wjakob/nanogui.svg?branch=master
:target: https://travis-ci.org/wjakob/nanogui
:alt: Travis Build Status

.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/m8h3uyvdb4ej2i02/branch/master?svg=true
:target: https://ci.appveyor.com/project/wjakob/nanogui/branch/master
:alt: Appveyor Build Status
.. |gha| image:: https://github.com/mitsuba-renderer/nanogui/actions/workflows/build.yml/badge.svg
:target: https://github.com/mitsuba-renderer/nanogui/actions/workflows/build.yml
:alt: GitHub Actions Build Status

.. begin_brief_description
NanoGUI is a minimalistic cross-platform widget library for OpenGL 3+, GLES
2/3, and Metal. It supports automatic layout generation, stateful C++ lambdas
callbacks, a variety of useful widget types and Retina-capable rendering on
Apple devices thanks to NanoVG_ by Mikko Mononen. Python bindings of all
functionality are provided using pybind11_. Binary wheels of NanoGUI are
functionality are provided using nanobind_. Binary wheels of NanoGUI are
available on PyPI_.

**Note**: This repository contains an improved port of the original NanoGUI_.
Expand Down Expand Up @@ -57,7 +53,7 @@ the the repository here incorporates the following changes:
7. The Entypo_ icon font has been replaced by FontAwesome_ (v5.10.1).

.. _NanoVG: https://github.com/memononen/NanoVG
.. _pybind11: https://github.com/wjakob/pybind11
.. _nanobind: https://github.com/wjakob/nanobind
.. _PyPi: https://pypi.org/project/nanogui
.. _NanoGUI: https://github.com/wjakob/nanogui
.. _Tekari: https://rgl.epfl.ch/tekari?url=%2F%2Frgl.s3.eu-central-1.amazonaws.com%2Fmedia%2Fuploads%2Fwjakob%2F2018%2F08%2F27%2Firidescent-paper.txt&log=1
Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <stdexcept>

#define NANOGUI_VERSION_MAJOR 0
#define NANOGUI_VERSION_MINOR 1
#define NANOGUI_VERSION_PATCH 4
#define NANOGUI_VERSION_MINOR 2
#define NANOGUI_VERSION_PATCH 0

#define NANOGUI_STRINGIFY(x) #x
#define NANOGUI_TOSTRING(x) NANOGUI_STRINGIFY(x)
Expand Down
4 changes: 2 additions & 2 deletions include/nanogui/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ class NANOGUI_EXPORT AdvancedGridLayout : public Layout {
/// Allows for printing out Anchor position, size, and alignment.
operator std::string() const {
char buf[50];
std::snprintf(buf, 50, "Format[pos=(%i, %i), size=(%i, %i), align=(%i, %i)]",
pos[0], pos[1], size[0], size[1], (int) align[0], (int) align[1]);
snprintf(buf, 50, "Format[pos=(%i, %i), size=(%i, %i), align=(%i, %i)]",
pos[0], pos[1], size[0], size[1], (int) align[0], (int) align[1]);
return buf;
}
};
Expand Down
2 changes: 1 addition & 1 deletion nanogui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_import('nanogui.nanogui_ext')

def get_cmake_dir():
def cmake_dir():
from os import path
file_dir = path.abspath(path.dirname(__file__))
cmake_path = path.join(file_dir, "share", "cmake", "nanogui")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "scikit-build @ git+https://github.com/scikit-build/scikit-build.git@master", "cmake", "ninja", "nanobind>=0.0.7"]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "nanobind>=0.0.8"]
build-backend = "setuptools.build_meta"
10 changes: 10 additions & 0 deletions src/python/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ int widget_tp_traverse_base(PyObject *self, visitproc visit, void *arg, PyTypeOb
strcmp(name + name_len - suffix_len, suffix) != 0)
continue;


#if PY_VERSION_HEX < 0x03090000
PyObject *func = PyObject_GetAttr(self, key),
*result = nullptr;
if (func) {
result = _PyObject_Vectorcall(func, nullptr, 0, nullptr);
Py_DECREF(func);
}
#else
PyObject *args[] = { self };
PyObject *result = PyObject_VectorcallMethod(
key, args, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, nullptr);
#endif

if (!result) {
PyErr_Clear();
Expand Down

0 comments on commit e9c6fc9

Please sign in to comment.