Skip to content

waf: detect 64-bit Linux targets for DroneCAN#33752

Open
dlanov wants to merge 1 commit into
ArduPilot:masterfrom
dlanov:waf-linux-canard-64bit
Open

waf: detect 64-bit Linux targets for DroneCAN#33752
dlanov wants to merge 1 commit into
ArduPilot:masterfrom
dlanov:waf-linux-canard-64bit

Conversation

@dlanov

@dlanov dlanov commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Detect the configured Linux target's pointer width and define CANARD_64_BIT explicitly for 64-bit DroneCAN builds.

Fixes #33721.

Classification & Testing

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change
  • Automated test(s) verify changes
  • Tested manually, description below
  • Tested on hardware
  • Logs attached
  • Logs available on request

Description

Libcanard determines whether it is compiling for a 64-bit target using glibc's __WORDSIZE macro. Musl does not provide that macro through the headers included by libcanard, so an AArch64 musl build incorrectly selects the 32-bit libcanard data layout and fails its compile-time structure-layout assertion.

Add a compile-only Waf check that uses the configured target C compiler to determine whether pointers are eight bytes. When the check succeeds, CANARD_64_BIT=1 is added to the common build definitions, including the generated DroneCAN C sources.

The check is limited to Linux boards with CAN enabled and does not rely on the build host architecture or an architecture-name list.

Testing

AArch64 Alpine/musl baseline

Before the change, the static Linux Rover build failed in generated DroneCAN C sources with:

modules/DroneCAN/libcanard/canard.h:371:
static assertion failed: "Invalid memory layout"

AArch64 Alpine/musl after the change

  • Checking for 64-bit pointers: yes
  • Full Linux Rover build completed successfully
  • Generated DroneCAN C compile commands contained CANARD_64_BIT=1
  • The result was an ELF 64-bit ARM AArch64 statically linked executable
  • The libcanard memory-layout failure was no longer present

ARMHF/musl regression build

Using the existing navigator ARMHF/musl CI-style build:

  • Checking for 64-bit pointers: no
  • The Sub build completed successfully
  • CANARD_64_BIT=1 was absent from compile_commands.json
  • The resulting executable was a 32-bit ARM ELF

Additional checks:

  • git diff --check
  • python3 -m py_compile Tools/ardupilotwaf/boards.py
  • Tools/scripts/check_branch_conventions.py
  • Confirmed only Tools/ardupilotwaf/boards.py changed

AI Assistance

This contribution was AI-assisted. Claude and ChatGPT were used to analyze the Waf and libcanard behavior, develop the validation plan, and review the proposed change and test results. I reproduced the failure, reviewed the code, ran the listed builds and checks, and take responsibility for the submitted change.

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>

@peterbarker peterbarker left a comment

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.

LGTM

@khancyr khancyr left a comment

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.

I would say OK

But we need to look at the combination of this that auto set 64bit flag and the --force-32bit . We may have some conflict there.

@khancyr khancyr left a comment

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.

Ok, I check the flag combination and it works for now as the order is correct. It will break if we change the flag order
adding
if not cfg.options.force_32bit: as guard would make it safer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AP_HAL_Linux: aarch64 Alpine Linux static build using musl fails

3 participants