microsoft / microsoft/onnxruntime
[Build] WebGPU EP fails to build for iOS: Dawn's ObjCUtils.mm is incompatible with ORT's forced ObjC ARC
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 184
Description
### Describe the issue
Building the WebGPU EP for iOS fails to compile. Dawn's `src/dawn/utils/ObjCUtils.mm` uses manual `retain` / `release`, while ORT's own iOS toolchain file forces ARC:
- `cmake/onnxruntime_ios.toolchain.cmake:11` → `SET(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")`
- `dawn-src/src/dawn/utils/ObjCUtils.mm` → `[static_cast(layer) retain]` / `release`
Dawn guards this file behind a plain `elseif (APPLE)` in `src/dawn/utils/CMakeLists.txt`, which is true for iOS as well as macOS — but the code itself assumes MRC, which only holds for the macOS build.
`ObjCUtils.mm` belongs to the `dawn_system_utils` target, so it is not excluded by `DAWN_BUILD_SAMPLES=OFF` / `DAWN_BUILD_TESTS=OFF` (both of which ORT already sets).
**This is the only file in the build that fails.** Everything else — including the WebGPU EP itself and Dawn's Metal backend — compiles for iOS. So the gap looks narrow.
Errors:
```
_deps/dawn-src/src/dawn/utils/ObjCUtils.mm:36:10: error: cast of C pointer type 'void *' to
Objective-C pointer type 'CALayer *' requires a bridged cast
_deps/dawn-src/src/dawn/utils/ObjCUtils.mm:36:39: error: 'retain' is unavailable:
not available in automatic reference counting mode
_deps/dawn-src/src/dawn/utils/ObjCUtils.mm:36:39: error: ARC forbids explicit message send of 'retain'
_deps/dawn-src/src/dawn/utils/ObjCUtils.mm:42:39: error: ARC forbids explicit message send of 'release'
_deps/dawn-src/src/dawn/utils/ObjCUtils.mm:48:16: error: no matching conversion for functional-style
cast from 'CALayer * _Nonnull' to 'ScopedCALayer'
```
The compile line does contain `-fobjc-arc`, confirming where it comes from.
#### Proposed fix
Disabling ARC for just that one file, after Dawn is made available, in `cmake/external/onnxruntime_external_deps.cmake`:
```cmake
onnxruntime_fetchcontent_makeavailable(dawn)
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
set_source_files_properties(
"${dawn_SOURCE_DIR}/src/dawn/utils/ObjCUtils.mm"
DIRECTORY "${dawn_SOURCE_DIR}/src/dawn/utils"
PROPERTIES COMPILE_OPTIONS "-fno-objc-arc")
endif()
```
Note that `set_source_files_properties` is directory-scoped, so both the placement *after* `makeavailable` and the explicit `DIRECTORY` argument matter — setting it earlier or without `DIRECTORY` silently has no effect.
An upstream-side alternative would be for Dawn to use `CFRetain` / `CFRelease` plus a `__bridge` cast, which compiles under both ARC and MRC.
> Status: I am reporting the blocker itself, which is fully reproducible. The proposed cmake fix is still being verified by a full rebuild on my side; I will follow up in a comment with the result either way.
### Urgency
Not urgent for us — we are evaluating, not shipping on this yet. Reporting it because #24308 ("Support WebGPU build for android and ios") suggests iOS is supported, and this makes the iOS half not build at all with the released v1.29.0 sources.
### Target platform
iOS
### Build script
```bash
python3 tools/ci_build/build.py \
--build_dir ./build/ios \
--config Release --parallel --skip_tests --skip_submodule_sync \
--ios --apple_sysroot iphoneos --osx_arch arm64 --apple_deploy_target 16.0 \
--use_webgpu --cmake_generator Xcode \
--cmake_extra_defines onnxruntime_BUILD_UNIT_TESTS=OFF
```
(Two notes for anyone reproducing: `--cmake_generator Xcode` is mandatory — `build.py` rejects Ninja for iOS at `build.py:935`, and that rejection message mentions "framework build" even when `--build_apple_framework` is not passed, which is a little misleading. Also, if Homebrew's `onnx` / `protobuf` are installed, `brew unlink onnx protobuf abseil` is needed first, otherwise `/opt/homebrew/include` shadows ORT's vendored onnx and protobuf.)
### Error / output
See above.
### Visual Studio Version
N/A
### GCC / Compiler Version
Apple clang 17.0.0 (clang-1700.6.3.2), Xcode on macOS 26.1, Apple M3 Pro. ONNX Runtime v1.29.0, Dawn v20260714.215939 (as pinned in `cmake/deps.txt`).
Contributor guide
Research direction
Start in cmake/external/onnxruntime_external_deps.cmake and inspect how Dawn is made available, then review dawn-src/src/dawn/utils/ObjCUtils.mm and its target directory. Reproduce with the provided iOS build command and verify the proposed file-specific ARC handling. Done means the WebGPU EP completes an iOS build without the ObjCUtils.mm errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, ios
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100