microsoft / microsoft/onnxruntime
[Build] Building onnxruntime with darwin cross-compilation toolchain
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
### Describe the issue
https://github.com/microsoft/onnxruntime/blob/a457c1df80f391ea6de0ab1d454297716976dbf3/cmake/adjust_global_compile_flags.cmake#L91
This line lead to undefined linker flag option when using darwin cross-compilation toolchain.
Rather use `CMAKE_SYSTEM_NAME`, since it's generally set in toolchain cmake files in practice.
https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
### Urgency
_No response_
### Target platform
darwin
### Build script
./build.sh --config=Release --build_shared_lib --minimal_build --disable_ml_ops --disable_exceptions --disable_rtti --skip_tests --compile_no_warning_as_error --allow_running_as_root --skip_submodule_sync --parallel 20 --cmake_extra_defines CMAKE_TOOLCHAIN_FILE=/toolchain.cmake --cmake_extra_defines TARGET_ARCHITECTURES=x86_64 --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=x86_64
### Error / output
[ 25%] Building CXX object CMakeFiles/onnxruntime_mlas.dir/onnx-src/clean-build-fat/onnxruntime/core/mlas/lib/qpostprocessor.cpp.o
ld: unknown option: --gc-sections
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [_deps/flatbuffers-build/CMakeFiles/flatc.dir/build.make:529: _deps/flatbuffers-build/flatc] Error 1
make[1]: *** [CMakeFiles/Makefile2:5023: _deps/flatbuffers-build/CMakeFiles/flatc.dir/all] Error 2
### Visual Studio Version
_No response_
### GCC / Compiler Version
Ubuntu clang version 14.0.6
Contributor guide
Research direction
Start at cmake/adjust_global_compile_flags.cmake around the linked line and review how the darwin toolchain sets CMAKE_SYSTEM_NAME. Reproduce the provided build.sh command with the toolchain file and confirm the resulting link flags no longer include the unsupported --gc-sections option; the build should proceed past the flatc link step.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100