diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index 2eb9add72..000000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,44 +0,0 @@ -name-template: 'v$RESOLVED_VERSION' -change-template: '- $TITLE [#$NUMBER](https://github.com/$OWNER/$REPOSITORY/pull/#$NUMBER)' -tag-template: 'v$RESOLVED_VERSION' -template: | - # What's Changed - - $CHANGES - - **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION - -categories: - - title: 'Breaking' - label: 'type: breaking' - - title: 'New' - label: 'type: feature' - - title: 'Bug Fixes' - label: 'type: bug' - - title: 'Maintenance' - label: 'type: maintenance' - - title: 'Documentation' - label: 'type: docs' - - title: 'Other changes' - - title: 'Dependency Updates' - label: 'type: dependencies' - collapse-after: 5 - -version-resolver: - major: - labels: - - 'type: breaking' - minor: - labels: - - 'type: feature' - patch: - labels: - - 'type: bug' - - 'type: maintenance' - - 'type: docs' - - 'type: dependencies' - - 'type: security' - default: patch - -exclude-labels: - - 'skip-changelog' diff --git a/.github/workflows/release.yml b/.github/workflows/create-gh-release.yml similarity index 56% rename from .github/workflows/release.yml rename to .github/workflows/create-gh-release.yml index 9ca17fa31..dc367c32a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/create-gh-release.yml @@ -3,13 +3,11 @@ name: Create release on: push: tags: - - 'v*.*' + - 'v*.*.*' jobs: release_add: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - uses: softprops/action-gh-release@v1 + - uses: softprops/action-gh-release@v2 diff --git a/.github/workflows/docs.yml b/.github/workflows/publish-docs.yml similarity index 69% rename from .github/workflows/docs.yml rename to .github/workflows/publish-docs.yml index 7f10fa528..a7b9a61cb 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/publish-docs.yml @@ -5,33 +5,31 @@ on: branches: [main] jobs: - deploy-docs: + publish-docs: runs-on: ubuntu-latest name: Docs builder and publisher steps: - uses: actions/checkout@v4 - with: - submodules: 'recursive' - uses: actions/setup-python@v5 with: python-version: 3.11 architecture: x64 cache: 'pip' - name: Install dependencies - run: sudo apt-get install -y libqhull-dev - if: runner.os == 'Linux' - - name: Install Python dependencies run: | - pip install --upgrade pip setuptools wheel + sudo apt-get update + sudo apt-get install -y libqhull-dev + - name: Install python dependencies + run: | pip install pip-tools python -m piptools compile --resolver=backtracking --extra=docs -o requirements.txt pyproject.toml pip install -r requirements.txt - - name: Install Gdstk - run: python setup.py install --user + - name: Install gdstk + run: pip install . - name: Build docs run: sphinx-build docs docs/_build - name: Deploy - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/_build diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml new file mode 100644 index 000000000..64e670dd6 --- /dev/null +++ b/.github/workflows/publish-packages.yml @@ -0,0 +1,158 @@ +name: Package Builder + +on: + push: + tags: + - 'v*.*' + workflow_dispatch: + +jobs: + build_manylinux2014: + name: Build wheels on manylinux2014 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_BUILD: "*-manylinux_x86_64 *-manylinux_i686 *-manylinux_aarch64" + CIBW_SKIP: "cp36-* cp37-* pp*" + CIBW_MANYLINUX_X86_64_IMAGE: "manylinux2014" + CIBW_MANYLINUX_I686_IMAGE: "manylinux2014" + CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux2014" + CIBW_BEFORE_ALL_LINUX: > + yum install -y wget && + wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && + tar -xf v8.0.2.tar.gz && + cd qhull-8.0.2 && + cmake -S . -B build && + cmake --build build --target install + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_manylinux_2_28: + name: Build wheels on manylinux_2_28 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_BUILD: "*-manylinux_x86_64 *-manylinux_aarch64" + CIBW_SKIP: "cp36-* cp37-* pp*" + CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_28" + CIBW_MANYLINUX_I686_IMAGE: "manylinux_2_28" + CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux_2_28" + # See https://almalinux.org/blog/2023-12-20-almalinux-8-key-update/ + CIBW_BEFORE_ALL_LINUX: > + rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux && + yum install -y wget && + wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && + tar -xf v8.0.2.tar.gz && + cd qhull-8.0.2 && + cmake -S . -B build && + cmake --build build --target install + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_musllinux: + name: Build wheels on musllinux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pypa/cibuildwheel@v2.16.2 + env: + CIBW_BUILD: "*-musllinux_x86_64 *-musllinux_i686 *-musllinux_aarch64" + CIBW_SKIP: "cp36-* cp37-* pp*" + CIBW_BEFORE_ALL_LINUX: > + apk update && + apk add wget && + wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && + tar -xf v8.0.2.tar.gz && + cd qhull-8.0.2 && + cmake -S . -B build && + cmake --build build --target install + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_macos: + name: Build wheels on MacOS + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: pypa/cibuildwheel@v2.12.3 + env: + CIBW_SKIP: "cp36-* cp37-* pp*" + CIBW_ARCHS_MACOS: "x86_64 universal2" + CIBW_BEFORE_ALL_MACOS: > + wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && + tar -xf v8.0.2.tar.gz && + cd qhull-8.0.2 && + cmake -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_APPLICATIONS=OFF -S . -B build && + cmake --build build --target install + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + build_windows: + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + name: Build wheels for Windows (${{ matrix.python-version }}) + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: ilammy/msvc-dev-cmd@v1 + - uses: johnwason/vcpkg-action@v6 + with: + manifest-dir: ${{ github.workspace }} + triplet: x64-windows-static + token: ${{ github.token }} + github-binarycache: true + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - name: Install build dependencies (pip) + run: | + python -m pip install --upgrade pip + pip install --upgrade setuptools wheel pip-tools ninja scikit_build_core + python -m piptools compile --resolver=backtracking -o requirements.txt pyproject.toml + pip install -r requirements.txt + - name: Build Python ${{ matrix.python-version }} wheel + run: python -m build -w + env: + CMAKE_GENERATOR: "Ninja" + CMAKE_TOOLCHAIN_FILE: "${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" + SKBUILD_CMAKE_ARGS: "-DVCPKG_TARGET_TRIPLET=x64-windows-static;-DVCPKG_MANIFEST_MODE=OFF" + - uses: actions/upload-artifact@v3 + with: + path: dist/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build sdist + run: python -m build -s + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + upload_pypi: + name: Upload wheel to PyPI + needs: [build_manylinux2014, build_manylinux_2_28, build_musllinux, build_macos, build_windows] + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + - uses: pypa/gh-action-pypi-publish@v1.8.5 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/pypi-packages.yml b/.github/workflows/pypi-packages.yml deleted file mode 100644 index 41f8b9085..000000000 --- a/.github/workflows/pypi-packages.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: PyPI Packages - -on: - push: - tags: - - 'v*.*' - workflow_dispatch: - -jobs: - build_wheels: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest] - name: Build wheels on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - uses: pypa/cibuildwheel@v2.16.2 - env: - CIBW_SKIP: "cp36-* cp37-* pp* *_ppc64le *_s390x" - CIBW_ARCHS_MACOS: "x86_64 universal2" - CIBW_BEFORE_ALL_LINUX: > - yum install -y wget || apk add qhull-dev; - wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && - tar -xf v8.0.2.tar.gz && - cd qhull-8.0.2 && - cmake -DBUILD_APPLICATIONS=OFF -S . -B build && - cmake --build build --target install - CIBW_BEFORE_ALL_MACOS: > - wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && - tar -xf v8.0.2.tar.gz && - cd qhull-8.0.2 && - cmake -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_APPLICATIONS=OFF -S . -B build && - cmake --build build --target install - - uses: actions/upload-artifact@v3 - with: - path: ./wheelhouse/gdstk*.whl - - build_windows: - strategy: - fail-fast: false - matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] - name: Build wheels for Windows (${{ matrix.python-version }}) - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - uses: ilammy/msvc-dev-cmd@v1 - - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - cache: 'pip' - - name: Install build dependencies (pip) - run: | - pip install --upgrade pip setuptools wheel - pip install pip-tools ninja conan==1.60 - python -m piptools compile --resolver=backtracking -o requirements.txt pyproject.toml - pip install -r requirements.txt - - name: Install build dependencies (conan) - run: | - conan install . -s compiler.version=16 - - name: Build Python ${{ matrix.python-version }} wheel - run: python setup.py bdist_wheel - env: - CMAKE_GENERATOR: "Ninja" - CMAKE_TOOLCHAIN_FILE: "conan_paths.cmake" - - uses: actions/upload-artifact@v3 - with: - path: "dist/gdstk*.whl" - - build_sdist: - name: Build source distribution - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: 'recursive' - - name: Build sdist - run: pipx run build --sdist - - uses: actions/upload-artifact@v3 - with: - path: dist/*.tar.gz - - upload_pypi: - name: Upload wheel to PyPI - needs: [build_sdist, build_wheels, build_windows] - runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - steps: - - uses: actions/download-artifact@v3 - with: - name: artifact - path: dist - - uses: pypa/gh-action-pypi-publish@v1.8.5 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index c9205f3eb..000000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Release Drafter - -on: - push: - branches: - - main - # pull_request: - # types: [opened, reopened, synchronize] - -permissions: - contents: read - -jobs: - update_release_draft: - permissions: - # write permission is required to create a github release - contents: write - # write permission is required for autolabeler - # otherwise, read permission is required at least - pull-requests: write - runs-on: ubuntu-latest - steps: - # (Optional) GitHub Enterprise requires GHE_HOST variable set - #- name: Set GHE_HOST - # run: | - # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV - - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml - # with: - # config-name: my-config.yml - # disable-autolabeler: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/testing.yml b/.github/workflows/run-tests.yml similarity index 59% rename from .github/workflows/testing.yml rename to .github/workflows/run-tests.yml index c79cdb779..0f8b7acd0 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/run-tests.yml @@ -1,10 +1,6 @@ name: Tests Runner -on: - push: - branches: [main] - pull_request: - workflow_dispatch: +on: [push, pull_request] jobs: linux-macos-test: @@ -12,28 +8,35 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - python-version: ['3.8', '3.11', '3.12'] + python-version: ['3.8', '3.12'] name: Test for ${{ matrix.python-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - with: - submodules: 'recursive' - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} architecture: x64 cache: 'pip' - name: Install dependencies (Linux) - run: sudo apt-get install -y libqhull-dev if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y libqhull-dev - name: Install dependencies (MacOS) - run: brew install qhull if: runner.os == 'macOS' + run: | + # Temporary fix, see https://github.com/actions/setup-python/issues/577 + rm /usr/local/bin/2to3* || true + rm /usr/local/bin/idle3* || true + rm /usr/local/bin/pydoc3* || true + rm /usr/local/bin/python3* || true + rm /usr/local/bin/python3-config* || true + brew update + brew install qhull - name: Install python dependencies run: | - pip install --upgrade pip setuptools wheel - pip install pip-tools pytest + pip install pip-tools python -m piptools compile --resolver=backtracking -o requirements.txt pyproject.toml pip install -r requirements.txt - name: Build and install @@ -53,26 +56,28 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v4 - with: - submodules: 'recursive' - uses: ilammy/msvc-dev-cmd@v1 + - uses: johnwason/vcpkg-action@v6 + with: + manifest-dir: ${{ github.workspace }} + triplet: x64-windows-static + token: ${{ github.token }} + github-binarycache: true - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' - name: Install build dependencies (pip) run: | - pip install --upgrade pip setuptools wheel - pip install pip-tools pytest ninja conan==1.60 + python -m pip install --upgrade pip + pip install --upgrade setuptools wheel pip-tools ninja scikit_build_core python -m piptools compile --resolver=backtracking -o requirements.txt pyproject.toml pip install -r requirements.txt - - name: Install build dependencies (conan) - run: | - conan install . -s compiler.version=16 - - name: Build Python ${{ matrix.python-version }} - run: python setup.py install --user + - name: Build and install + run: pip install . env: CMAKE_GENERATOR: "Ninja" - CMAKE_TOOLCHAIN_FILE: "conan_paths.cmake" + CMAKE_TOOLCHAIN_FILE: "${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" + SKBUILD_CMAKE_ARGS: "-DVCPKG_TARGET_TRIPLET=x64-windows-static;-DVCPKG_MANIFEST_MODE=OFF" - name: Test run: pytest diff --git a/.gitignore b/.gitignore index bf3f0cacf..836ed9903 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Local config compile_commands.json +compile_flags.txt +local/ ### C++ ### # Prerequisites @@ -96,6 +98,8 @@ coverage.xml # Sphinx documentation docs/_build/ +docs/gdstk + # Generated images *.svg *.gds diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29bb..000000000 diff --git a/CMakeLists.txt b/CMakeLists.txt index 25e9d6049..8ce4f5553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,7 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.26) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") -set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Target architectures on macOS") - file(READ include/gdstk/gdstk.hpp HEADER_CONTENTS) string(REGEX MATCH "GDSTK_VERSION \"([^\"]*)\"" _ ${HEADER_CONTENTS}) set(GDSTK_VERSION ${CMAKE_MATCH_1}) @@ -12,8 +10,13 @@ project(gdstk VERSION ${GDSTK_VERSION} LANGUAGES CXX C) +set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Target architectures on macOS") + if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -30,9 +33,16 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) add_subdirectory(docs/cpp) endif() +if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.9") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.9") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace") +endif() + add_subdirectory(external) add_subdirectory(src) -include(GNUInstallDirs) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gdstk.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -CONFIGURE_FILE("gdstk.pc.in" "gdstk.pc") +if("${SKBUILD}" STREQUAL "2") + add_subdirectory(python) +endif() + diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 7af1f3acf..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,13 +0,0 @@ -graft external -graft include -graft python -graft src -graft docs -graft cmake_modules -include CHANGELOG.md -include CMakeLists.txt -include LICENSE -include conanfile.txt -include gdstk.pc.in -include pyproject.toml -include setup.py diff --git a/Makefile b/Makefile index 3dcf4fb1b..53d3b6503 100644 --- a/Makefile +++ b/Makefile @@ -14,17 +14,17 @@ clean: all: test docs examples lib: - cmake -S . -B build -DCMAKE_INSTALL_PREFIX=build/install + cmake -S . -B build -G Ninja -DCMAKE_INSTALL_PREFIX=build -DCMAKE_BUILD_TYPE=Debug cmake --build build --target install module: - python setup.py build $(PYTHON_RELEASE) + python -m build -w docs: module sphinx-build docs docs/_build test: module - pytest + python -m pytest examples: lib cmake --build build --target examples diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index a164d8dce..000000000 --- a/conanfile.txt +++ /dev/null @@ -1,6 +0,0 @@ -[requires] -zlib/1.2.13 -qhull/8.0.1 - -[generators] -cmake_paths diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 4ec1ff65e..05a1ca09f 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,20 +1,27 @@ +include(GNUInstallDirs) + + ## CLIPPER ######################################################## set(clipper_HEADERS clipper/clipper.hpp) -set(clipper_SOURCES clipper/clipper.cpp ${clipper_HEADERS}) +set(clipper_SOURCES clipper/clipper.cpp) -add_library(clipper ${clipper_SOURCES}) +add_library(clipper ${clipper_SOURCES} ${clipper_HEADERS}) if(UNIX) target_link_libraries(clipper m) endif(UNIX) -set_target_properties(clipper PROPERTIES - POSITION_INDEPENDENT_CODE ON - PUBLIC_HEADER "${clipper_HEADERS}") +set_target_properties(clipper PROPERTIES POSITION_INDEPENDENT_CODE ON) + +target_compile_features(clipper PRIVATE cxx_std_11) + +target_include_directories(clipper PUBLIC + $ + $) -include(GNUInstallDirs) install(TARGETS clipper + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/clipper) + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/gdstk.pc.in b/gdstk.pc.in deleted file mode 100644 index 273d1dd0e..000000000 --- a/gdstk.pc.in +++ /dev/null @@ -1,7 +0,0 @@ -Name: ${PROJECT_NAME} -Description: Gdstk library -URL: https://github.com/heitzmann/gdstk -Version: ${PROJECT_VERSION} - -Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} -Libs: -L${CMAKE_INSTALL_FULL_LIBDIR} -lgdstk ${PKGCONF_LIBS} diff --git a/gdstk/__init__.py b/gdstk/__init__.py index f6d100284..7216d9bb5 100644 --- a/gdstk/__init__.py +++ b/gdstk/__init__.py @@ -1,2 +1,2 @@ -from .gdstk import * -from .gdstk import __version__ \ No newline at end of file +from ._gdstk import * +from ._gdstk import __version__ diff --git a/gdstk/gdstk.pyi b/gdstk/_gdstk.pyi similarity index 100% rename from gdstk/gdstk.pyi rename to gdstk/_gdstk.pyi diff --git a/pyproject.toml b/pyproject.toml index 878cff5bb..e9c40af0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,11 @@ +[build-system] +requires = [ + "scikit_build_core", + "numpy; platform_system=='Darwin'", + "oldest-supported-numpy; platform_system!='Darwin'", +] +build-backend = "scikit_build_core.build" + [project] name = "gdstk" version = "0.9.50" @@ -34,40 +42,14 @@ documentation = "https://heitzmann.github.io/gdstk/" repository = "https://github.com/heitzmann/gdstk" changelog = "https://github.com/heitzmann/gdstk/blob/main/CHANGELOG.md" +[tool.scikit-build] +cmake.version = ">=3.26" +# cmake.build-type = "debug" +build-dir = "build/{wheel_tag}" +sdist.reproducible = false +# package_data={"gdstk": ["*.pyi", "py.typed"]}, +wheel.packages = ["gdstk"] +install.components = ["_gdstk"] + [tool.black] line-length = 100 - -[build-system] -requires = [ - "setuptools>=42", - "wheel", - "numpy; platform_system=='Darwin'", - "oldest-supported-numpy; platform_system!='Darwin'", -] - -[tool.tbump] - -[[tool.tbump.before_commit]] -cmd = "git add CHANGELOG.md" -name = "create & check changelog" - -[[tool.tbump.file]] -src = "pyproject.toml" - -[[tool.tbump.file]] -src = "include/gdstk/gdstk.hpp" - -[tool.tbump.git] -message_template = "Bump to {new_version}" -tag_template = "v{new_version}" - -[tool.tbump.version] -current = "0.9.50" -regex = ''' - (?P\d+) - \. - (?P\d+) - \. - (?P\d+) - ''' - diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 000000000..48db879de --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,14 @@ +include(GNUInstallDirs) + +find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) + +python_add_library(_gdstk MODULE WITH_SOABI "gdstk_module.cpp") + +target_compile_features(_gdstk PRIVATE cxx_std_11) + +target_link_libraries(_gdstk PRIVATE gdstk Python::NumPy) + +install(TARGETS _gdstk + COMPONENT _gdstk + DESTINATION ${SKBUILD_PROJECT_NAME}) + diff --git a/python/gdstk_module.cpp b/python/gdstk_module.cpp index 321865628..13972db38 100644 --- a/python/gdstk_module.cpp +++ b/python/gdstk_module.cpp @@ -1949,7 +1949,7 @@ static int gdstk_exec(PyObject* module) { static PyModuleDef_Slot gdstk_slots[] = {{Py_mod_exec, (void*)gdstk_exec}, {0, NULL}}; static struct PyModuleDef gdstk_module = {PyModuleDef_HEAD_INIT, - "gdstk", + "_gdstk", gdstk_module_doc, 0, gdstk_methods, @@ -1958,7 +1958,7 @@ static struct PyModuleDef gdstk_module = {PyModuleDef_HEAD_INIT, NULL, NULL}; -PyMODINIT_FUNC PyInit_gdstk(void) { +PyMODINIT_FUNC PyInit__gdstk(void) { PyDateTime_IMPORT; PyObject* module = PyModuleDef_Init(&gdstk_module); if (!module) { diff --git a/setup.py b/setup.py deleted file mode 100644 index 4e0bd2869..000000000 --- a/setup.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Copyright 2020 Lucas Heitzmann Gabrielli. -# This file is part of gdstk, distributed under the terms of the -# Boost Software License - Version 1.0. See the accompanying -# LICENSE file or - -import numpy -import pathlib -import platform -import setuptools -from setuptools.command.build_ext import build_ext - - -class CMakeBuilder(build_ext): - def run(self): - darwin = platform.system() == "Darwin" - root_dir = pathlib.Path().absolute() - build_dir = pathlib.Path(self.build_temp).absolute() / "cmake_build" - install_dir = build_dir / "install" - - config = "Debug" if self.debug else "Release" - - build_dir.mkdir(parents=True, exist_ok=True) - self.spawn( - [ - "cmake", - "-S", - str(root_dir), - "-B", - str(build_dir), - "-DCMAKE_INSTALL_PREFIX=" + str(install_dir), - "-DCMAKE_BUILD_TYPE=" + config, - ] - ) - if not self.dry_run: - self.spawn( - [ - "cmake", - "--build", - str(build_dir), - "--config", - config, - "--target", - "install", - ] - ) - - pkgconfig = list(install_dir.glob("**/gdstk.pc")) - if len(pkgconfig) == 0: - raise RuntimeError(f"File gdstk.pc not found in cmake install tree: {install_dir}") - - with open(pkgconfig[0]) as pkg: - for line in pkg: - if line.startswith("Cflags:"): - for arg in line.split()[1:]: - if arg.startswith("-I"): - self.extensions[0].include_dirs.append(arg[2:]) - else: - self.extensions[0].extra_compile_args.append(arg) - elif line.startswith("Libs:"): - for arg in line.split()[1:]: - if darwin and (arg == "-lpython" or arg.endswith("Python.framework")): - # Do not link to python in macOS, we use the -undefined dynamic_lookup - # linker flag instead. - # See https://blog.tim-smith.us/2015/09/python-extension-modules-os-x/ - continue - if arg.endswith(".framework"): - # macOS-specific - self.extensions[0].extra_link_args.extend( - ["-framework", arg[arg.rfind("/") + 1 : -10]] - ) - elif arg.startswith("-L"): - self.extensions[0].library_dirs.append(arg[2:]) - elif arg.startswith("-l"): - self.extensions[0].libraries.append(arg[2:]) - else: - self.extensions[0].extra_link_args.append(arg) - - super().run() - - -extra_compile_args = [] -extra_link_args = [] -if platform.system() == "Darwin": - extra_compile_args.extend(["-std=c++11", "-mmacosx-version-min=10.9"]) - extra_link_args.extend(["-undefined", "dynamic_lookup", "-flat_namespace"]) - -setuptools.setup( - ext_modules=[ - setuptools.Extension( - "gdstk.gdstk", - ["python/gdstk_module.cpp"], - include_dirs=[numpy.get_include()], - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args, - ), - ], - packages=["gdstk"], - package_data={"gdstk": ["*.pyi", "py.typed"]}, - include_package_data=True, - cmdclass={"build_ext": CMakeBuilder}, - zip_safe=False, -) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 972243586..a6462af83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,5 @@ +include(GNUInstallDirs) + find_package(ZLIB 1.2.7) if(NOT ZLIB_FOUND) # Check first for header files @@ -65,47 +67,36 @@ set(SOURCE_LIST repetition.cpp robustpath.cpp style.cpp - utils.cpp - ${HEADER_LIST}) + utils.cpp) -add_library(gdstk ${SOURCE_LIST}) +add_library(gdstk ${SOURCE_LIST} ${HEADER_LIST}) -target_compile_features(gdstk PUBLIC cxx_std_11) +set_target_properties(gdstk PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(gdstk PROPERTIES - POSITION_INDEPENDENT_CODE ON - PUBLIC_HEADER "${HEADER_LIST}") +target_compile_features(gdstk PUBLIC cxx_std_11) -target_include_directories(gdstk PUBLIC "${gdstk_SOURCE_DIR}/include") -target_include_directories(gdstk PUBLIC "${gdstk_SOURCE_DIR}/external") -target_include_directories(gdstk PRIVATE ${ZLIB_INCLUDE_DIRS}) -target_include_directories(gdstk PRIVATE ${QHULL_INCLUDE_DIRS}) +target_include_directories(gdstk PUBLIC + $ + $ + $ + ${ZLIB_INCLUDE_DIRS} + ${QHULL_INCLUDE_DIRS}) -target_link_libraries(gdstk clipper) -set(gdstk_LIBS "-lclipper") +target_link_libraries(gdstk + ${ZLIB_LIBRARIES} + ${QHULL_LIBRARIES} + clipper) if(UNIX) - set(gdstk_LIBS "${gdstk_LIBS} -lm") + target_link_libraries(gdstk m) endif(UNIX) -target_link_libraries(gdstk ${ZLIB_LIBRARIES}) -foreach(IT ${ZLIB_LIBRARIES}) - set(gdstk_LIBS "${gdstk_LIBS} ${IT}") -endforeach() - -target_link_libraries(gdstk ${QHULL_LIBRARIES}) -foreach(IT ${QHULL_LIBRARIES}) - set(gdstk_LIBS "${gdstk_LIBS} ${IT}") -endforeach() - -set(PKGCONF_LIBS ${gdstk_LIBS} PARENT_SCOPE) - source_group( TREE "${PROJECT_SOURCE_DIR}/include" PREFIX "Header Files" FILES ${HEADER_LIST}) -include(GNUInstallDirs) install(TARGETS gdstk + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gdstk) + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gdstk) diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..9b8d80ebb --- /dev/null +++ b/vcpkg.json @@ -0,0 +1 @@ +{"dependencies": ["qhull", "zlib"]}