From 124812e40cc3e2cf1edb8d1dc801c56c0d80c663 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:08:15 -0700 Subject: [PATCH 01/10] First past attempt to add pypy builds. --- .github/workflows/build-wasm.yml | 11 +---- .github/workflows/build.yml | 75 ++++++++++++++++++-------------- .github/workflows/release.yml | 13 +----- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index d2c9b939ac..df86e026c8 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -1,43 +1,34 @@ name: build-wasm - on: [workflow_call, workflow_dispatch] - jobs: build-wasm: runs-on: ubuntu-22.04 steps: - name: Check out repository uses: actions/checkout@v3 - - name: Install Emscripten uses: mymindstorm/setup-emsdk@v13 with: version: 3.1.58 - - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt - - name: Install Python uses: actions/setup-python@v4 with: python-version: "3.12" - - name: Install Python packages run: pip install -r python/requirements.txt - - name: Build wheel run: make build-wasm - - name: Upload wheel uses: actions/upload-artifact@v4 with: name: pyxel-wasm - path: dist/* + path: dist/* \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61b4a0ac4a..2ca2423f7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,106 +1,119 @@ name: build - on: [workflow_call, workflow_dispatch] - jobs: build-winmac: strategy: fail-fast: false matrix: include: + # CPython builds - target: x86_64-pc-windows-msvc os: windows-2022 arch: x64 - + python-impl: cpython + python-version: "3.12" - target: i686-pc-windows-msvc os: windows-2022 arch: x86 - + python-impl: cpython + python-version: "3.12" - target: x86_64-apple-darwin os: macos-13 arch: x64 - + python-impl: cpython + python-version: "3.12" - target: aarch64-apple-darwin os: macos-13 arch: x64 - + python-impl: cpython + python-version: "3.12" + # PyPy builds + - target: x86_64-pc-windows-msvc + os: windows-2022 + arch: x64 + python-impl: pypy + python-version: "3.10" + - target: x86_64-apple-darwin + os: macos-13 + arch: x64 + python-impl: pypy + python-version: "3.10" runs-on: ${{ matrix.os }} steps: - name: Check out repository uses: actions/checkout@v3 - - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt - - name: Install Python uses: actions/setup-python@v4 with: - python-version: "3.12" + python-version: ${{ matrix.python-version }} + python-implementation: ${{ matrix.python-impl }} architecture: ${{ matrix.arch }} - - name: Install Python packages run: pip install -r python/requirements.txt - - name: Build wheel - run: make TARGET=${{ matrix.target }} - + run: make TARGET=${{ matrix.target }} PYTHON_IMPL=${{ matrix.python-impl }} - name: Upload wheel uses: actions/upload-artifact@v4 with: - name: pyxel-${{ matrix.target }} + name: pyxel-${{ matrix.python-impl }}-${{ matrix.target }} path: dist/* - build-linux: strategy: fail-fast: false matrix: include: + # CPython builds - target: x86_64-unknown-linux-gnu image: messense/manylinux2014-cross:x86_64 - + python-impl: cpython + python-version: "3.12" - target: i686-unknown-linux-gnu image: messense/manylinux2014-cross:i686 - + python-impl: cpython + python-version: "3.12" - target: aarch64-unknown-linux-gnu image: messense/manylinux2014-cross:aarch64 - + python-impl: cpython + python-version: "3.12" - target: armv7-unknown-linux-gnueabihf image: messense/manylinux2014-cross:armv7l - + python-impl: cpython + python-version: "3.12" + # PyPy builds (x86_64 only as PyPy doesn't support all architectures) + - target: x86_64-unknown-linux-gnu + image: messense/manylinux2014-cross:x86_64 + python-impl: pypy + python-version: "3.10" runs-on: ubuntu-22.04 container: ${{ matrix.image }} - steps: - name: Check out repository uses: actions/checkout@v3 - - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt - - name: Install Python uses: actions/setup-python@v4 with: - python-version: "3.12" - + python-version: ${{ matrix.python-version }} + python-implementation: ${{ matrix.python-impl }} - name: Install Python packages run: pip install -r python/requirements.txt - - name: Build and install SDL2 run: | SDL2_VERSION=2.0.10 @@ -118,15 +131,13 @@ jobs: make install cd .. rm -rf SDL2-${SDL2_VERSION} - - name: Build wheel run: | export BINDGENFLAGS="-I/usr/${{ matrix.target }}/include/SDL2 -I/usr/${{ matrix.target }}/${{ matrix.target }}/sysroot/usr/include" export RUSTFLAGS="-L/usr/${{ matrix.target }}/lib" - make TARGET=${{ matrix.target }} - + make TARGET=${{ matrix.target }} PYTHON_IMPL=${{ matrix.python-impl }} - name: Upload wheel uses: actions/upload-artifact@v4 with: - name: pyxel-${{ matrix.target }} - path: dist/* + name: pyxel-${{ matrix.python-impl }}-${{ matrix.target }} + path: dist/* \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 30fbe2dec6..dbc020d94a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,48 +1,39 @@ name: release - on: push: tags: - "v*.*.*" - jobs: build: uses: kitao/pyxel/.github/workflows/build.yml@main - release: runs-on: macos-13 needs: build steps: - name: Check out repository uses: actions/checkout@v3 - - name: Download wheels uses: actions/download-artifact@v4 with: path: dist - - name: Flatten wheels run: | find dist -type f -name "*.whl" -exec mv {} dist/ \; find dist -type d -empty -delete - - name: Get Pyxel version run: | PYXEL_VERSION=$(echo $GITHUB_REF | sed 's/refs\/tags\/v//') echo "PYXEL_VERSION=${PYXEL_VERSION}" >> $GITHUB_ENV - - name: Create release uses: softprops/action-gh-release@v1 with: name: Pyxel ${{ env.PYXEL_VERSION }} tag_name: ${{ github.ref }} files: dist/* - - name: Install Python uses: actions/setup-python@v4 with: python-version: "3.12" - - name: Publish wheels run: | pip install twine @@ -50,10 +41,8 @@ jobs: env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - - name: Install Rust uses: dtolnay/rust-toolchain@stable - - name: Publish crates run: | cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} @@ -64,4 +53,4 @@ jobs: cargo publish sleep 60 cd ../pyxel-wrapper - RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo publish + RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo publish \ No newline at end of file From 8ef1fea6efcea95853d48ded6d61b826738e821c Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:15:55 -0700 Subject: [PATCH 02/10] Restore whitespace to build-wasm --- .github/workflows/build-wasm.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index df86e026c8..7aec08a7e0 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -1,19 +1,24 @@ name: build-wasm + on: [workflow_call, workflow_dispatch] + jobs: build-wasm: runs-on: ubuntu-22.04 steps: - name: Check out repository uses: actions/checkout@v3 + - name: Install Emscripten uses: mymindstorm/setup-emsdk@v13 with: version: 3.1.58 + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable + - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: @@ -23,12 +28,15 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3.12" + - name: Install Python packages run: pip install -r python/requirements.txt + - name: Build wheel run: make build-wasm + - name: Upload wheel uses: actions/upload-artifact@v4 with: name: pyxel-wasm - path: dist/* \ No newline at end of file + path: dist/* From 7097a5fe8177e848800d9bd441b50ae59ae4c706 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:16:52 -0700 Subject: [PATCH 03/10] Revert build-wasm. --- .github/workflows/build-wasm.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index 7aec08a7e0..d2c9b939ac 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -13,17 +13,18 @@ jobs: uses: mymindstorm/setup-emsdk@v13 with: version: 3.1.58 - + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable - + - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt + - name: Install Python uses: actions/setup-python@v4 with: From 3a53b099d6017abc998013d35c1c3d2d3dea604a Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:23:51 -0700 Subject: [PATCH 04/10] Fix whitespace and try to add linux build target for arm. --- .github/workflows/build.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ca2423f7a..1d042e5356 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,7 @@ name: build + on: [workflow_call, workflow_dispatch] + jobs: build-winmac: strategy: @@ -42,23 +44,28 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v3 + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable + - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt + - name: Install Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} python-implementation: ${{ matrix.python-impl }} architecture: ${{ matrix.arch }} + - name: Install Python packages run: pip install -r python/requirements.txt + - name: Build wheel run: make TARGET=${{ matrix.target }} PYTHON_IMPL=${{ matrix.python-impl }} - name: Upload wheel @@ -66,6 +73,7 @@ jobs: with: name: pyxel-${{ matrix.python-impl }}-${{ matrix.target }} path: dist/* + build-linux: strategy: fail-fast: false @@ -76,42 +84,57 @@ jobs: image: messense/manylinux2014-cross:x86_64 python-impl: cpython python-version: "3.12" + - target: i686-unknown-linux-gnu image: messense/manylinux2014-cross:i686 python-impl: cpython python-version: "3.12" + - target: aarch64-unknown-linux-gnu image: messense/manylinux2014-cross:aarch64 python-impl: cpython python-version: "3.12" + - target: armv7-unknown-linux-gnueabihf image: messense/manylinux2014-cross:armv7l python-impl: cpython python-version: "3.12" - # PyPy builds (x86_64 only as PyPy doesn't support all architectures) + + # PyPy builds - target: x86_64-unknown-linux-gnu image: messense/manylinux2014-cross:x86_64 python-impl: pypy python-version: "3.10" + + - target: armv7-unknown-linux-gnueabihf + image: messense/manylinux2014-cross:armv7l + python-impl: pypy + python-version: "3.10" + runs-on: ubuntu-22.04 container: ${{ matrix.image }} + steps: - name: Check out repository uses: actions/checkout@v3 + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: toolchain: stable + - name: Install Nightly Rust uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: rustfmt + - name: Install Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} python-implementation: ${{ matrix.python-impl }} + - name: Install Python packages run: pip install -r python/requirements.txt - name: Build and install SDL2 @@ -131,11 +154,13 @@ jobs: make install cd .. rm -rf SDL2-${SDL2_VERSION} + - name: Build wheel run: | export BINDGENFLAGS="-I/usr/${{ matrix.target }}/include/SDL2 -I/usr/${{ matrix.target }}/${{ matrix.target }}/sysroot/usr/include" export RUSTFLAGS="-L/usr/${{ matrix.target }}/lib" make TARGET=${{ matrix.target }} PYTHON_IMPL=${{ matrix.python-impl }} + - name: Upload wheel uses: actions/upload-artifact@v4 with: From 1c18d11faa4cb14d5ff76d4334a03e33cba42635 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:24:28 -0700 Subject: [PATCH 05/10] Revert release.yml --- .github/workflows/release.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dbc020d94a..30fbe2dec6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,39 +1,48 @@ name: release + on: push: tags: - "v*.*.*" + jobs: build: uses: kitao/pyxel/.github/workflows/build.yml@main + release: runs-on: macos-13 needs: build steps: - name: Check out repository uses: actions/checkout@v3 + - name: Download wheels uses: actions/download-artifact@v4 with: path: dist + - name: Flatten wheels run: | find dist -type f -name "*.whl" -exec mv {} dist/ \; find dist -type d -empty -delete + - name: Get Pyxel version run: | PYXEL_VERSION=$(echo $GITHUB_REF | sed 's/refs\/tags\/v//') echo "PYXEL_VERSION=${PYXEL_VERSION}" >> $GITHUB_ENV + - name: Create release uses: softprops/action-gh-release@v1 with: name: Pyxel ${{ env.PYXEL_VERSION }} tag_name: ${{ github.ref }} files: dist/* + - name: Install Python uses: actions/setup-python@v4 with: python-version: "3.12" + - name: Publish wheels run: | pip install twine @@ -41,8 +50,10 @@ jobs: env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + - name: Install Rust uses: dtolnay/rust-toolchain@stable + - name: Publish crates run: | cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} @@ -53,4 +64,4 @@ jobs: cargo publish sleep 60 cd ../pyxel-wrapper - RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo publish \ No newline at end of file + RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" cargo publish From cd6cfda63f29e686ef3ecbf4698ed98d3d962bd4 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:28:50 -0700 Subject: [PATCH 06/10] Tweak whitespace on last line --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d042e5356..15a29f971b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -165,4 +165,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: pyxel-${{ matrix.python-impl }}-${{ matrix.target }} - path: dist/* \ No newline at end of file + path: dist/* From 513cf1f9e76944a446c6349fbe7d82793850be91 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:45:03 -0700 Subject: [PATCH 07/10] Incorporate PYTHON_IMPL to Makefile. --- .github/workflows/build.yml | 14 ++++---- Makefile | 69 ++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15a29f971b..2d6560c1f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,12 +34,12 @@ jobs: os: windows-2022 arch: x64 python-impl: pypy - python-version: "3.10" + python-version: "pypy3.10" - target: x86_64-apple-darwin os: macos-13 arch: x64 python-impl: pypy - python-version: "3.10" + python-version: "pypy3.10" runs-on: ${{ matrix.os }} steps: - name: Check out repository @@ -57,10 +57,9 @@ jobs: components: rustfmt - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - python-implementation: ${{ matrix.python-impl }} architecture: ${{ matrix.arch }} - name: Install Python packages @@ -104,12 +103,12 @@ jobs: - target: x86_64-unknown-linux-gnu image: messense/manylinux2014-cross:x86_64 python-impl: pypy - python-version: "3.10" + python-version: "pypy3.10" - target: armv7-unknown-linux-gnueabihf image: messense/manylinux2014-cross:armv7l python-impl: pypy - python-version: "3.10" + python-version: "pypy3.10" runs-on: ubuntu-22.04 container: ${{ matrix.image }} @@ -130,10 +129,9 @@ jobs: components: rustfmt - name: Install Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - python-implementation: ${{ matrix.python-impl }} - name: Install Python packages run: pip install -r python/requirements.txt diff --git a/Makefile b/Makefile index 17150ca488..2aff56d26f 100644 --- a/Makefile +++ b/Makefile @@ -62,12 +62,24 @@ RUSTUP_TOOLCHAIN=nightly-2025-02-01 CLIPPY_OPTS = -q --all-targets --all-features -- --no-deps MATURIN_OPTS = --manylinux 2014 --auditwheel skip +# Set Python implementation (cpython or pypy) +PYTHON_IMPL ?= cpython + +# Add Python implementation to wheel filename for easier identification +ifeq ($(PYTHON_IMPL),pypy) + MATURIN_OPTS += --interpreter pypy3 + WHEEL_PREFIX = pypy +else + WHEEL_PREFIX = cpython +endif + + ifeq ($(TARGET),) -ENSURE_TARGET = -BUILD_OPTS = --release + ENSURE_TARGET = + BUILD_OPTS = --release else -ENSURE_TARGET = rustup target add $(TARGET) --toolchain $(RUSTUP_TOOLCHAIN) -BUILD_OPTS = --release --target $(TARGET) + ENSURE_TARGET = rustup target add $(TARGET) --toolchain $(RUSTUP_TOOLCHAIN) + BUILD_OPTS = --release --target $(TARGET) endif .PHONY: \ @@ -103,13 +115,58 @@ build: format @$(ENSURE_TARGET) @$(SCRIPTS_DIR)/generate_readme_abspath @cp LICENSE $(PYTHON_DIR)/pyxel - @cd $(PYTHON_DIR); RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) maturin build -o ../$(DIST_DIR) $(BUILD_OPTS) $(MATURIN_OPTS) + @cd $(PYTHON_DIR); RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) PYTHON_IMPL=$(PYTHON_IMPL) maturin build -o ../$(DIST_DIR) $(BUILD_OPTS) $(MATURIN_OPTS) + @# Rename the wheels to include the Python implementation for clarity + @if [ -n "$(TARGET)" ] && [ "$(PYTHON_IMPL)" = "pypy" ]; then \ + for wheel in $(DIST_DIR)/*$(TARGET)*.whl; do \ + if [ -f "$$wheel" ]; then \ + new_name=$$(echo $$wheel | sed -E "s/([^\/]+)-([0-9]+\.[0-9]+\.[0-9]+.*)/\1-$(WHEEL_PREFIX)-\2/"); \ + mv "$$wheel" "$$new_name"; \ + fi; \ + done; \ + fi install: build +ifeq ($(PYTHON_IMPL),pypy) + @pypy3 -m pip install --force-reinstall `ls -rt $(DIST_DIR)/*-$(WHEEL_PREFIX)-*.whl | tail -n 1 || ls -rt $(DIST_DIR)/*.whl | tail -n 1` +else @pip3 install --force-reinstall `ls -rt $(DIST_DIR)/*.whl | tail -n 1` +endif test: install #@cd $(RUST_DIR); cargo test $(BUILD_OPTS) +ifeq ($(PYTHON_IMPL),pypy) + @pypy3 -m unittest discover $(RUST_DIR)/pyxel-wrapper/tests + @pypy3 -m pyxel run $(EXAMPLES_DIR)/01_hello_pyxel.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/02_jump_game.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/03_draw_api.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/04_sound_api.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/05_color_palette.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/06_click_game.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/07_snake.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/08_triangle_api.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/09_shooter.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/10_platformer.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/11_offscreen.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/12_perlin_noise.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/13_bitmap_font.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/14_synthesizer.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/15_tiled_map_file.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/16_transform.py + @pypy3 -m pyxel run $(EXAMPLES_DIR)/99_flip_animation.py + @pypy3 -m pyxel play $(EXAMPLES_DIR)/30sec_of_daylight.pyxapp + @pypy3 -m pyxel play $(EXAMPLES_DIR)/megaball.pyxapp + @pypy3 -m pyxel play $(EXAMPLES_DIR)/8bit-bgm-gen.pyxapp + @pypy3 -m pyxel edit $(EXAMPLES_DIR)/assets/sample.pyxres + @rm -rf testapp testapp.pyxapp + @mkdir -p testapp/assets + @cp $(EXAMPLES_DIR)/10_platformer.py testapp + @cp $(EXAMPLES_DIR)/assets/platformer.pyxres testapp/assets + @pypy3 -m pyxel package testapp testapp/10_platformer.py + @pypy3 -m pyxel play testapp.pyxapp + @rm -rf testapp testapp.pyxapp + @pypy3 -m pyxel watch $(EXAMPLES_DIR) $(EXAMPLES_DIR)/01_hello_pyxel.py +else @python3 -m unittest discover $(RUST_DIR)/pyxel-wrapper/tests @pyxel run $(EXAMPLES_DIR)/01_hello_pyxel.py @pyxel run $(EXAMPLES_DIR)/02_jump_game.py @@ -140,6 +197,7 @@ test: install @pyxel play testapp.pyxapp @rm -rf testapp testapp.pyxapp @pyxel watch $(EXAMPLES_DIR) $(EXAMPLES_DIR)/01_hello_pyxel.py +endif clean-wasm: @make clean TARGET=$(WASM_TARGET) @@ -162,3 +220,4 @@ start-test-server: test-wasm: build-wasm start-test-server test-remote-wasm: fetch-remote-wasm start-test-server + From 027d81781f1a29beb688f6ffbef7059315fd51ec Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 13:47:18 -0700 Subject: [PATCH 08/10] Incorporate pypy to build. --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 2aff56d26f..e5896d0a8b 100644 --- a/Makefile +++ b/Makefile @@ -220,4 +220,3 @@ start-test-server: test-wasm: build-wasm start-test-server test-remote-wasm: fetch-remote-wasm start-test-server - From dfb88cf1a3531a86b29e197d2b9033208b880cec Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 14:00:39 -0700 Subject: [PATCH 09/10] Simply and deduplicate the Makefile after reviewing documentation. --- Makefile | 85 ++++++++++++++++++-------------------------------------- 1 file changed, 27 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index e5896d0a8b..bd71a23dbe 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ WASM_TARGET = wasm32-unknown-emscripten RUSTUP_TOOLCHAIN=nightly-2025-02-01 CLIPPY_OPTS = -q --all-targets --all-features -- --no-deps MATURIN_OPTS = --manylinux 2014 --auditwheel skip +PYTHON_BIN = $(if $(filter pypy,$(PYTHON_IMPL)),pypy3,python3) # Set Python implementation (cpython or pypy) PYTHON_IMPL ?= cpython @@ -135,69 +136,37 @@ endif test: install #@cd $(RUST_DIR); cargo test $(BUILD_OPTS) -ifeq ($(PYTHON_IMPL),pypy) - @pypy3 -m unittest discover $(RUST_DIR)/pyxel-wrapper/tests - @pypy3 -m pyxel run $(EXAMPLES_DIR)/01_hello_pyxel.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/02_jump_game.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/03_draw_api.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/04_sound_api.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/05_color_palette.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/06_click_game.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/07_snake.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/08_triangle_api.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/09_shooter.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/10_platformer.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/11_offscreen.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/12_perlin_noise.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/13_bitmap_font.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/14_synthesizer.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/15_tiled_map_file.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/16_transform.py - @pypy3 -m pyxel run $(EXAMPLES_DIR)/99_flip_animation.py - @pypy3 -m pyxel play $(EXAMPLES_DIR)/30sec_of_daylight.pyxapp - @pypy3 -m pyxel play $(EXAMPLES_DIR)/megaball.pyxapp - @pypy3 -m pyxel play $(EXAMPLES_DIR)/8bit-bgm-gen.pyxapp - @pypy3 -m pyxel edit $(EXAMPLES_DIR)/assets/sample.pyxres + @$(PYTHON_BIN) -m unittest discover $(RUST_DIR)/pyxel-wrapper/tests + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/01_hello_pyxel.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/02_jump_game.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/03_draw_api.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/04_sound_api.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/05_color_palette.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/06_click_game.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/07_snake.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/08_triangle_api.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/09_shooter.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/10_platformer.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/11_offscreen.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/12_perlin_noise.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/13_bitmap_font.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/14_synthesizer.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/15_tiled_map_file.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/16_transform.py + @$(PYTHON_BIN) -m pyxel run $(EXAMPLES_DIR)/99_flip_animation.py + @$(PYTHON_BIN) -m pyxel play $(EXAMPLES_DIR)/30sec_of_daylight.pyxapp + @$(PYTHON_BIN) -m pyxel play $(EXAMPLES_DIR)/megaball.pyxapp + @$(PYTHON_BIN) -m pyxel play $(EXAMPLES_DIR)/8bit-bgm-gen.pyxapp + @$(PYTHON_BIN) -m pyxel edit $(EXAMPLES_DIR)/assets/sample.pyxres @rm -rf testapp testapp.pyxapp @mkdir -p testapp/assets @cp $(EXAMPLES_DIR)/10_platformer.py testapp @cp $(EXAMPLES_DIR)/assets/platformer.pyxres testapp/assets - @pypy3 -m pyxel package testapp testapp/10_platformer.py - @pypy3 -m pyxel play testapp.pyxapp - @rm -rf testapp testapp.pyxapp - @pypy3 -m pyxel watch $(EXAMPLES_DIR) $(EXAMPLES_DIR)/01_hello_pyxel.py -else - @python3 -m unittest discover $(RUST_DIR)/pyxel-wrapper/tests - @pyxel run $(EXAMPLES_DIR)/01_hello_pyxel.py - @pyxel run $(EXAMPLES_DIR)/02_jump_game.py - @pyxel run $(EXAMPLES_DIR)/03_draw_api.py - @pyxel run $(EXAMPLES_DIR)/04_sound_api.py - @pyxel run $(EXAMPLES_DIR)/05_color_palette.py - @pyxel run $(EXAMPLES_DIR)/06_click_game.py - @pyxel run $(EXAMPLES_DIR)/07_snake.py - @pyxel run $(EXAMPLES_DIR)/08_triangle_api.py - @pyxel run $(EXAMPLES_DIR)/09_shooter.py - @pyxel run $(EXAMPLES_DIR)/10_platformer.py - @pyxel run $(EXAMPLES_DIR)/11_offscreen.py - @pyxel run $(EXAMPLES_DIR)/12_perlin_noise.py - @pyxel run $(EXAMPLES_DIR)/13_bitmap_font.py - @pyxel run $(EXAMPLES_DIR)/14_synthesizer.py - @pyxel run $(EXAMPLES_DIR)/15_tiled_map_file.py - @pyxel run $(EXAMPLES_DIR)/16_transform.py - @pyxel run $(EXAMPLES_DIR)/99_flip_animation.py - @pyxel play $(EXAMPLES_DIR)/30sec_of_daylight.pyxapp - @pyxel play $(EXAMPLES_DIR)/megaball.pyxapp - @pyxel play $(EXAMPLES_DIR)/8bit-bgm-gen.pyxapp - @pyxel edit $(EXAMPLES_DIR)/assets/sample.pyxres + @$(PYTHON_BIN) -m pyxel package testapp testapp/10_platformer.py + @$(PYTHON_BIN) -m pyxel play testapp.pyxapp @rm -rf testapp testapp.pyxapp - @mkdir -p testapp/assets - @cp $(EXAMPLES_DIR)/10_platformer.py testapp - @cp $(EXAMPLES_DIR)/assets/platformer.pyxres testapp/assets - @pyxel package testapp testapp/10_platformer.py - @pyxel play testapp.pyxapp - @rm -rf testapp testapp.pyxapp - @pyxel watch $(EXAMPLES_DIR) $(EXAMPLES_DIR)/01_hello_pyxel.py -endif + @$(PYTHON_BIN) -m pyxel watch $(EXAMPLES_DIR) $(EXAMPLES_DIR)/01_hello_pyxel.py + clean-wasm: @make clean TARGET=$(WASM_TARGET) From 3b737f1c1a2b633a7a8b8feba3a2a1cf67f90c42 Mon Sep 17 00:00:00 2001 From: Larry Du Date: Sun, 9 Mar 2025 14:01:40 -0700 Subject: [PATCH 10/10] Simplify and deduplicate. --- Makefile | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Makefile b/Makefile index bd71a23dbe..4f59bb379e 100644 --- a/Makefile +++ b/Makefile @@ -117,15 +117,6 @@ build: format @$(SCRIPTS_DIR)/generate_readme_abspath @cp LICENSE $(PYTHON_DIR)/pyxel @cd $(PYTHON_DIR); RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) PYTHON_IMPL=$(PYTHON_IMPL) maturin build -o ../$(DIST_DIR) $(BUILD_OPTS) $(MATURIN_OPTS) - @# Rename the wheels to include the Python implementation for clarity - @if [ -n "$(TARGET)" ] && [ "$(PYTHON_IMPL)" = "pypy" ]; then \ - for wheel in $(DIST_DIR)/*$(TARGET)*.whl; do \ - if [ -f "$$wheel" ]; then \ - new_name=$$(echo $$wheel | sed -E "s/([^\/]+)-([0-9]+\.[0-9]+\.[0-9]+.*)/\1-$(WHEEL_PREFIX)-\2/"); \ - mv "$$wheel" "$$new_name"; \ - fi; \ - done; \ - fi install: build ifeq ($(PYTHON_IMPL),pypy)