packages/app-core/scripts/bun-riscv64/bun-patches/README.md
This directory holds the Bun-side patches that have to land on top of
oven-sh/bun @ ${BUN_TAG} (see ../bun-version.json:bun.tag) so the
build system accepts riscv64-linux-musl as a target.
build.sh applies every *.patch in this directory in lexical order
via git am --3way inside the Bun clone.
Bun's TypeScript build driver explicitly types its Arch as
"x64" | "aarch64" (scripts/build/config.ts). Every codepath downstream
of that — flag selection, CMake processor name, Rust target triple
derivation, dependency build configs — branches on those two values. We
need a small series of patches to:
scripts/build/config.ts
Arch = "x64" | "aarch64" → Arch = "x64" | "aarch64" | "riscv64".detectHost(), accept arch === 'riscv64'. (We only run the
build driver under cross-compile from an x86_64 host, so this is
mostly defensive — but the resolveConfig path goes through detectHost
for build-time host introspection too.)cfg.riscv64: boolean to the Config interface so dep configs
can switch on it ergonomically.scripts/build/flags.ts
cpuTargetFlags, add a riscv64 entry that emits
-march=rv64gc -mabi=lp64d. (Match what the Docker wrappers already
pass — defense in depth, since cpuTargetFlags is applied late and
overrides the wrapper's defaults if the wrapper-supplied flags get
filtered out anywhere.)scripts/build/rust.ts
allRustTargets already covers riscv64gc-unknown-linux-musl as a
Tier-2 prebuilt-std target, but verify the host→rust-triple mapping
emits it when cfg.riscv64 is true.scripts/build/deps/webkit.ts
arch to "amd64" | "arm64"
only. For riscv64, force cfg.webkit === "local" (Bun's WEBKIT_PATH
env-var path) and disable the prebuilt branch — there is no upstream
oven-sh/WebKit tarball for riscv64 and there never will be unless
they publish one. build.sh already exports BUN_WEBKIT_PATH
pointing at the freshly built WebKitBuild/riscv64-Release/, so the
local-mode path is the only one we need to reach.scripts/build/deps/tinycc.ts
oven-sh/tinycc fork has no riscv64 backend. Gate the dep with
enabled: cfg => cfg.tinycc && !cfg.riscv64. The runtime config flag
already follows: bun:ffi's JIT-compile path becomes unavailable on
riscv64, but static FFI bindings still work. This is acceptable for
the Android agent runtime — BUN_DISABLE_TINYCC=1 in build.sh's env
also enforces this through Bun's own toggle.scripts/build/bd.ts (or wherever build:release lives)
--arch=riscv64 --abi=musl and thread it through to the
cmake invocation. The --webkit-path=... flag should already work
unmodified; double-check it's not gated by arch.CMakeLists.txt (top-level)
CMAKE_SYSTEM_PROCESSOR is normalized (search for
aarch64 / arm64 matches), add a riscv64 branch that sets
BUN_CPU=riscv64 and emits the correct -march/-mabi. If the
project gates entire compilation units behind BUN_CPU (some
vendored deps' CMakeLists do), add riscv64 to the allowlist.vendor/bun-uws/uSockets/CMakeLists.txt (and other vendored libs)
CMAKE_C_COMPILER directly. Anything that grep'es
CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" to enable assembly
fast-paths should add a riscv64 branch that falls back to the
portable C implementation. Examples to check:
MI_ARCH switch) — falls back fine.bun-v1.3.13)| File | Touches |
|---|---|
0001-config-add-riscv64-arch.patch | scripts/build/config.ts |
0002-flags-add-riscv64-march-mabi.patch | scripts/build/flags.ts |
0003-zig-add-riscv64-target-triple-and-cpu.patch | scripts/build/zig.ts |
0004-webkit-force-local-mode-on-riscv64.patch | scripts/build/config.ts + deps/webkit.ts |
0005-tinycc-disable-on-riscv64.patch | scripts/build/deps/tinycc.ts |
0006-build-add-riscv64-cli-validation.patch | scripts/build.ts (doc-only) |
0007-deps-per-dep-riscv64-checks.patch | scripts/build/deps/lolhtml.ts |
Note on the original task brief: Bun 1.3.x removed the top-level
CMakeLists.txt — the build is now fully driven by scripts/build.ts
through ninja directly. There is no cmake/ directory to patch, so
"patch #7 CMakeLists.txt processor normalization" from the original
brief was obsolete and is collapsed into 0007 (the per-dep audit).
Likewise the .cargo/config.toml patch is unneeded: lol-html is the
only cargo-built dep, and patch 0007 sets rustTarget = riscv64gc-unknown-linux-${cfg.abi} directly. cargo finds the
cross-clang via the wrapper script in the Docker image's /opt/cross/.
cd ../ # to bun-riscv64/
./validate.sh
Runs git apply --check against a shallow clone of oven-sh/bun @ bun-v1.3.13. See ../README.md for output details.