From 87acc536144c1ba04041b28ff2f96d3e70534ee3 Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Tue, 10 Oct 2023 10:41:06 +0100 Subject: [PATCH 1/2] Create python-package.yml Automate build for linux and windows --- .github/workflows/python-package.yml | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..29310c7 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,35 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: ["3.11"] + os: [ubuntu-latest, windows-latest] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + working-directory: ${{github.workspace}}/cydoomgeneric + run: | + python -m pip install --upgrade pip + python -m pip install numpy cython wheel + - name: Build wheel + working-directory: ${{github.workspace}}/cydoomgeneric + run: | + python setup.py bdist_wheel From 7ae71b7419597ab0c1eac9da8844eb56646ef5c8 Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Tue, 10 Oct 2023 10:35:01 +0100 Subject: [PATCH 2/2] Update setup.py for Windows --- README.md | 1 - cydoomgeneric/setup.py | 49 +++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6623129..d48b3de 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,5 @@ $ python democalc.py ## TODO -- Windows build - Fix segfault when closing game - Implement sound diff --git a/cydoomgeneric/setup.py b/cydoomgeneric/setup.py index 9d81c2b..3ce1e1a 100644 --- a/cydoomgeneric/setup.py +++ b/cydoomgeneric/setup.py @@ -13,9 +13,11 @@ """ -from setuptools import Extension, setup, find_packages +from setuptools import Extension, setup from Cython.Build import cythonize +import Cython import numpy +import sys doom_src = ( @@ -102,6 +104,30 @@ ) +libraries = [] +define_macros = [("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")] +extra_compile_args = [] +extra_link_args = [] +compiler_directives = {} + + +if sys.platform == "win32": + libraries.append("user32") +else: + define_macros.extend([ + ("NORMALUNIX", None), + ("LINUX", None), + ("_DEFAULT_SOURCE", None) + ]) + extra_compile_args.append("-Os") + extra_link_args.append("-Wl,--gc-sections") + + +cython_version = list(map(lambda x: int(x) if x.isdigit() else x, Cython.__version__.split("."))) +if cython_version[0] >= 3: + compiler_directives["legacy_implicit_noexcept"] = True + + setup( name="cydoomgeneric", description="Easily portable doom for python", @@ -121,21 +147,14 @@ "./../doomgeneric", numpy.get_include() ], - define_macros=[ - ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"), - ("NORMALUNIX", None), - ("LINUX", None), - ("_DEFAULT_SOURCE", None), - ], - extra_compile_args=[ - "-Os", - ], - extra_link_args=[ - "-Wl,--gc-sections" - ], + define_macros=define_macros, + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, + libraries=libraries ) ], - language_level=2 + language_level=2, + compiler_directives=compiler_directives ), - install_requires=['numpy>=1.20'], + install_requires=['numpy>=1.20'] )