microsoft / microsoft/onnxruntime

[Build] Issue when cross-compiling for ARM64

Open
#25,201 4 comments 0 reactions 0 assignees View on GitHub
build contributions welcome
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

We are using linux-x86 to build for linux-arm64. There is an issue in how cpuinfo is included and built.

See https://github.com/microsoft/onnxruntime/blob/739e7375448995d21224e58722eca98e625ac8ee/cmake/onnxruntime_common.cmake#L196

The onnxruntime_target_platform is set up to be aarch64, but this is not checked before running `clang -dumpmachine` ...which of course doesn't help when running on an x86 machine but targeting an aarch64 machine. ARM64 or ARM need to be defined for the proper inclusion and build of cpuinfo. (See lines 213-221)

One easy way to fix this is to add

```
if (onnxruntime_target_platform STREQUAL "aarch64")
set(ARM64 TRUE)
```
before testing the dumpmachine_output.

As an aside, the parameter --arm64 is only checked when building on Windows.

### Urgency

_No response_

### Target platform

linux-aarch64

### Build script

```
python3 tools/ci_build/build.py \
--cmake_extra_defines CMAKE_TOOLCHAIN_FILE="

Contributor guide

Open the contributing guide

Research direction

Start in cmake/onnxruntime_common.cmake around lines 196 and 213-221, then review the tools/ci_build/build.py command and its Linux-aarch64 toolchain settings. Reproduce the cross-compilation link step and verify that cpuinfo_initialize and related symbols are found when targeting linux-aarch64.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, compilers
Issue type
Bug
Difficulty
2/5
Estimated time
Half a day
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.