From 8b9aad67905f22b5e7a5a9b4a7f478edc55fe5ae Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 03:28:15 +0000 Subject: [PATCH 1/7] runai-model-streamer: port to riscv64 Add build-runai-model-streamer.yml, docs/packages/runai-model-streamer.yaml and the riscv64 toolchain patch for version 0.16.1. --- .../workflows/build-runai-model-streamer.yml | 314 ++++++++++++++++++ docs/packages/runai-model-streamer.yaml | 5 + ...-riscv64-as-a-supported-architecture.patch | 50 +++ 3 files changed, 369 insertions(+) create mode 100644 .github/workflows/build-runai-model-streamer.yml create mode 100644 docs/packages/runai-model-streamer.yaml create mode 100644 patches/runai-model-streamer/0.16.1/0001-toolchain-add-riscv64-as-a-supported-architecture.patch diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml new file mode 100644 index 00000000000..7d94e28fe8c --- /dev/null +++ b/.github/workflows/build-runai-model-streamer.yml @@ -0,0 +1,314 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +# +# This workflow is based on: https://github.com/run-ai/runai-model-streamer/blob/master/Makefile +--- +name: Build runai-model-streamer wheels (riscv64) + +on: + workflow_dispatch: + inputs: + version: + description: 'Version glob to (re)build; empty builds every version of docs/packages/runai-model-streamer.yaml not released yet' + required: false + default: '' + pull_request: + branches: [main] + paths: + - '.github/workflows/build-runai-model-streamer.yml' + - 'docs/packages/runai-model-streamer.yaml' + - 'patches/runai-model-streamer/**' + push: + branches: [main] + paths: + - '.github/workflows/build-runai-model-streamer.yml' + - 'docs/packages/runai-model-streamer.yaml' + - 'patches/runai-model-streamer/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +env: + MANYLINUX_RISCV64_IMAGE: quay.io/pypa/manylinux_2_39_riscv64 + # Upstream's own .bazelversion; bazelisk publishes no riscv64 binary, so it is + # bootstrapped from the dist archive instead. + BAZEL_VERSION: '7.6.1' + # Versions bazel 7.6.1's own MODULE.bazel pins; both need a riscv64 fix below. + RULES_PYTHON_VERSION: '0.33.2' + RULES_JAVA_VERSION: '7.6.5' + +jobs: + setup: + uses: $/.github/workflows/_setup.yml + with: + package: runai-model-streamer + version: ${{ inputs.version }} + + bazel: + needs: [setup] + if: needs.setup.outputs.versions != '[]' + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + name: Bootstrap bazel (riscv64) + runs-on: ubuntu-24.04-riscv + timeout-minutes: 120 + + steps: + - name: Restore bazel binary + id: cache + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: bazel-bin + key: bazel-${{ env.BAZEL_VERSION }}-manylinux_riscv64 + + - name: Bootstrap bazel ${{ env.BAZEL_VERSION }} + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p bazel-bin + docker run --rm -i --network=host \ + -v "${GITHUB_WORKSPACE}:/work" \ + -w /work \ + -e BAZEL_VERSION="${BAZEL_VERSION}" \ + -e RULES_PYTHON_VERSION="${RULES_PYTHON_VERSION}" \ + -e RULES_JAVA_VERSION="${RULES_JAVA_VERSION}" \ + "${MANYLINUX_RISCV64_IMAGE}" \ + bash <<'SCRIPT' + set -eux + + dnf install -y --setopt=install_weak_deps=False java-21-openjdk-devel zip unzip + JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")" + export JAVA_HOME + + # rules_python 0.33.2's PLATFORMS has no riscv64 entry, aborting the bootstrap + # (bazelbuild/bazel#23018). Any linux entry is a safe stand-in: the toolchain it names + # is never selected on a riscv64 host. Fixed in bazel 8.2.0; the 7.x backport is open. + mkdir -p /tmp/rules_python + curl -fsSLo /tmp/rules_python.tar.gz "https://github.com/bazel-contrib/rules_python/releases/download/${RULES_PYTHON_VERSION}/rules_python-${RULES_PYTHON_VERSION}.tar.gz" + tar -xzf /tmp/rules_python.tar.gz -C /tmp/rules_python --strip-components=1 + sed -i 's|fail("No platform declared for host OS {} on arch {}".format(os_name, arch))|return "x86_64-unknown-linux-gnu"|' \ + /tmp/rules_python/python/private/toolchains_repo.bzl + + # rules_java 7.x maps riscv64 to a stray-colon include path, so libcpu_profiler.so + # can't find jni_md.h. Fixed in rules_java 8.x, never backported. + mkdir -p /tmp/rules_java + curl -fsSLo /tmp/rules_java.tar.gz "https://github.com/bazelbuild/rules_java/releases/download/${RULES_JAVA_VERSION}/rules_java-${RULES_JAVA_VERSION}.tar.gz" + tar -xzf /tmp/rules_java.tar.gz -C /tmp/rules_java + sed -i 's|\[":include/linux"\]|["include/linux"]|g' /tmp/rules_java/toolchains/BUILD + + mkdir -p /tmp/bazel-src + cd /tmp/bazel-src + curl -fsSLo dist.zip "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip" + unzip -q dist.zip + + EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk \ + --override_module=rules_python=/tmp/rules_python \ + --override_module=rules_java=/tmp/rules_java" \ + bash ./compile.sh + install -m 0755 output/bazel /work/bazel-bin/bazel + SCRIPT + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: bazel-${{ env.BAZEL_VERSION }}-riscv64 + path: bazel-bin/bazel + if-no-files-found: error + + build_wheel: + name: Build runai-model-streamer ${{ matrix.version }} py3-none-manylinux_riscv64 + needs: [setup, bazel] + if: needs.setup.outputs.versions != '[]' + runs-on: ubuntu-24.04-riscv + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + + env: + RUNAI_MODEL_STREAMER_VERSION: ${{ matrix.version }} + + steps: + - name: Checkout runai-model-streamer ${{ env.RUNAI_MODEL_STREAMER_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: run-ai/runai-model-streamer + ref: ${{ env.RUNAI_MODEL_STREAMER_VERSION }} + path: runai-model-streamer + persist-credentials: false + + - name: Checkout python-wheels + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + path: python-wheels + persist-credentials: false + + - name: Patch runai-model-streamer source + working-directory: runai-model-streamer + run: git apply -v ../python-wheels/patches/runai-model-streamer/${{ env.RUNAI_MODEL_STREAMER_VERSION }}/*.patch + + - name: Download bazel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: bazel-${{ env.BAZEL_VERSION }}-riscv64 + path: bazel-bin + + - name: Build the C++ streamer library and package the wheel + run: | + mkdir -p dist + docker run --rm -i --network=host \ + -v "${GITHUB_WORKSPACE}:/work" \ + -w /work/runai-model-streamer \ + -e PACKAGE_VERSION="${RUNAI_MODEL_STREAMER_VERSION}" \ + "${MANYLINUX_RISCV64_IMAGE}" \ + bash <<'SCRIPT' + set -eux + + dnf install -y --setopt=install_weak_deps=False java-21-openjdk-devel + JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")" + export JAVA_HOME + install -m 0755 /work/bazel-bin/bazel /usr/local/bin/bazel + git config --global --add safe.directory '*' + + cd cpp + bazel build streamer:libstreamer.so --config=riscv64 + + cd ../py/runai_model_streamer + /opt/python/cp312-cp312/bin/pip install -q wheel + /opt/python/cp312-cp312/bin/python setup.py bdist_wheel --plat-name manylinux2014_riscv64 + cp dist/*.whl /work/dist/ + SCRIPT + + - name: Verify the wheel ships a riscv64 shared object + run: | + python3 - dist/*.whl <<'EOF' + import sys, zipfile + with zipfile.ZipFile(sys.argv[1]) as zf: + names = zf.namelist() + so = next(n for n in names if n.endswith("libstreamer/lib/libstreamer.so")) + header = zf.read(so)[:20] + assert header[:4] == b"\x7fELF", header + assert header[18] == 0xF3, header # EM_RISCV + EOF + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runai-model-streamer-${{ matrix.version }}-py3-none-manylinux_riscv64 + path: dist/*.whl + if-no-files-found: error + + test_wheel: + name: Test runai-model-streamer ${{ matrix.version }} on Python ${{ matrix.python-version }} + needs: [setup, build_wheel] + if: needs.setup.outputs.versions != '[]' + runs-on: ubuntu-24.04-riscv + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + python-version: ['3.12', '3.13', '3.14'] + + env: + RUNAI_MODEL_STREAMER_VERSION: ${{ matrix.version }} + + steps: + - name: Checkout runai-model-streamer ${{ env.RUNAI_MODEL_STREAMER_VERSION }} + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: run-ai/runai-model-streamer + ref: ${{ env.RUNAI_MODEL_STREAMER_VERSION }} + path: runai-model-streamer + persist-credentials: false + + - name: Download wheel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: runai-model-streamer-${{ env.RUNAI_MODEL_STREAMER_VERSION }}-py3-none-manylinux_riscv64 + path: wheelhouse + + - name: Install Python + uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 + with: + python-version: ${{ matrix.python-version }} + activate-environment: true + enable-cache: false + + - name: Install the wheel and upstream's test dependencies + env: + UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ + UV_INDEX_STRATEGY: unsafe-best-match + run: uv pip install -r runai-model-streamer/py/runai_model_streamer/requirements.dev wheelhouse/*.whl + + # setup.py's package_data ships libstreamer.so alone; upstream's own dev + # fixtures for the mocked object-storage tests are never part of the + # wheel, so they are copied in from the checkout before running them. + - name: Stage upstream's test fixtures into the installed package + run: | + site="$(python -c 'import runai_model_streamer, os; print(os.path.dirname(runai_model_streamer.__file__))')" + cp -r runai-model-streamer/py/runai_model_streamer/runai_model_streamer/safetensors_streamer/tests/test_files \ + "$site/safetensors_streamer/tests/" + + # Run from the installed package's own parent directory so this exercises the + # wheel's copy, not the checkout's, matching upstream's `make -C py test-unit-real` + # (minus test-dist, which needs a multi-node torchrun harness). + - name: Run upstream's tests against the installed wheel + run: | + site="$(python -c 'import runai_model_streamer, os; print(os.path.dirname(os.path.dirname(runai_model_streamer.__file__)))')" + cd "$site" + python -m unittest discover -b runai_model_streamer + + gpl_sources: + needs: [setup] + if: needs.setup.outputs.versions != '[]' + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + name: Collect GPL sources for runai-model-streamer ${{ matrix.version }} + runs-on: ubuntu-24.04-riscv + + env: + RUNAI_MODEL_STREAMER_VERSION: ${{ matrix.version }} + + steps: + - name: Checkout python-wheels + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: ./actions/collect-gpl-sources + with: + image: ${{ env.MANYLINUX_RISCV64_IMAGE }} + packages: gcc + output: gpl-sources.tar + + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: runai-model-streamer-${{ env.RUNAI_MODEL_STREAMER_VERSION }}-gpl-sources + path: gpl-sources.tar + if-no-files-found: error + + publish: + name: Publish runai-model-streamer ${{ matrix.version }} + needs: [setup, build_wheel, test_wheel, gpl_sources] + if: needs.setup.outputs.versions != '[]' + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.setup.outputs.versions) }} + permissions: + contents: write + pull-requests: write + uses: $/.github/workflows/_publish-wheel.yml + secrets: + app-private-key: ${{ secrets.RISEPROJECT_APP_PRIVATE_KEY }} + with: + artifact-pattern: runai-model-streamer-${{ matrix.version }}-py3-none-manylinux_riscv64 + gpl-sources-artifact: runai-model-streamer-${{ matrix.version }}-gpl-sources + gpl-sources-description: gcc diff --git a/docs/packages/runai-model-streamer.yaml b/docs/packages/runai-model-streamer.yaml new file mode 100644 index 00000000000..48910b2a3a2 --- /dev/null +++ b/docs/packages/runai-model-streamer.yaml @@ -0,0 +1,5 @@ +package-name: runai-model-streamer +source-code: https://github.com/run-ai/runai-model-streamer +license: Apache-2.0 +versions: +- version: 0.16.1 diff --git a/patches/runai-model-streamer/0.16.1/0001-toolchain-add-riscv64-as-a-supported-architecture.patch b/patches/runai-model-streamer/0.16.1/0001-toolchain-add-riscv64-as-a-supported-architecture.patch new file mode 100644 index 00000000000..627eb0aadf1 --- /dev/null +++ b/patches/runai-model-streamer/0.16.1/0001-toolchain-add-riscv64-as-a-supported-architecture.patch @@ -0,0 +1,50 @@ +From 820707245ffc7f9f363fc5de3f5375daacb0a8b9 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Thu, 24 Sep 2026 03:32:40 +0000 +Subject: [PATCH] toolchain: add riscv64 as a supported architecture + +configure_toolchain() and its per-arch .bazelrc block are already fully +generic over the arch string (native.platform constraint is +@platforms//cpu:, gcc tools are resolved as +/usr/bin/-linux-gnu-) -- riscv64 was simply never added to +either list. + +No -march flag is added for riscv64 (unlike aarch64's, which exists only +for a google-cloud-cpp ARM dependency libstreamer.so does not build +against): a native riscv64 build uses the compiler's own default target. + +Upstream-Status: To upstream [this port does not open issues/PRs against third-party repos; riscv64 toolchain support is exactly the kind of change upstream would want once a downstream build proves it works] +--- + cpp/.bazelrc | 3 +++ + cpp/toolchain/configure.bzl | 2 +- + 2 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/cpp/.bazelrc b/cpp/.bazelrc +index 830e568..4a6ccd2 100644 +--- a/cpp/.bazelrc ++++ b/cpp/.bazelrc +@@ -19,5 +19,8 @@ build:aarch64 --copt="-march=armv8-a+crc+crypto" + build:x86_64 --platform_suffix=x86_64 + build:x86_64 --platforms=@toolchain//:x86_64 + ++build:riscv64 --platform_suffix=riscv64 ++build:riscv64 --platforms=@toolchain//:riscv64 ++ + # Azurite testing support (enables AZURE_STORAGE_ACCOUNT_KEY for local testing) + build:azurite --define azurite_testing=true +diff --git a/cpp/toolchain/configure.bzl b/cpp/toolchain/configure.bzl +index 6b89f54..9a04125 100644 +--- a/cpp/toolchain/configure.bzl ++++ b/cpp/toolchain/configure.bzl +@@ -4,7 +4,7 @@ load("//toolchain:rules.bzl", "get_target_triplet", "runai_crosstool_tools") + + # This should map to the devcontainer Dockerfile + # We install gcc-x86-64-linux-gnu and gcc-aarch64-linux-gnu toolchains +-ARCHITECTURES = ["x86_64", "aarch64"] ++ARCHITECTURES = ["x86_64", "aarch64", "riscv64"] + OS = "linux-gnu" + + def _get_gcc_version(repository_ctx, arch): +-- +2.43.0 + From a70e47d8ae600ecfecbc4334421cd2bdc8c85209 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 05:52:28 +0000 Subject: [PATCH 2/7] build-runai-model-streamer: symlink riscv64-linux-gnu-* onto the native compiler cpp/toolchain/rules.bzl resolves gcc/g++/ar/ld/etc as /usr/bin/-linux-gnu-, the Debian cross-toolchain naming upstream's own x86_64/aarch64 devcontainer ships as real binaries. The riscv64 build runs natively inside manylinux_2_39_riscv64 (Rocky-based, not cross-compiling), whose compiler is the unprefixed system gcc/g++, so those paths didn't exist: analysis succeeded (repository_ctx.execute() tolerates a missing binary and just returns empty stdout for gcc-dumpversion), but every compile action then failed execvp'ing a gcc that was never there. Symlinking the expected triplet name onto the real tool fixes it without touching upstream's generic, unmodified toolchain code. --- .github/workflows/build-runai-model-streamer.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml index 7d94e28fe8c..823f86202ba 100644 --- a/.github/workflows/build-runai-model-streamer.yml +++ b/.github/workflows/build-runai-model-streamer.yml @@ -175,6 +175,17 @@ jobs: install -m 0755 /work/bazel-bin/bazel /usr/local/bin/bazel git config --global --add safe.directory '*' + # cpp/toolchain/rules.bzl resolves every tool as /usr/bin/-linux-gnu-, + # the Debian cross-toolchain naming upstream's own devcontainer ships (real + # x86_64-linux-gnu-gcc/aarch64-linux-gnu-gcc binaries there). This image is a + # native (not cross-compiling) riscv64 build of manylinux, so its compiler is + # the unprefixed system gcc/g++ - symlink the triplet-prefixed names the + # toolchain rule expects onto it. + for tool in gcc g++ ar ld cpp gcov nm objdump strip; do + native="$(command -v "$tool" || true)" + [ -n "$native" ] && ln -sf "$native" "/usr/bin/riscv64-linux-gnu-$tool" + done + cd cpp bazel build streamer:libstreamer.so --config=riscv64 From f82257ba5a27ff73ec16297cb61fd848b15342d7 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 08:03:03 +0000 Subject: [PATCH 3/7] runai-model-streamer: patch cxx_builtin_include_directories for RH triplet Job 107529099711 (run 35967283033) failed bazel build streamer:libstreamer.so with an absolute-path-inclusion error on /usr/lib/gcc/riscv64-redhat-linux/14/include/stddef.h, a header gcc includes via its own builtin search path. cpp/toolchain/template/toolchain.bzl declares cxx_builtin_include_directories from the same -linux-gnu naming convention used for the toolchain's tool paths (/usr/bin/-linux-gnu-). That equals the compiler's own -dumpmachine for a genuine Debian cross-gcc (upstream's own devcontainer), but manylinux_2_39_riscv64's gcc is Red Hat's *native* riscv64-redhat-linux build, only reachable under the expected name via the tool symlinks already added in a70e47d8ae -- its own compiled-in include search path still uses its real vendor triplet regardless of the invocation name, so aliasing a directory under a different name (which I tried first and reverted) changes nothing: gcc never looks there. Confirmed by inspecting the real image's filesystem directly (docker create/export, no riscv64 execution needed): only /usr/lib/gcc/riscv64-redhat-linux exists (no .../riscv64-linux-gnu), and the same RH-vs-Debian triplet split also applies to libstdc++'s per-target headers (/usr/include/c++/14/riscv64-redhat-linux vs the Debian-style /usr/include/riscv64-linux-gnu/c++/14 the toolchain config assumes), which would have surfaced as the same class of failure on the first C++ compile. Patch 0002 threads gcc's actual -dumpmachine output down as gcc_machine and uses it for cxx_builtin_include_directories specifically (tool_paths keeps the naming-convention triplet the workflow's symlinks provide). x86_64 and aarch64 are unaffected: a real cross-gcc's -dumpmachine already equals that convention. Verified patches 0001+0002 apply cleanly in sequence against a fresh v0.16.1 checkout, matching the workflow's git apply step, and pass ci_scripts/check_patch.py's Upstream-Status validation. Could not exercise the actual bazel build: manylinux_2_39_riscv64 is a riscv64 image and this host has no riscv64 qemu/binfmt registered (confirmed by a failed docker run), so verification is limited to patch-apply and direct toolchain-source/filesystem inspection, not a real bazel run. --- ...ine-triplet-for-builtin-include-dirs.patch | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 patches/runai-model-streamer/0.16.1/0002-toolchain-use-gcc-s-own-dumpmachine-triplet-for-builtin-include-dirs.patch diff --git a/patches/runai-model-streamer/0.16.1/0002-toolchain-use-gcc-s-own-dumpmachine-triplet-for-builtin-include-dirs.patch b/patches/runai-model-streamer/0.16.1/0002-toolchain-use-gcc-s-own-dumpmachine-triplet-for-builtin-include-dirs.patch new file mode 100644 index 00000000000..367c1fc785b --- /dev/null +++ b/patches/runai-model-streamer/0.16.1/0002-toolchain-use-gcc-s-own-dumpmachine-triplet-for-builtin-include-dirs.patch @@ -0,0 +1,134 @@ +From 75c45793987328b8011252f0f24950e94456b336 Mon Sep 17 00:00:00 2001 +From: Ludovic Henry +Date: Thu, 24 Sep 2026 08:01:06 +0000 +Subject: [PATCH] toolchain: use gcc's own -dumpmachine triplet for builtin + include dirs + +configure_toolchain()'s cxx_builtin_include_directories are built from the +same os+arch naming-convention triplet (-linux-gnu) used to resolve +tool paths (/usr/bin/-linux-gnu-). That equivalence holds for a +genuine Debian cross-toolchain package (a real x86_64-linux-gnu-gcc reports +exactly that as its own -dumpmachine), but not when the tool path is a +same-arch *native* compiler reachable only via a symlink under the expected +name -- its own compiled-in builtin search path (/usr/lib/gcc///include, etc.) still uses its real vendor triplet regardless +of what name it is invoked under. + +This is exactly riscv64's manylinux_riscv64 image: gcc is Red Hat's native +riscv64-redhat-linux build, symlinked to /usr/bin/riscv64-linux-gnu-gcc so +runai_crosstool_tools() finds it. Bazel's own absolute-path sandboxing then +rejects gcc's builtin headers (e.g. stddef.h) because +/usr/lib/gcc/riscv64-redhat-linux//include is not in the declared +riscv64-linux-gnu-based list. + +Thread the compiler's actual -dumpmachine output down as gcc_machine and use +it (falling back to the naming-convention triplet when unset, so x86_64 and +aarch64 are unaffected) for cxx_builtin_include_directories specifically, +while tool_paths keeps using the naming-convention triplet the workflow's +symlinks provide. + +Upstream-Status: To upstream [this port does not open issues/PRs against third-party repos; making cxx_builtin_include_directories match the compiler's own reported triplet is a general robustness fix upstream would likely want] +--- + cpp/toolchain/configure.bzl | 7 ++++++- + cpp/toolchain/template/toolchain.bzl | 23 ++++++++++++++++++++--- + 2 files changed, 26 insertions(+), 4 deletions(-) + +diff --git a/cpp/toolchain/configure.bzl b/cpp/toolchain/configure.bzl +index 9a04125..510ef90 100644 +--- a/cpp/toolchain/configure.bzl ++++ b/cpp/toolchain/configure.bzl +@@ -11,6 +11,10 @@ def _get_gcc_version(repository_ctx, arch): + gcc_tool = runai_crosstool_tools(get_target_triplet(OS, arch))["gcc"] + return repository_ctx.execute([gcc_tool, "-dumpversion"]).stdout.strip() + ++def _get_gcc_machine(repository_ctx, arch): ++ gcc_tool = runai_crosstool_tools(get_target_triplet(OS, arch))["gcc"] ++ return repository_ctx.execute([gcc_tool, "-dumpmachine"]).stdout.strip() ++ + def _get_host_arch(repository_ctx): + return repository_ctx.execute(["/usr/bin/uname", "-m"]).stdout.strip() + +@@ -18,9 +22,10 @@ def _cc_autoconf_toolchain_impl(repository_ctx): + define_statements = [] + for arch in ARCHITECTURES: + gcc_version = _get_gcc_version(repository_ctx, arch) ++ gcc_machine = _get_gcc_machine(repository_ctx, arch) + host_arch = _get_host_arch(repository_ctx) + toolchain_name = arch +- define_statements.append('define_toolchain(name = "%s", os = "%s", host_arch = "%s", arch = "%s", gcc_version = "%s")' % (toolchain_name, OS, host_arch, arch, gcc_version)) ++ define_statements.append('define_toolchain(name = "%s", os = "%s", host_arch = "%s", arch = "%s", gcc_version = "%s", gcc_machine = "%s")' % (toolchain_name, OS, host_arch, arch, gcc_version, gcc_machine)) + + repository_ctx.template( + "BUILD", +diff --git a/cpp/toolchain/template/toolchain.bzl b/cpp/toolchain/template/toolchain.bzl +index 6a4c6cf..36daffc 100644 +--- a/cpp/toolchain/template/toolchain.bzl ++++ b/cpp/toolchain/template/toolchain.bzl +@@ -73,6 +73,15 @@ def _impl(ctx): + target_triplet = get_target_triplet(ctx.attr.os, ctx.attr.arch) + tool_paths = [tool_path(name = k, path = v) for k, v in runai_crosstool_tools(target_triplet).items()] + ++ # gcc_machine is the triplet gcc itself reports (`gcc -dumpmachine`), which is ++ # what its own builtin include search path is actually built from. It is ++ # normally identical to target_triplet (a real x86_64-linux-gnu/aarch64-linux-gnu ++ # cross-gcc reports exactly that), but differs when the "gcc" behind ++ # target_triplet's tool path is a same-arch native compiler under a different ++ # vendor triplet (e.g. Red Hat's riscv64-redhat-linux) made reachable only by a ++ # symlink under the expected name. ++ include_triplet = ctx.attr.gcc_machine if ctx.attr.gcc_machine else target_triplet ++ + # Documented at + # https://docs.bazel.build/versions/main/skylark/lib/cc_common.html#create_cc_toolchain_config_info. + # +@@ -89,7 +98,7 @@ def _impl(ctx): + abi_version = "unknown", + abi_libc_version = "unknown", + tool_paths = tool_paths, +- cxx_builtin_include_directories = _get_include_directories(target_triplet, ctx.attr.gcc_version, ctx.attr.use_cross), ++ cxx_builtin_include_directories = _get_include_directories(include_triplet, ctx.attr.gcc_version, ctx.attr.use_cross), + features = features + ) + +@@ -111,6 +120,11 @@ _toolchain_config = rule( + mandatory = True, + doc = "GCC major version to use (eg: 9)", + ), ++ "gcc_machine": attr.string( ++ mandatory = False, ++ default = "", ++ doc = "The triplet `gcc -dumpmachine` reports, if it differs from os/arch's own naming convention", ++ ), + "use_cross": attr.bool( + mandatory = False, + default = False, +@@ -121,7 +135,7 @@ _toolchain_config = rule( + ) + + +-def define_toolchain(name, os, host_arch, arch, gcc_version): ++def define_toolchain(name, os, host_arch, arch, gcc_version, gcc_machine = ""): + """"define_toolchain creates rules for a cc_toolchain. + + This expects toolchain tools to exist at a canonical path. +@@ -134,6 +148,9 @@ def define_toolchain(name, os, host_arch, arch, gcc_version): + host_arch: The host architecture for this toolchain + arch: The target architecture for this toochain + gcc_version: The GCC version of this toolchain ++ gcc_machine: The triplet `gcc -dumpmachine` reports for this toolchain's ++ compiler, if it differs from the os/arch naming convention used for ++ the tool paths themselves + """ + + native.platform( +@@ -145,7 +162,7 @@ def define_toolchain(name, os, host_arch, arch, gcc_version): + ) + + toolchain_config_name = "%s_toolchain_config" % name +- _toolchain_config(name = toolchain_config_name, os = os, arch = arch, gcc_version = gcc_version, use_cross = host_arch != arch) ++ _toolchain_config(name = toolchain_config_name, os = os, arch = arch, gcc_version = gcc_version, gcc_machine = gcc_machine, use_cross = host_arch != arch) + + empty_target_name = "%s_empty" % name + empty_target_label = ":%s" % empty_target_name +-- +2.43.0 + From f1456f20c425ee98388ac550abcc59112e34a4e7 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 12:10:18 +0000 Subject: [PATCH 4/7] build-runai-model-streamer: install libstdc++-static for the linker's -l:libstdc++.a cpp/toolchain/template/toolchain.bzl's default_linker_flags feature always passes -static-libstdc++ -l:libstdc++.a for every link action on every arch (a deliberate upstream choice, not something riscv64-specific to work around). quay.io/pypa/manylinux_2_39_riscv64 has no libstdc++.a: verified by exporting the real image's filesystem (docker create/export), which has only usr/lib64/libstdc++.so.6* and usr/lib/gcc/riscv64-redhat-linux/14/ libstdc++.so, no .a. The archive ships in Rocky 10's CRB repo as libstdc++-static (riscv64, 14.3.1-4.4.el10, confirmed against CRB's primary.xml.gz) -- CRB is already enabled in this image's repo config, so this is a one-package dnf install, not a toolchain/BUILD patch. No change needed to the gpl_sources job: libstdc++-static's source RPM is gcc-14.3.1-4.4.el10.src.rpm, already covered by the existing `packages: gcc` collect-gpl-sources input. --- .github/workflows/build-runai-model-streamer.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml index 823f86202ba..86a3537b43e 100644 --- a/.github/workflows/build-runai-model-streamer.yml +++ b/.github/workflows/build-runai-model-streamer.yml @@ -169,7 +169,10 @@ jobs: bash <<'SCRIPT' set -eux - dnf install -y --setopt=install_weak_deps=False java-21-openjdk-devel + # cpp/toolchain/template/toolchain.bzl links -static-libstdc++ -l:libstdc++.a + # for every arch; this image's gcc devel package (libstdc++-devel) ships only + # the shared libstdc++.so, so the static archive needs its own CRB package. + dnf install -y --setopt=install_weak_deps=False java-21-openjdk-devel libstdc++-static JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")" export JAVA_HOME install -m 0755 /work/bazel-bin/bazel /usr/local/bin/bazel From 7d54aa85eedc9fb2e233b0a1b9af92a3a275142d Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 15:32:58 +0000 Subject: [PATCH 5/7] runai-model-streamer: install setuptools before setup.py bdist_wheel The cp312-cp312 build image's Python venv has no setuptools preinstalled (newer CPython/pip dropped the implicit bootstrap), so setup.py's own `from setuptools import setup, find_packages` failed with ModuleNotFoundError right after bazel finished building libstreamer.so. Only `wheel` was being pip-installed; add setuptools alongside it. --- .github/workflows/build-runai-model-streamer.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml index 86a3537b43e..98564be69a1 100644 --- a/.github/workflows/build-runai-model-streamer.yml +++ b/.github/workflows/build-runai-model-streamer.yml @@ -193,7 +193,9 @@ jobs: bazel build streamer:libstreamer.so --config=riscv64 cd ../py/runai_model_streamer - /opt/python/cp312-cp312/bin/pip install -q wheel + # cp312's venv has no setuptools preinstalled (newer CPython/pip dropped the + # implicit bootstrap); setup.py's own `from setuptools import setup` needs it. + /opt/python/cp312-cp312/bin/pip install -q setuptools wheel /opt/python/cp312-cp312/bin/python setup.py bdist_wheel --plat-name manylinux2014_riscv64 cp dist/*.whl /work/dist/ SCRIPT From d5da845974dd4d55f0b10f7efd30428c13df2f82 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 16:50:58 +0000 Subject: [PATCH 6/7] runai-model-streamer: fix wheel platform tag to manylinux_2_39_riscv64 setup.py bdist_wheel was tagging the wheel manylinux2014_riscv64, but manylinux2014 (glibc 2.17) predates riscv64 glibc support entirely - it's not a platform tag pip/uv recognize as valid for this arch, unlike the manylinux_2_39_riscv64 tag every other package in this repo uses (matching the actual quay.io/pypa/manylinux_2_39_riscv64 build image). The test job's `uv pip install` refused the wheel outright: error: Failed to determine installation plan cause: A path (wheelhouse/runai_model_streamer-0.16.1-py3-none-manylinux2014_riscv64.whl) dependency is incompatible with the current platform hint: The wheel is compatible with Linux (manylinux2014_riscv64), but you're on Linux (manylinux_2_39_riscv64) --- .github/workflows/build-runai-model-streamer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml index 98564be69a1..645eb62f801 100644 --- a/.github/workflows/build-runai-model-streamer.yml +++ b/.github/workflows/build-runai-model-streamer.yml @@ -196,7 +196,7 @@ jobs: # cp312's venv has no setuptools preinstalled (newer CPython/pip dropped the # implicit bootstrap); setup.py's own `from setuptools import setup` needs it. /opt/python/cp312-cp312/bin/pip install -q setuptools wheel - /opt/python/cp312-cp312/bin/python setup.py bdist_wheel --plat-name manylinux2014_riscv64 + /opt/python/cp312-cp312/bin/python setup.py bdist_wheel --plat-name manylinux_2_39_riscv64 cp dist/*.whl /work/dist/ SCRIPT From fa7d37587be6912fbee53f7027401ea15377fde2 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Thu, 24 Sep 2026 17:17:04 +0000 Subject: [PATCH 7/7] runai-model-streamer: override numpy pin in the test job's dependency install requirements.dev pins numpy==1.24.4, which ships no riscv64 wheel and fails to build from source under Python >=3.12: ModuleNotFoundError: No module named 'distutils' (numpy 1.24.4's legacy setup.py needs distutils, removed from the stdlib in 3.12.) Our registry has riscv64 wheels for numpy 2.5.3 across cp312-cp314t, so override the pin via a uv override file instead of patching upstream's requirements.dev - nothing in this test suite depends on numpy 1.24.4 specifically. --- .github/workflows/build-runai-model-streamer.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-runai-model-streamer.yml b/.github/workflows/build-runai-model-streamer.yml index 645eb62f801..6b6e4147845 100644 --- a/.github/workflows/build-runai-model-streamer.yml +++ b/.github/workflows/build-runai-model-streamer.yml @@ -259,7 +259,14 @@ jobs: env: UV_EXTRA_INDEX_URL: https://pypi.riseproject.dev/simple/ UV_INDEX_STRATEGY: unsafe-best-match - run: uv pip install -r runai-model-streamer/py/runai_model_streamer/requirements.dev wheelhouse/*.whl + # requirements.dev pins numpy==1.24.4, which ships no riscv64 wheel and + # fails to build from source under Python >=3.12 (its legacy setup.py + # needs the stdlib `distutils` module, removed in 3.12). Override it to + # the newer numpy our registry does have a riscv64 wheel for; nothing + # in this test suite depends on numpy 1.24.4 specifically. + run: | + echo "numpy>=1.26,<3" > /tmp/numpy-override.txt + uv pip install --override /tmp/numpy-override.txt -r runai-model-streamer/py/runai_model_streamer/requirements.dev wheelhouse/*.whl # setup.py's package_data ships libstreamer.so alone; upstream's own dev # fixtures for the mocked object-storage tests are never part of the