From 1dfefda0692b4b53a104f92160c60649e9e84eba Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 11 Sep 2026 14:43:30 +0000 Subject: [PATCH] Bug 2071075 - Build the macOS onnxruntime toolchains on Linux workers. r=jcristau The aarch64 task was already a cross build on the Intel b-osx-1015 workers, so neither build executes what it compiles. build.py's --osx_arch only acts on a macOS host, so the Darwin cmake variables are passed directly, the way build-llvm-common.sh does for compiler-rt, with linux64-clang-toolchain replacing the Mach-O macosx64-clang and the mac cmake/ninja fetches. Deployment targets are set explicitly to Firefox's (10.15 x86_64, 11.0 arm64). -fuse-ld=lld goes in the compile flags because cmake's try_compile checks, including the one behind --enable_lto, don't inherit CMAKE_*_LINKER_FLAGS and would silently disable LTO. CMAKE_ASM_COMPILER_TARGET is needed or the .S files are assembled for the host. Differential Revision: https://phabricator.services.mozilla.com/D325157 --- taskcluster/kinds/toolchain/onnx.yml | 12 +----- taskcluster/scripts/misc/build-onnxruntime.sh | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/taskcluster/kinds/toolchain/onnx.yml b/taskcluster/kinds/toolchain/onnx.yml index bc2126d61544..ebce83133daa 100644 --- a/taskcluster/kinds/toolchain/onnx.yml +++ b/taskcluster/kinds/toolchain/onnx.yml @@ -83,7 +83,6 @@ onnxruntime-i686-windows-msvc: onnxruntime-x86_64-apple-darwin: description: "ONNX Runtime (macOS x64)" - worker-type: b-osx-1015 treeherder: symbol: TM(onnx) run: @@ -93,16 +92,12 @@ onnxruntime-x86_64-apple-darwin: toolchain-artifact: public/build/onnxruntime-x86_64-apple-darwin.tar.zst fetches: toolchain: - - macosx64-clang-toolchain + - linux64-clang-toolchain - macosx64-sdk-toolchain - fetch: - - macosx64-cmake - - macosx64-ninja onnxruntime-aarch64-apple-darwin: description: "ONNX Runtime (macOS aarch64)" - worker-type: b-osx-1015 treeherder: symbol: TMA64(onnx) run: @@ -112,11 +107,8 @@ onnxruntime-aarch64-apple-darwin: toolchain-artifact: public/build/onnxruntime-aarch64-apple-darwin.tar.zst fetches: toolchain: - - macosx64-clang-toolchain + - linux64-clang-toolchain - macosx64-sdk-toolchain - fetch: - - macosx64-cmake - - macosx64-ninja onnxruntime-arm-linux-androideabi: diff --git a/taskcluster/scripts/misc/build-onnxruntime.sh b/taskcluster/scripts/misc/build-onnxruntime.sh index 0e8b04889064..2fd477b5d35f 100755 --- a/taskcluster/scripts/misc/build-onnxruntime.sh +++ b/taskcluster/scripts/misc/build-onnxruntime.sh @@ -30,9 +30,38 @@ export CXX=clang++ # Extra setup per platform case ${target_platform} in Darwin) - # Use taskcluster clang instead of host compiler on OSX + case $target_arch in + arm64) + target_triple=aarch64-apple-darwin + macosx_deployment_target=11.0 + ;; + x86_64) + target_triple=x86_64-apple-darwin + macosx_deployment_target=10.15 + ;; + *) + echo "ERROR: unsupported Darwin architecture $target_arch" >&2 + exit 1 + ;; + esac osx_sysroot=`cd ${MOZ_FETCHES_DIR}/MacOSX*.sdk; pwd` - extra_args=(--cmake_extra_defines CMAKE_OSX_SYSROOT=${osx_sysroot} --osx_arch $target_arch) + # cmake probes the mac-only sw_vers; the version it sees doesn't matter. + mkdir -p "$PWD/fakebin" + printf '#!/bin/sh\necho 10.15\n' > "$PWD/fakebin/sw_vers" + chmod +x "$PWD/fakebin/sw_vers" + export PATH="$PATH:$PWD/fakebin" + extra_args=(--cmake_extra_defines + CMAKE_SYSTEM_NAME=Darwin + CMAKE_SYSTEM_PROCESSOR=$target_arch + CMAKE_OSX_ARCHITECTURES=$target_arch + CMAKE_OSX_SYSROOT=${osx_sysroot} + CMAKE_OSX_DEPLOYMENT_TARGET=$macosx_deployment_target + CMAKE_C_COMPILER_TARGET=$target_triple + CMAKE_CXX_COMPILER_TARGET=$target_triple + CMAKE_ASM_COMPILER_TARGET=$target_triple + CMAKE_AR=${MOZ_FETCHES_DIR}/clang/bin/llvm-ar + CMAKE_RANLIB=${MOZ_FETCHES_DIR}/clang/bin/llvm-ranlib) + TARGET_FLAGS="-fuse-ld=lld -Wno-unused-command-line-argument" prefix=lib extension=dylib HARDENING_FLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong" @@ -148,8 +177,8 @@ python3 tools/ci_build/build.py \ --cmake_extra_defines PYTHON_EXECUTABLE=$(which python3)\ --cmake_extra_defines ONNX_USE_LITE_PROTO=ON\ --disable_exceptions \ - --cmake_extra_defines CMAKE_C_FLAGS_INIT="$HARDENING_FLAGS"\ - --cmake_extra_defines CMAKE_CXX_FLAGS_INIT="$HARDENING_FLAGS $EXTRA_CXX_FLAGS"\ + --cmake_extra_defines CMAKE_C_FLAGS_INIT="$HARDENING_FLAGS $TARGET_FLAGS"\ + --cmake_extra_defines CMAKE_CXX_FLAGS_INIT="$HARDENING_FLAGS $TARGET_FLAGS $EXTRA_CXX_FLAGS"\ "${extra_args[@]}" ###