Skip to content

debian: fix grub package arch selectors for riscv64#2464

Open
monkey-jsun wants to merge 30 commits intogoogle:mainfrom
monkey-jsun:pr/debian-grub-arch
Open

debian: fix grub package arch selectors for riscv64#2464
monkey-jsun wants to merge 30 commits intogoogle:mainfrom
monkey-jsun:pr/debian-grub-arch

Conversation

@monkey-jsun
Copy link
Copy Markdown
Contributor

Summary

  • grub-efi-amd64-bin used [!arm64] which incorrectly pulls amd64 grub on riscv64 (and any other
    non-arm64 arch)
  • Changed to explicit [amd64] selector
  • Added grub-efi-riscv64-bin [riscv64] for riscv64 hosts

No official Bazel binary exists for riscv64, and bazelisk cannot
download Bazel for this architecture. Fail fast with a clear error
message and a ready-to-run shell script for building Bazel 8.5.1
from source using the official dist archive and compile.sh bootstrap.
Currently an unrecognized architecture leaves NODE_DISTRO and
NODE_SHA256SUM unset, causing a confusing curl 404 error later.
Add an explicit exit 1 for riscv64 so any future caller gets a
clear error message immediately.

Note: base/setup-nodejs-env.sh has no callers in the current build.
This change is a precaution against silent failure if that changes.
webpack 5 has deep V8 JIT incompatibilities on riscv64 causing
multiple runtime failures (WebAssembly memory allocation, object
method resolution). The web UI will be absent but all core
cuttlefish host tool functionality is unaffected.

TODO: remove this guard when webpack/V8 WebAssembly support matures
on riscv64, or when the project migrates to the esbuild-based
@angular/build:application builder.
rules_rust 0.68.1 does not support riscv64 as a host architecture.
Patch triple.bzl to:
1. Add riscv64gc to the supported linux architectures list
2. Map the riscv64 os.arch string to riscv64gc (Rust's triple prefix
   for riscv64 with G and C ISA extensions)

Applied via single_version_override in MODULE.bazel so the patch
is automatically applied when Bazel fetches rules_rust.
toolchains_llvm 1.6.0 does not support riscv64 as a host architecture.
Patch three files to add linux-riscv64:
- toolchain/internal/common.bzl: add (linux, riscv64) to SUPPORTED_TARGETS
- toolchain/internal/configure.bzl: add riscv64-unknown-linux-gnu target
  system name mapping
- toolchain/cc_toolchain_config.bzl: add linux-riscv64 toolchain config
  entry mirroring linux-aarch64

Also configure llvm.MODULE.bazel to use the system-installed clang-19
at /usr/lib/llvm-19 as the toolchain root for riscv64, since no
prebuilt LLVM distribution exists for riscv64 Linux host.
rules_rust's crate_universe extension requires a cargo-bazel binary
which has no prebuilt release for riscv64. Fail fast with a clear
error if CARGO_BAZEL_GENERATOR_URL is not set, rather than producing
a confusing download failure.

Users must build cargo-bazel from source and set:
  export CARGO_BAZEL_GENERATOR_URL=file:///path/to/cargo-bazel
Optionally also set CARGO_BAZEL_GENERATOR_SHA256 for verification.
Add riscv64gc-unknown-linux-gnu to the Rust toolchain registration
so cargo-bazel and rustc are available when building on riscv64 host.

Requires cargo-bazel built from rules_rust 0.68.1 source:
  export CARGO_BAZEL_GENERATOR_URL=file://$HOME/.local/cargo-bazel-.../bin/cargo-bazel
  export CARGO_BAZEL_GENERATOR_SHA256=<hash>
The LLVM backend sources select() in BUILD.swiftshader.bazel only lists
x86_64 and aarch64 entries. On riscv64 Bazel fails with 'no matching
condition'. Add //conditions:default: [] so riscv64 falls through to
pure C/software rendering (SwiftShader's CPU renderer works without
arch-specific LLVM backends).
aspect_bazel_lib's expand_template toolchain has no prebuilt binary
for riscv64. Patch the module to add linux_riscv64 support using a
locally built binary at /usr/local/bin/expand_template.

Build the binary from aspect_bazel_lib source:
  go build -o /usr/local/bin/expand_template .
from the tools/expand_template/ directory.
openssl 3.3.1.bcr.1's generated overlay (bazel-openssl-cc) does not
include constants for linux_riscv64. Add riscv64 support via two patches
applied through single_version_override:

1. riscv64_overlay.patch: redirects MODULE.bazel to use a patched overlay
   tarball hosted at monkey-jsun/android-cuttlefish releases, which adds
   constants-linux-riscv64.bzl generated from ./Configure linux64-riscv64.

2. openssl_riscv64_build.patch: adds linux_riscv64 entries to all select()
   blocks in BUILD.bazel (srcs, copts, defines, GEN_FILES genrule).

The constants-linux-riscv64.bzl includes proper riscv64 assembly sources
(aes-riscv64-*.s, ghash-riscv64-*.s, etc.) generated by OpenSSL's
Configure script, not a fallback to another arch.

Overlay tarball: https://github.com/monkey-jsun/android-cuttlefish/releases/tag/openssl-overlay-riscv64-3.3.1.bcr.1
SHA256: 1ff5a8932702296f1fb03336fd79a910a1af16be4f0a03a736d9c38f166627ba
  _is_hermetic_or_exists needs to strip the %workspace% prefix before
checking path existence, so include dirs like lib64/ or arch-specific
c++/v1 are filtered out when they don't exist on the host. This
is a generic bug affecting any toolchain_root usage with absolute paths.
  Add riscv64gc-unknown-linux-gnu to SUPPORTED_PLATFORM_TRIPLES in
  crate_universe so generated BUILD files include riscv64 platform
  constraints.  Use Rust 1.86.0 and 2021 edition to match other archs
…fig.guess

Add riscv64 to SUPPORTED_CPU and triplet_name in platform.bzl.
Pass --build explicitly to pkg-config configure when not cross-
compiling, so outdated config.guess (2015 vintage, bundled in
pkg-config 0.29.2) does not need to detect the host architecture.
Add riscv64 entry to prebuilt_toolchains.bzl pointing to cmake 3.31.8
built from source and hosted on GitHub releases.  Avoids 3+ hour
bootstrap from source on riscv64 hardware.
SharedMemory_posix.cpp has hardcoded __NR_memfd_create syscall numbers
for x86/arm but not riscv64.  Including sys/syscall.h provides the
correct kernel-defined value, so the hardcoded fallback is skipped.
Add riscv64 sources, copts, and deps to BUILD.libffi.bazel select()
blocks, mirroring the existing x86_64 and arm64 patterns.  Provide
pre-generated fficonfig.h and ffi.h for linux-riscv64.
xz BUILD.bazel only has config settings for x86_64 and arm64.  On
riscv64 it falls through to //conditions:default which uses the x86_64
config defining HAVE_IMMINTRIN_H — but immintrin.h is x86-only.
Add a linux_riscv64 config_setting and expand_template that undefs
x86 intrinsics, mirroring the arm64 approach.
…wnload

Replace local /usr/local/bin symlink with rctx.download() from
GitHub releases, eliminating host dependency.  The prebuilt binary
is built from aspect_bazel_lib's Go source for linux/riscv64.
The arch-specific select() defaults to empty sources on riscv64,
leaving WebRtcSpl_SqrtFloor, WebRtcSpl_ComplexBitReverse, and
WebRtcSpl_FilterARFastQ12 undefined.  Add the generic C
implementations, same as arm64 and x86_64 use.
Automate riscv64 host setup for building android-cuttlefish
Rework riscv64 openssl support to generate assembly via perlasm at
build time, matching how x86_64 and aarch64 handle openssl.  The
previous approach (filtering .s/.S files and ASM defines) broke on
SM4 cipher files using bare #if defined(__riscv) guards.

- Add riscv64 to perlasm genrule (cmd, tools, target_compatible_with)
- Add crypto/perlasm/*.pm to PERLASM_TOOLS glob (riscv.pm was missing,
  generic fix applicable to all arches)
- Post-process perlasm output: sed jal->call for PIC-compatible linking
  (upstream perlasm bug in aes-riscv64.pl)
- Add include/crypto/*.def to hdrs glob for riscv_arch.def
- Provide riscv64 perl 5.42.2 toolchain via relocatable-perl-riscv
- Update overlay tarball URL to consolidated prebuilt-riscv64-assests
On riscv64, cargo-bazel has no prebuilt binary and must be provided
via CARGO_BAZEL_GENERATOR_URL.  Preserve this env var (and the
optional SHA256) through debuild so the bazel build inside the
container can find it.
The version from crates.io does not work. Move cargo-bazel build ahead
of bazel since it is shorter.
- install packages needed by debuild
- force locale to be C when bootstraping bazel from source
Add [riscv64] entries for cuttlefish-base, cuttlefish-integration,
and cuttlefish-metrics pointing to bazel-out/riscv64-opt/, matching
the existing amd64 (k8-opt) and arm64 (aarch64-opt) patterns.
Add Containerfile.riscv64 based on debian:trixie with all build
dependencies for riscv64: LLVM/Clang 19, Rust, Go, Bazel (built
from source), and cargo-bazel (built from rules_rust source).
Includes ca-certificates-java for JVM TLS trust store.

Requires Docker seccomp disabled on riscv64 hosts due to
RISCV_FLUSH_ICACHE syscall needed by JVM.
grub-efi-amd64-bin used [!arm64] which incorrectly pulls amd64 grub on
riscv64 hosts. Change to explicit [amd64] selector and add
grub-efi-riscv64-bin [riscv64].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant