docker/riscv64: fix cross-compiler availability for generate-dockerfile#9589
docker/riscv64: fix cross-compiler availability for generate-dockerfile#9589igorpecovnik wants to merge 3 commits intomainfrom
Conversation
When generating Dockerfiles on native riscv64 hosts, skip cross-compiler packages (gcc-x86-64-linux-gnu, gcc-aarch64-linux-gnu, gcc-arm-linux-*) that don't exist in riscv64 package repositories. This fixes generate-dockerfile failures on riscv64 hosts that tried to install non-existent cross-compilation toolchains. Signed-off-by: Igor Pecovnik <igor@armbian.com>
When generating Dockerfiles, detect the actual host architecture using dpkg --print-architecture and pass it to early_prepare_host_dependencies. This ensures that cross-compiler packages that don't exist on certain architectures (e.g., riscv64) are properly skipped during Dockerfile generation. Signed-off-by: Igor Pecovnik <igor@armbian.com>
Fix cross-compiler package selection for riscv64 hosts in both Docker generation and extensions: - docker.sh: Detect host architecture and pass it to dependency resolution functions - extensions: Check host_arch and skip cross-compilers unavailable on riscv64 (g++-aarch64-linux-gnu, gcc-arm-linux-gnueabi) This fixes generate-dockerfile failures on native riscv64 hosts where cross-compilation toolchains for other architectures don't exist in the package repositories. Signed-off-by: Igor Pecovnik <igor@armbian.com>
📝 WalkthroughWalkthroughThe changes add RISC-V64 host architecture awareness to build dependency functions. Multiple scripts now detect when the host architecture is Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@extensions/c-plus-plus-compiler.sh`:
- Around line 7-13: Add a host_dependencies_ready hook that fails fast when the
arm64 C++ cross-compiler is declared but missing: in the new
host_dependencies_ready function (use the same hook name as
arm64-compat-vdso.sh) check if host_arch != "riscv64" and then verify
availability of the cross-compiler binary (check for either
"g++-aarch64-linux-gnu" or "aarch64-linux-gnu-g++" with command -v); if not
found, emit an error and return non-zero so the dependency phase fails early.
Update the script to reference host_arch and the existing EXTRA_BUILD_DEPS logic
so the check matches when the cross-compiler was appended.
In `@extensions/sunxi-tools.sh`:
- Around line 6-10: Add a readiness-phase check that ensures the 32-bit
cross-compiler exists before allowing the dependency phase to pass: implement a
hook named host_dependencies_ready__sunxi_add_32_bit_c_compiler() (following the
pattern in arm64-compat-vdso.sh) that verifies the presence of
gcc-arm-linux-gnueabi (e.g., command -v or which) and fails readiness if it is
missing; keep the existing riscv64 early-return behavior in the current file but
ensure build_host_tools__compile_sunxi_tools() will not run later when the
compiler is absent by making the readiness hook enforce that requirement.
In `@lib/functions/host/prepare-host.sh`:
- Around line 233-249: The code currently silently skips adding cross-compiler
packages when host_arch == "riscv64", which hides unsupported host/target
combinations during late prep; update adaptative_prepare_host_dependencies() to
detect late-prep concrete targets (when wanted_arch != "all") and if host_arch
== "riscv64" and wanted_arch is not "riscv64" immediately print a clear error
referencing host_arch and wanted_arch and exit non-zero (fail fast) instead of
silently continuing; keep the existing silent-skip behavior only for
Dockerfile-generation cases where wanted_arch == "all". Ensure you reference the
variables host_arch, wanted_arch and the host_dependencies array in your change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0b55f0ab-8e0e-47ca-a2d2-c516c0651ece
📒 Files selected for processing (5)
extensions/arm64-compat-vdso.shextensions/c-plus-plus-compiler.shextensions/sunxi-tools.shlib/functions/host/docker.shlib/functions/host/prepare-host.sh
| # Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64) | ||
| if [[ "${host_arch}" != "riscv64" ]]; then | ||
| declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++-aarch64-linux-gnu" # @TODO: convert to array later | ||
| fi | ||
|
|
||
| # Always add the native g++ compiler | ||
| declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++" # @TODO: convert to array later |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, check if the file exists and examine its full content
fd "c-plus-plus-compiler.sh" -t fRepository: armbian/build
Length of output: 91
🏁 Script executed:
# Check the full content of the extension
cat "extensions/c-plus-plus-compiler.sh"Repository: armbian/build
Length of output: 743
🏁 Script executed:
# Compare with arm64-compat-vdso.sh to see if it has the claimed hook
cat "extensions/arm64-compat-vdso.sh"Repository: armbian/build
Length of output: 2307
🏁 Script executed:
# Search for other host_dependencies_ready hooks in extensions
rg "host_dependencies_ready" extensions/ -A 3Repository: armbian/build
Length of output: 1336
🏁 Script executed:
# Check how other extensions handle architecture-specific dependencies
rg "host_arch.*riscv64" extensions/ -B 2 -A 5Repository: armbian/build
Length of output: 1976
Add a host_dependencies_ready hook to fail fast when arm64 C++ compiler is unavailable.
This extension silently skips g++-aarch64-linux-gnu on riscv64 hosts but lacks the host_dependencies_ready hook that arm64-compat-vdso.sh uses to catch missing cross-compiler toolchains. Without this check, dependency phase succeeds and the error defers to first aarch64-linux-gnu-g++ invocation. Add an explicit runtime check following the arm64-compat-vdso.sh pattern:
Suggested implementation
function add_host_dependencies__add_arm64_c_plus_plus_compiler() {
display_alert "Extension: ${EXTENSION}: Adding arm64 c++ compiler to host dependencies" "g++" "debug"
# Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64)
if [[ "${host_arch}" != "riscv64" ]]; then
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++-aarch64-linux-gnu" # `@TODO`: convert to array later
fi
# Always add the native g++ compiler
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++" # `@TODO`: convert to array later
}
+
+function host_dependencies_ready__add_arm64_c_plus_plus_compiler() {
+ if ! command -v aarch64-linux-gnu-g++ >/dev/null 2>&1; then
+ exit_with_error "Missing arm64 C++ compiler 'aarch64-linux-gnu-g++'; install g++-aarch64-linux-gnu or disable this extension"
+ fi
+}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@extensions/c-plus-plus-compiler.sh` around lines 7 - 13, Add a
host_dependencies_ready hook that fails fast when the arm64 C++ cross-compiler
is declared but missing: in the new host_dependencies_ready function (use the
same hook name as arm64-compat-vdso.sh) check if host_arch != "riscv64" and then
verify availability of the cross-compiler binary (check for either
"g++-aarch64-linux-gnu" or "aarch64-linux-gnu-g++" with command -v); if not
found, emit an error and return non-zero so the dependency phase fails early.
Update the script to reference host_arch and the existing EXTRA_BUILD_DEPS logic
so the check matches when the cross-compiler was appended.
| # Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64) | ||
| if [[ "${host_arch}" == "riscv64" ]]; then | ||
| display_alert "Skipping sunxi 32-bit compiler" "gcc-arm-linux-gnueabi not available on ${host_arch}" "warn" | ||
| return 0 | ||
| fi |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Check if the file exists and examine the relevant section
find . -name "sunxi-tools.sh" -type f | head -5Repository: armbian/build
Length of output: 84
🏁 Script executed:
# Look for the file in extensions directory
git ls-files | grep -i sunxiRepository: armbian/build
Length of output: 50370
🏁 Script executed:
# Check the structure and search for host_dependencies_ready patterns
rg "host_dependencies_ready" --type sh | head -20Repository: armbian/build
Length of output: 600
🏁 Script executed:
# Search for how other extensions handle architecture-specific dependencies
rg "if.*host_arch.*riscv64" --type sh -A 5 | head -30Repository: armbian/build
Length of output: 2148
🏁 Script executed:
# Check the adaptative_prepare_host_dependencies pattern
rg "adaptative_prepare_host_dependencies" --type sh -B 2 -A 10 | head -50Repository: armbian/build
Length of output: 2148
🏁 Script executed:
cat -n extensions/sunxi-tools.shRepository: armbian/build
Length of output: 2115
🏁 Script executed:
cat -n extensions/arm64-compat-vdso.shRepository: armbian/build
Length of output: 2727
🏁 Script executed:
# Check if arm64-compat-vdso has a readiness hook despite the riscv64 skip
grep -n "host_dependencies_ready" extensions/arm64-compat-vdso.shRepository: armbian/build
Length of output: 115
🏁 Script executed:
# Check if sunxi-tools source or makefile references arm-linux-gnueabi
rg "arm-linux-gnueabi|gcc-arm|32" extensions/sunxi-tools.shRepository: armbian/build
Length of output: 405
🏁 Script executed:
# Check the sunxi-tools repository to understand what gets compiled
# The fetch_sources_tools__sunxi_tools function fetches from github
# Let's check the comments and other extensions to understand the 32-bit requirement
rg "sunxi.*32|32.*sunxi" --type sh extensions/ lib/ -B 2 -A 2 | head -40Repository: armbian/build
Length of output: 858
🏁 Script executed:
# Look at how the sunxi-tools make is called
rg "make.*tools|compile.*sunxi" extensions/sunxi-tools.sh -A 5 -B 2Repository: armbian/build
Length of output: 1311
Add an explicit readiness check for the required 32-bit compiler.
On riscv64, this now skips adding gcc-arm-linux-gnueabi and returns success. The dependency phase passes, but the first call to build_host_tools__compile_sunxi_tools() that invokes make -s tools will fail much later. Following the pattern used in arm64-compat-vdso.sh, add a host_dependencies_ready__sunxi_add_32_bit_c_compiler() hook to validate the compiler exists at the readiness phase:
Add readiness check
function add_host_dependencies__sunxi_add_32_bit_c_compiler() {
# Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64)
if [[ "${host_arch}" == "riscv64" ]]; then
display_alert "Skipping sunxi 32-bit compiler" "gcc-arm-linux-gnueabi not available on ${host_arch}" "warn"
return 0
fi
display_alert "Adding armhf C compiler to host dependencies" "for sunxi bootloader compile" "debug"
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} gcc-arm-linux-gnueabi" # `@TODO`: convert to array later
}
+
+function host_dependencies_ready__sunxi_add_32_bit_c_compiler() {
+ if ! command -v arm-linux-gnueabi-gcc >/dev/null 2>&1; then
+ exit_with_error "Missing 32-bit compiler 'arm-linux-gnueabi-gcc' for sunxi bootloader compile"
+ fi
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64) | |
| if [[ "${host_arch}" == "riscv64" ]]; then | |
| display_alert "Skipping sunxi 32-bit compiler" "gcc-arm-linux-gnueabi not available on ${host_arch}" "warn" | |
| return 0 | |
| fi | |
| function add_host_dependencies__sunxi_add_32_bit_c_compiler() { | |
| # Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64) | |
| if [[ "${host_arch}" == "riscv64" ]]; then | |
| display_alert "Skipping sunxi 32-bit compiler" "gcc-arm-linux-gnueabi not available on ${host_arch}" "warn" | |
| return 0 | |
| fi | |
| display_alert "Adding armhf C compiler to host dependencies" "for sunxi bootloader compile" "debug" | |
| declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} gcc-arm-linux-gnueabi" # `@TODO`: convert to array later | |
| } | |
| function host_dependencies_ready__sunxi_add_32_bit_c_compiler() { | |
| if ! command -v arm-linux-gnueabi-gcc >/dev/null 2>&1; then | |
| exit_with_error "Missing 32-bit compiler 'arm-linux-gnueabi-gcc' for sunxi bootloader compile" | |
| fi | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@extensions/sunxi-tools.sh` around lines 6 - 10, Add a readiness-phase check
that ensures the 32-bit cross-compiler exists before allowing the dependency
phase to pass: implement a hook named
host_dependencies_ready__sunxi_add_32_bit_c_compiler() (following the pattern in
arm64-compat-vdso.sh) that verifies the presence of gcc-arm-linux-gnueabi (e.g.,
command -v or which) and fails readiness if it is missing; keep the existing
riscv64 early-return behavior in the current file but ensure
build_host_tools__compile_sunxi_tools() will not run later when the compiler is
absent by making the readiness hook enforce that requirement.
| # Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64) | ||
| # On riscv64, only riscv64 cross-compilers are available in the repositories | ||
| if [[ "${host_arch}" != "riscv64" ]]; then | ||
| if [[ "${wanted_arch}" == "amd64" || "${wanted_arch}" == "all" ]]; then | ||
| host_dependencies+=("gcc-x86-64-linux-gnu") # from crossbuild-essential-amd64 | ||
| fi | ||
|
|
||
| if [[ "${wanted_arch}" == "arm64" || "${wanted_arch}" == "all" ]]; then | ||
| # gcc-aarch64-linux-gnu: from crossbuild-essential-arm64 | ||
| # gcc-arm-linux-gnueabi: necessary for rockchip64 (and maybe other too) ATF compilation | ||
| host_dependencies+=("gcc-aarch64-linux-gnu" "gcc-arm-linux-gnueabi") | ||
| fi | ||
| if [[ "${wanted_arch}" == "arm64" || "${wanted_arch}" == "all" ]]; then | ||
| # gcc-aarch64-linux-gnu: from crossbuild-essential-arm64 | ||
| # gcc-arm-linux-gnueabi: necessary for rockchip64 (and maybe other too) ATF compilation | ||
| host_dependencies+=("gcc-aarch64-linux-gnu" "gcc-arm-linux-gnueabi") | ||
| fi | ||
|
|
||
| if [[ "${wanted_arch}" == "armhf" || "${wanted_arch}" == "all" ]]; then | ||
| host_dependencies+=("gcc-arm-linux-gnueabihf") # from crossbuild-essential-armhf crossbuild-essential-armel | ||
| if [[ "${wanted_arch}" == "armhf" || "${wanted_arch}" == "all" ]]; then | ||
| host_dependencies+=("gcc-arm-linux-gnueabihf") # from crossbuild-essential-armhf crossbuild-essential-armel | ||
| fi | ||
| fi |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the specific lines mentioned in the review
sed -n '230,265p' lib/functions/host/prepare-host.sh | cat -nRepository: armbian/build
Length of output: 1952
🏁 Script executed:
# Check if adaptative_prepare_host_dependencies is used in early and late prep
rg -A 3 -B 3 "early_prepare_host_dependencies|late_prepare_host_dependencies" lib/functions/host/prepare-host.sh | head -40Repository: armbian/build
Length of output: 1953
🏁 Script executed:
# Search for the function definition to see full context
rg "^adaptative_prepare_host_dependencies" -A 100 lib/functions/host/prepare-host.sh | head -150Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Check for x86-specific helpers or execution paths
rg "x86|amd64" lib/functions/ -l | head -10Repository: armbian/build
Length of output: 412
🏁 Script executed:
# Check if there's documentation or CI config about riscv64 as build host
rg "riscv64" lib/functions/host/prepare-host.sh -B 5 -A 5Repository: armbian/build
Length of output: 1558
🏁 Script executed:
# Look for actual error handling when dependencies are missing
rg "exit_with_error.*toolchain|exit_with_error.*gcc|exit_with_error.*dependency" lib/functions/host/Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Check if install_host_dependencies validates or fails on missing packages
rg "install_host_dependencies|install_host_side_packages" -A 10 lib/functions/host/prepare-host.sh | head -50Repository: armbian/build
Length of output: 1560
🏁 Script executed:
# Search for any x86-specific execution in the codebase that would fail on riscv64
rg "x86|x86_64|amd64" lib/functions/compilation/ -lRepository: armbian/build
Length of output: 148
🏁 Script executed:
# Check what install_host_side_packages does
rg "^install_host_side_packages" -A 30 lib/functions/host/Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Check if there's CI/test config that shows riscv64 as a build host
fd -t f "\.yml|\.yaml|Jenkinsfile|\.github" | xargs grep -l "riscv64" 2>/dev/null | head -5Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Check git history/comments for context on this riscv64 code
git log -p --all -S "riscv64, only riscv64 cross-compilers" -- lib/functions/host/prepare-host.sh 2>/dev/null | head -80Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Look for the full adaptative_prepare_host_dependencies function
rg "^function adaptative_prepare_host_dependencies" -A 200 lib/functions/host/prepare-host.sh | head -250Repository: armbian/build
Length of output: 9168
🏁 Script executed:
# Check if there's any validation that packages actually exist
rg "install_host_side_packages" -A 50 lib/functions/host/prepare-host.sh | grep -A 30 "^function install_host_side_packages"Repository: armbian/build
Length of output: 39
🏁 Script executed:
# Search for any PR/issue discussion about riscv64 support
git log --all --oneline --grep="riscv64" 2>/dev/null | head -20Repository: armbian/build
Length of output: 522
🏁 Script executed:
# Check recent commits to prepare-host.sh to understand context
git log --oneline lib/functions/host/prepare-host.sh 2>/dev/null | head -20Repository: armbian/build
Length of output: 120
🏁 Script executed:
# Look at the specific commit that fixed this
git show c617c393 --statRepository: armbian/build
Length of output: 50370
🏁 Script executed:
# Get more detail on that commit
git show c617c393Repository: armbian/build
Length of output: 50377
🏁 Script executed:
# Check if install_host_side_packages validates packages exist
rg "install_host_side_packages" lib/functions/ -A 30Repository: armbian/build
Length of output: 4818
🏁 Script executed:
# Verify if there's a way to distinguish between early (wanted_arch="all") and late prep scenarios
rg "ARCH|target_arch|HOSTARCH" lib/functions/general/main.sh | head -20Repository: armbian/build
Length of output: 126
🏁 Script executed:
# Check if there are any riscv64 boards to understand real-world usage
fd -e conf -e csc "riscv64" config/boards/ | head -10Repository: armbian/build
Length of output: 87
Clarify late prep semantics: fail fast for unsupported host/target combinations.
adaptative_prepare_host_dependencies() is called by both early prep (Dockerfile generation, wanted_arch="all") and late prep (real builds, wanted_arch=concrete). The current conditional silently skips toolchain packages if host_arch == "riscv64", allowing builds with unsupported host/target pairs to proceed with incomplete dependencies—violating Armbian's fail-fast principle.
For Dockerfile generation, the silent skip is benign. For late prep with a concrete target, it creates a silent failure scenario where a non-riscv64 target on a riscv64 host produces unclear compilation errors instead of a clear diagnostic.
Once wanted_arch is concrete and different from the host architecture, validate the combination and fail explicitly:
Reject unsupported host/target matrices during late prep
declare wanted_arch="${target_arch:-"all"}"
+ # Fail fast on unsupported host/target combinations once target is concrete
+ if [[ "${wanted_arch}" != "all" ]] && [[ "${host_arch}" == "riscv64" ]]; then
+ if [[ "${wanted_arch}" != "riscv64" ]]; then
+ exit_with_error "Target architecture '${wanted_arch}' requires toolchains unavailable on riscv64 hosts"
+ fi
+ fi
+
# Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64)
# On riscv64, only riscv64 cross-compilers are available in the repositories
if [[ "${host_arch}" != "riscv64" ]]; then🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/functions/host/prepare-host.sh` around lines 233 - 249, The code
currently silently skips adding cross-compiler packages when host_arch ==
"riscv64", which hides unsupported host/target combinations during late prep;
update adaptative_prepare_host_dependencies() to detect late-prep concrete
targets (when wanted_arch != "all") and if host_arch == "riscv64" and
wanted_arch is not "riscv64" immediately print a clear error referencing
host_arch and wanted_arch and exit non-zero (fail fast) instead of silently
continuing; keep the existing silent-skip behavior only for
Dockerfile-generation cases where wanted_arch == "all". Ensure you reference the
variables host_arch, wanted_arch and the host_dependencies array in your change.
Summary
Fix
./compile.sh generate-dockerfilefailures on native RISC-V hosts by properly detecting host architecture and skipping cross-compiler packages that don't exist in RISC-V package repositories.Bugs
Loop devices problem (has been reported upstream):
https://github.com/armbian/os/actions/runs/23560017249/job/68609709451
Referremce
armbian/docker-armbian-build#13
Problem
When running
generate-dockerfileon RISC-V hosts, the build fails with errors like:This occurs because:
Solution
dpkg --print-architectureand pass it to dependency resolution functionshost_archand skip cross-compilers unavailable on RISC-V (x86-64, ARM64, ARMHF)host_archand skip unavailable cross-compilers on RISC-VWhy This Matters
This fix enables Armbian to build properly on RISC-V hardware, which is important for:
RISE RISC-V Runners - Free GitHub Actions runner service providing bare-metal RISC-V CI (Scaleway EM-RV1)
runs-on: ubuntu-24.04-riscvNative RISC-V Development - Developers can now build Armbian images natively on RISC-V workstations
Multi-Arch CI/CD - Enables testing on real RISC-V hardware instead of QEMU emulation
Test plan
./compile.sh generate-dockerfileon native RISC-V hostFiles changed
lib/functions/host/docker.sh- Detect and pass host architecturelib/functions/host/prepare-host.sh- Skip unavailable cross-compilersextensions/c-plus-plus-compiler.sh- Architecture-aware dependency additionextensions/arm64-compat-vdso.sh- Architecture-aware dependency additionextensions/sunxi-tools.sh- Architecture-aware dependency additionSummary by CodeRabbit
New Features
Chores