diff --git a/.github/workflows/mpy_native_module.yaml b/.github/workflows/mpy_native_module.yaml index 92f2f30..2c8f2a8 100644 --- a/.github/workflows/mpy_native_module.yaml +++ b/.github/workflows/mpy_native_module.yaml @@ -11,188 +11,112 @@ on: jobs: build: + name: "Build all architectures and mpy versions" runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - micropython_version: ["1.22.2", "1.23.0", "1.24.1", "1.25.0", "1.26.0"] - ARCH: - - "x86" - - "x64" - - "armv6m" - - "armv7m" - - "armv7emsp" - - "armv7emdp" - - "xtensa" - - "xtensawin" - - "rv32imc" - exclude: - # rv32imc is only valid for micropython >=1.25.0 - - micropython_version: "1.22.2" - ARCH: "rv32imc" - - micropython_version: "1.23.0" - ARCH: "rv32imc" - - micropython_version: "1.24.1" - ARCH: "rv32imc" - env: - ARCH: ${{ matrix.ARCH }} steps: - name: Check out repository uses: actions/checkout@v4 with: fetch-depth: 0 - # Fixes some bugs on some platforms? - - name: Replace "static const uint8_t" with "const uint8_t" + - name: Export module version run: | - find . -type f -name "*.c" -exec sed -i 's/static const uint8_t/const uint8_t/g' {} + + VERSION=$(git describe --tags --always) + echo "Detected version is: $VERSION" + echo "VERSION=$VERSION" >> $GITHUB_ENV - - name: Set up python ${{ matrix.python-version }} - if: env.ARCH != 'xtensa' - uses: actions/setup-python@v5 + - name: Build native module + uses: BrianPugh/build-mpy-native-module@v1 with: - python-version: "3.11" + # See https://github.com/BrianPugh/build-mpy-native-module for the + # MPY subversion <-> MicroPython version mapping and all options. + mpy-version: 6.2, 6.3 + architecture: all + output-name: pythontemplate-${{ env.VERSION }} + static-const-workaround: true - - name: Install Belay - run: | - pipx install belay + - name: Display built artifacts + run: ls -alh dist/*.mpy - - name: Install Xtensa dependencies - if: env.ARCH == 'xtensa' - run: | - sudo apt-get update - sudo apt-get install -y \ - gperf \ - help2man \ - libtool-bin \ - python3 \ - python3-dev - - - name: arm-none-eabi-gcc GNU Arm Embedded Toolchain - if: startsWith(env.ARCH, 'arm') - uses: carlosperate/arm-none-eabi-gcc-action@v1.8.1 - - - name: Install RISC-V toolchain for rv32imc - if: env.ARCH == 'rv32imc' - run: | - sudo apt-get update - sudo apt-get install -y gcc-riscv64-unknown-elf picolibc-riscv64-unknown-elf - - - name: Install Micropython Build Dependencies - run: | - sudo apt-get update && sudo apt-get install gcc-multilib - pip install pyelftools + - name: Upload Native Module MPY Files + uses: actions/upload-artifact@v4 + with: + name: mpy-native-module-all + path: "dist/*.mpy" - - name: Cache Setup Xtensa Toolchain (ESP8266) - if: env.ARCH == 'xtensa' - uses: actions/cache@v4 + test: + name: "Test x64 mpy ${{ matrix.mpy_version }}" + runs-on: ubuntu-latest + needs: + - build + strategy: + fail-fast: false + matrix: + include: + # Runtime must match the mpy subversion to load native modules + - mpy_version: "6.2" + micropython_version: "v1.22.2" + - mpy_version: "6.3" + micropython_version: "v1.27.0" + steps: + - name: Check out repository + uses: actions/checkout@v4 with: - path: | - esp-open-sdk/xtensa-lx106-elf - key: xtensa-toolchain-${{ hashFiles('**/Makefile') }} - restore-keys: | - xtensa-toolchain- - - - name: Clone and build Xtensa toolchain - if: env.ARCH == 'xtensa' - run: | - if [ ! -d "esp-open-sdk" ]; then - git clone --branch fix-ubuntu-21.10-build --recursive https://github.com/BrianPugh/esp-open-sdk.git - cd esp-open-sdk - unset LD_LIBRARY_PATH - make - cd .. - fi - echo "$PWD/esp-open-sdk/xtensa-lx106-elf/bin" >> $GITHUB_PATH - - - name: Cache Setup ESP-IDF (ESP32) - if: env.ARCH == 'xtensawin' - uses: actions/cache@v4 + fetch-depth: 0 + + - name: Download Native Module Artifacts + uses: actions/download-artifact@v4 with: - path: | - esp-idf - ~/.espressif - !esp-idf/.git - key: esp-idf-${{ hashFiles('**/Makefile') }} - restore-keys: | - esp-idf- - - - name: Setup ESP-IDF (ESP32) - if: env.ARCH == 'xtensawin' - run: | - if [ ! -d "esp-idf" ]; then - git clone -b v5.0.6 --recursive https://github.com/espressif/esp-idf.git - cd esp-idf - git submodule update --init --recursive - ./install.sh - cd .. - fi - cd esp-idf - ENV_BEFORE=$(env) - source export.sh - ENV_AFTER=$(env) - echo "$ENV_AFTER" | grep -vxF "$ENV_BEFORE" | grep '=' | while IFS='=' read -r name value - do - echo "exporting to GITHUB_ENV: ${name}=${value}" - echo "${name}=${value}" >> $GITHUB_ENV - done + name: mpy-native-module-all + path: dist - name: Install MicroPython uses: BrianPugh/install-micropython@v2 with: - reference: v${{ matrix.micropython_version }} + reference: ${{ matrix.micropython_version }} + + - name: Install Belay + run: pipx install belay - - name: Export MicroPython version. + - name: Export module version run: | - export VERSION=$(git describe --tags) + VERSION=$(git describe --tags --always) echo "VERSION=$VERSION" >> $GITHUB_ENV - export MICROPYTHON_VERSION=${{ matrix.micropython_version }} - export MICROPYTHON_VERSION_MAJOR_MINOR=${MICROPYTHON_VERSION%.*} - echo "Detected Micropython Major.Minor: $MICROPYTHON_VERSION_MAJOR_MINOR" - echo "MICROPYTHON_VERSION_MAJOR_MINOR=$MICROPYTHON_VERSION_MAJOR_MINOR" >> $GITHUB_ENV - - - name: Build MicroPython Native Module + - name: Run unit tests against the x64 module run: | - echo "Building architecture $ARCH Complete" - make clean - make ARCH=$ARCH - if [[ "$ARCH" == "x64" ]]; then - belay run micropython -X heapsize=200M -m unittest tests/test_*.py - fi - mv pythontemplate.mpy pythontemplate-${{ env.VERSION }}-mpy${MICROPYTHON_VERSION_MAJOR_MINOR}-${ARCH}.mpy - - - name: Upload Native Module MPY Files - uses: actions/upload-artifact@v4 - with: - name: mpy-native-module-pythontemplate-${{ env.VERSION }}-mpy${{ env.MICROPYTHON_VERSION_MAJOR_MINOR }}-${{ env.ARCH }} - path: "*.mpy" + cp "dist/pythontemplate-${VERSION}-mpy${{ matrix.mpy_version }}-x64.mpy" pythontemplate.mpy + belay run micropython -X heapsize=200M -m unittest tests/test_*.py release_upload: runs-on: ubuntu-latest needs: - build + - test steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Export module version + run: | + VERSION=$(git describe --tags --always) + echo "VERSION=$VERSION" >> $GITHUB_ENV + - name: Download All Native Module Artifacts uses: actions/download-artifact@v4 with: + name: mpy-native-module-all path: mpy-native-modules - pattern: mpy-native-module-* - merge-multiple: true - name: Display All Native Module Artifacts run: ls -alh mpy-native-modules - - name: Upload Single Native Module MPY Archive - uses: actions/upload-artifact@v4 - with: - name: mpy-native-module-all - path: "mpy-native-modules/*.mpy" - - name: Create tarball of mpy files run: | - mkdir -p archives - tar -czvf mpy-native-modules/pythontemplate-${{ env.VERSION }}.tar.gz mpy-native-modules/*.mpy + tar -czvf "pythontemplate-${VERSION}.tar.gz" mpy-native-modules/*.mpy + mv "pythontemplate-${VERSION}.tar.gz" mpy-native-modules/ - name: Release uses: softprops/action-gh-release@v2