From 8169a6067935970fca55d479400a29883a636d84 Mon Sep 17 00:00:00 2001 From: ihb2032 Date: Tue, 24 Mar 2026 16:53:57 +0800 Subject: [PATCH 1/5] fix(cpu_features): refactor architecture detection to explicit x86 whitelist Currently, `cpu_features.cc` assumes any non-ARM architecture is x86/x64, which leads to a fatal missing `` error on architectures like RISC-V. This commit refactors the preprocessor macros to explicitly whitelist x86 architectures (`__x86_64__`, `__i386__`, `_M_X64`, `_M_IX86`). All other architectures (RISC-V, ARM, etc.) will now safely fall back to the default zero-initialization, allowing cross-compilation to succeed. Signed-off-by: ihb2032 --- src/ailego/internal/cpu_features.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ailego/internal/cpu_features.cc b/src/ailego/internal/cpu_features.cc index 06e1444d5..d124aea58 100644 --- a/src/ailego/internal/cpu_features.cc +++ b/src/ailego/internal/cpu_features.cc @@ -17,7 +17,9 @@ #if defined(_MSC_VER) #include -#elif !defined(__ARM_ARCH) +#endif + +#if (defined(__x86_64__) || defined(__i386__)) && !defined(_MSC_VER) #include #endif @@ -34,7 +36,7 @@ namespace internal { CpuFeatures::CpuFlags CpuFeatures::flags_; -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) CpuFeatures::CpuFlags::CpuFlags(void) : L1_ECX(0), L1_EDX(0), L7_EBX(0), L7_ECX(0), L7_EDX(0) { int l1[4] = {0, 0, 0, 0}; @@ -48,7 +50,7 @@ CpuFeatures::CpuFlags::CpuFlags(void) L7_ECX = l7[2]; L7_EDX = l7[3]; } -#elif !defined(__ARM_ARCH) +#elif defined(__x86_64__) || defined(__i386__) CpuFeatures::CpuFlags::CpuFlags(void) : L1_ECX(0), L1_EDX(0), L7_EBX(0), L7_ECX(0), L7_EDX(0) { uint32_t eax, ebx, ecx, edx; From 6040065ff15b34e4b65e626beeb324f7d8b19a20 Mon Sep 17 00:00:00 2001 From: ihb2032 Date: Wed, 15 Apr 2026 18:48:11 +0800 Subject: [PATCH 2/5] ci: Add RISE RISC-V runner Introduce the RISC-V CI runner provided by the RISE project. This enables automated testing and building for the RISC-V architecture. Signed-off-by: ihb2032 --- .github/workflows/01-ci-pipeline.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/01-ci-pipeline.yml b/.github/workflows/01-ci-pipeline.yml index c2296f501..173e04248 100644 --- a/.github/workflows/01-ci-pipeline.yml +++ b/.github/workflows/01-ci-pipeline.yml @@ -84,6 +84,14 @@ jobs: os: ubuntu-24.04 compiler: clang + build-and-test-linux-riscv64: + name: Build & Test (linux-riscv64) + needs: lint + uses: ./.github/workflows/03-macos-linux-build.yml + with: + platform: linux-riscv64 + os: ubuntu-24.04-riscv + build-android: name: Build & Test (android) needs: lint From a0dbfc8b2dc1918e059592393f59d42a920a0584 Mon Sep 17 00:00:00 2001 From: ihb2032 Date: Thu, 16 Apr 2026 17:37:03 +0800 Subject: [PATCH 3/5] ci: use python 3.12 for RISC-V64 Signed-off-by: ihb2032 --- .github/workflows/03-macos-linux-build.yml | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 1dd1e45c7..0ffad1b26 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -21,7 +21,6 @@ permissions: contents: read jobs: - # Build and test matrix (parallel execution) build-and-test: name: Build & Test (${{ inputs.platform }}) runs-on: ${{ inputs.os }} @@ -32,7 +31,7 @@ jobs: include: - os: ${{ inputs.os }} platform: ${{ inputs.platform }} - arch_flag: "" # Use appropriate architecture + arch_flag: "" steps: - name: Checkout code @@ -41,12 +40,27 @@ jobs: submodules: recursive - name: Set up Python + if: ${{ !contains(inputs.os, 'riscv') }} uses: actions/setup-python@v6 with: python-version: '3.10' cache: 'pip' cache-dependency-path: 'pyproject.toml' + - name: Select Python on RISC-V + if: ${{ contains(inputs.os, 'riscv') }} + run: | + python3.10 --version + echo "PYTHON=python3.10" >> $GITHUB_ENV + shell: bash + + - name: Select Python on non-RISC-V + if: ${{ !contains(inputs.os, 'riscv') }} + run: | + python --version + echo "PYTHON=python" >> $GITHUB_ENV + shell: bash + - name: Install Clang if: inputs.compiler == 'clang' && runner.os == 'Linux' run: | @@ -61,7 +75,6 @@ jobs: - name: Set up environment variables run: | - # Set number of processors for parallel builds if [[ "${{ matrix.platform }}" == "macos-arm64" ]]; then NPROC=$(sysctl -n hw.ncpu 2>/dev/null || echo 2) else @@ -70,19 +83,17 @@ jobs: echo "NPROC=$NPROC" >> $GITHUB_ENV echo "Using $NPROC parallel jobs for builds" - # Set compiler when clang is requested if [[ "${{ inputs.compiler }}" == "clang" ]]; then echo "CC=clang" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV fi - # Add Python user base bin to PATH for pip-installed CLI tools - echo "$(python -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH + echo "$($PYTHON -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH shell: bash - name: Install dependencies run: | - python -m pip install --upgrade pip \ + $PYTHON -m pip install --upgrade pip \ pybind11==3.0 \ cmake==3.30.0 \ ninja==1.11.1 \ @@ -97,7 +108,7 @@ jobs: CMAKE_GENERATOR="Unix Makefiles" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ - python -m pip install -v . \ + $PYTHON -m pip install -v . \ --no-build-isolation \ --config-settings='cmake.define.BUILD_TOOLS="ON"' \ ${{ matrix.arch_flag }} @@ -112,7 +123,7 @@ jobs: - name: Run Python Tests run: | cd "$GITHUB_WORKSPACE" - python -m pytest python/tests/ + $PYTHON -m pytest python/tests/ shell: bash - name: Run C++ Examples From 603961f665ab108776162a2b7a2fe73bc0e11b28 Mon Sep 17 00:00:00 2001 From: ihb2032 Date: Thu, 16 Apr 2026 21:12:23 +0800 Subject: [PATCH 4/5] ci: add RISC-V numpy dependencies Signed-off-by: ihb2032 --- .github/workflows/03-macos-linux-build.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 0ffad1b26..8f25b9440 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -93,13 +93,15 @@ jobs: - name: Install dependencies run: | - $PYTHON -m pip install --upgrade pip \ - pybind11==3.0 \ - cmake==3.30.0 \ - ninja==1.11.1 \ - pytest \ - scikit-build-core \ - setuptools_scm + $PYTHON -m pip install --upgrade pip + DEPS="pybind11==3.0 cmake==3.30.0 ninja==1.11.1 pytest scikit-build-core setuptools_scm" + + if [[ "${{ inputs.os }}" == *"riscv"* ]]; then + echo "RISC-V architecture detected. Adding build tools for compiling numpy from source..." + DEPS="$DEPS meson-python meson Cython" + fi + + $PYTHON -m pip install $DEPS shell: bash - name: Build from source From bef69b7cc7d17a1b04a08fdd496073bd86e12a81 Mon Sep 17 00:00:00 2001 From: ihb2032 Date: Thu, 16 Apr 2026 21:24:21 +0800 Subject: [PATCH 5/5] ci: add RISC-V wheel cache Signed-off-by: ihb2032 --- .github/workflows/03-macos-linux-build.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/03-macos-linux-build.yml b/.github/workflows/03-macos-linux-build.yml index 8f25b9440..c07887543 100644 --- a/.github/workflows/03-macos-linux-build.yml +++ b/.github/workflows/03-macos-linux-build.yml @@ -91,6 +91,22 @@ jobs: echo "$($PYTHON -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH shell: bash + - name: Get pip cache dir + if: ${{ contains(inputs.os, 'riscv') }} + id: pip-cache + run: | + echo "dir=$($PYTHON -m pip cache dir)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache pip dependencies for RISC-V + if: ${{ contains(inputs.os, 'riscv') }} + uses: actions/cache@v4 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-riscv-pip-${{ hashFiles('**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-riscv-pip- + - name: Install dependencies run: | $PYTHON -m pip install --upgrade pip