Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/arm64-compat-vdso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ function extension_prepare_config__arm64_compat_vdso() {
}

function add_host_dependencies__arm64_compat_vdso() {
# Skip cross-compilers that don't exist on non-standard host architectures (e.g., riscv64)
if [[ "${host_arch}" == "riscv64" ]]; then
display_alert "Skipping arm64-compat-vdso extension" "gcc-arm-linux-gnueabi not available on ${host_arch}" "warn"
return 0
fi

if [[ "${KERNEL_COMPILER}" == "clang" ]]; then
EXTRA_BUILD_DEPS+=" clang "
else
Expand Down
9 changes: 8 additions & 1 deletion extensions/c-plus-plus-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@

function add_host_dependencies__add_arm64_c_plus_plus_compiler() {
display_alert "Extension: ${EXTENSION}: Adding arm64 c++ compiler to host dependencies" "g++" "debug"
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} g++-aarch64-linux-gnu g++" # @TODO: convert to array later

# 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
Comment on lines +7 to +13
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and examine its full content
fd "c-plus-plus-compiler.sh" -t f

Repository: 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 3

Repository: armbian/build

Length of output: 1336


🏁 Script executed:

# Check how other extensions handle architecture-specific dependencies
rg "host_arch.*riscv64" extensions/ -B 2 -A 5

Repository: 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.

}
6 changes: 6 additions & 0 deletions extensions/sunxi-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# Most sunxi stuff, even if 64-bit, requires 32-bit compiler, add it.
# This is only used for non-Docker, since the Docker image already has it, since it includes compilers for all architectures.
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
Comment on lines +6 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and examine the relevant section
find . -name "sunxi-tools.sh" -type f | head -5

Repository: armbian/build

Length of output: 84


🏁 Script executed:

# Look for the file in extensions directory
git ls-files | grep -i sunxi

Repository: 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 -20

Repository: 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 -30

Repository: 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 -50

Repository: armbian/build

Length of output: 2148


🏁 Script executed:

cat -n extensions/sunxi-tools.sh

Repository: armbian/build

Length of output: 2115


🏁 Script executed:

cat -n extensions/arm64-compat-vdso.sh

Repository: 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.sh

Repository: 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.sh

Repository: 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 -40

Repository: 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 2

Repository: 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.

Suggested change
# 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.


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
}
Expand Down
6 changes: 4 additions & 2 deletions lib/functions/host/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ function docker_cli_prepare_dockerfile() {
fi
declare -a -g host_dependencies=()

host_release="${DOCKER_WANTED_RELEASE}" early_prepare_host_dependencies # hooks: add_host_dependencies // host_dependencies_known
display_alert "Pre-game host dependencies for host_release '${DOCKER_WANTED_RELEASE}'" "${host_dependencies[*]}" "debug"
# Get the actual host architecture for proper cross-compiler selection
declare host_arch="$(dpkg --print-architecture)"
host_release="${DOCKER_WANTED_RELEASE}" host_arch="${host_arch}" early_prepare_host_dependencies # hooks: add_host_dependencies // host_dependencies_known
display_alert "Pre-game host dependencies for host_release '${DOCKER_WANTED_RELEASE}' host_arch '${host_arch}'" "${host_dependencies[*]}" "debug"

# This includes apt install equivalent to install_host_dependencies()
display_alert "Creating" "Dockerfile; FROM ${DOCKER_ARMBIAN_BASE_IMAGE}" "info"
Expand Down
27 changes: 16 additions & 11 deletions lib/functions/host/prepare-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,22 @@ function adaptative_prepare_host_dependencies() {
### ARCH
declare wanted_arch="${target_arch:-"all"}"

if [[ "${wanted_arch}" == "amd64" || "${wanted_arch}" == "all" ]]; then
host_dependencies+=("gcc-x86-64-linux-gnu") # from crossbuild-essential-amd64
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
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
Comment on lines +233 to 249
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 -n

Repository: 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 -40

Repository: 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 -150

Repository: armbian/build

Length of output: 39


🏁 Script executed:

# Check for x86-specific helpers or execution paths
rg "x86|amd64" lib/functions/ -l | head -10

Repository: 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 5

Repository: 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 -50

Repository: 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/ -l

Repository: 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 -5

Repository: 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 -80

Repository: 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 -250

Repository: 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 -20

Repository: 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 -20

Repository: armbian/build

Length of output: 120


🏁 Script executed:

# Look at the specific commit that fixed this
git show c617c393 --stat

Repository: armbian/build

Length of output: 50370


🏁 Script executed:

# Get more detail on that commit
git show c617c393

Repository: 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 30

Repository: 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 -20

Repository: 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 -10

Repository: 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.


if [[ "${wanted_arch}" == "riscv64" || "${wanted_arch}" == "all" ]]; then
Expand All @@ -254,7 +258,8 @@ function adaptative_prepare_host_dependencies() {
host_dependencies+=("debian-ports-archive-keyring")
fi

if [[ "${wanted_arch}" != "amd64" ]]; then
# libc6-amd64-cross is not available on riscv64 hosts
if [[ "${wanted_arch}" != "amd64" ]] && [[ "${host_arch}" != "riscv64" ]]; then
host_dependencies+=("libc6-amd64-cross") # Support for running x86 binaries (under qemu on other arches)
fi

Expand Down
Loading