Skip to content

Commit c8ce839

Browse files
authored
Download protoc for all Apple host builds, remove protoc build from iOS packaging pipeline. (#19209)
1 parent 6e17571 commit c8ce839

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

cmake/external/onnxruntime_external_deps.cmake

+39-35
Original file line numberDiff line numberDiff line change
@@ -108,48 +108,53 @@ FetchContent_Declare(
108108
)
109109

110110
# Download a protoc binary from Internet if needed
111-
if(CMAKE_CROSSCOMPILING AND NOT ONNX_CUSTOM_PROTOC_EXECUTABLE)
111+
if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE)
112112
# This part of code is only for users' convenience. The code couldn't handle all cases. Users always can manually
113113
# download protoc from Protobuf's Github release page and pass the local path to the ONNX_CUSTOM_PROTOC_EXECUTABLE
114114
# variable.
115-
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
116-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
117-
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
118-
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win64} URL_HASH SHA1=${DEP_SHA1_protoc_win64})
119-
FetchContent_Populate(protoc_binary)
120-
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86")
121-
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win32} URL_HASH SHA1=${DEP_SHA1_protoc_win32})
122-
FetchContent_Populate(protoc_binary)
123-
endif()
124-
if(protoc_binary_SOURCE_DIR)
125-
message("Use prebuilt protoc")
126-
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc.exe)
127-
set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
128-
endif()
129-
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
130-
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
131-
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x64})
132-
FetchContent_Populate(protoc_binary)
133-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$")
134-
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x86} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x86})
135-
FetchContent_Populate(protoc_binary)
136-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*")
137-
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_aarch64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_aarch64})
138-
FetchContent_Populate(protoc_binary)
139-
endif()
140-
if(protoc_binary_SOURCE_DIR)
141-
message("Use prebuilt protoc")
142-
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc)
143-
set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
144-
endif()
145-
elseif ((CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
115+
if (CMAKE_HOST_APPLE)
116+
# Using CMAKE_CROSSCOMPILING is not recommended for Apple target devices.
117+
# https://cmake.org/cmake/help/v3.26/variable/CMAKE_CROSSCOMPILING.html
118+
# To keep it simple, just download and use the universal protoc binary for all Apple host builds.
146119
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_mac_universal} URL_HASH SHA1=${DEP_SHA1_protoc_mac_universal})
147120
FetchContent_Populate(protoc_binary)
148121
if(protoc_binary_SOURCE_DIR)
149122
message("Use prebuilt protoc")
150123
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc)
151124
set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
152125
endif()
126+
elseif (CMAKE_CROSSCOMPILING)
127+
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
128+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
129+
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
130+
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win64} URL_HASH SHA1=${DEP_SHA1_protoc_win64})
131+
FetchContent_Populate(protoc_binary)
132+
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86")
133+
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win32} URL_HASH SHA1=${DEP_SHA1_protoc_win32})
134+
FetchContent_Populate(protoc_binary)
135+
endif()
136+
if(protoc_binary_SOURCE_DIR)
137+
message("Use prebuilt protoc")
138+
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc.exe)
139+
set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
140+
endif()
141+
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
142+
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
143+
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x64})
144+
FetchContent_Populate(protoc_binary)
145+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$")
146+
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x86} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x86})
147+
FetchContent_Populate(protoc_binary)
148+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*")
149+
FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_aarch64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_aarch64})
150+
FetchContent_Populate(protoc_binary)
151+
endif()
152+
if(protoc_binary_SOURCE_DIR)
153+
message("Use prebuilt protoc")
154+
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc)
155+
set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE})
156+
endif()
157+
endif()
153158
endif()
154159
endif()
155160

@@ -184,9 +189,9 @@ FetchContent_Declare(
184189
)
185190

186191
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE)
187-
#TODO: we'd better to turn the following option off. However, it will cause
192+
#TODO: we'd better to turn the following option off. However, it will cause
188193
# ".\build.bat --config Debug --parallel --skip_submodule_sync --update" fail with an error message:
189-
# install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
194+
# install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is
190195
# not in any export set.
191196
#set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and files" FORCE)
192197
set(protobuf_USE_EXTERNAL_GTEST ON CACHE BOOL "" FORCE)
@@ -562,4 +567,3 @@ endif()
562567

563568
FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR)
564569
FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR)
565-

tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ stages:
7878
pip install -r tools/ci_build/github/apple/ios_packaging.requirements.txt
7979
displayName: "Install Python requirements"
8080
81-
- script: |
82-
$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/inference/x64/python/cpu/scripts/install_protobuf.sh -p $(Build.BinariesDirectory)/protobuf_install -d $(Build.SourcesDirectory)/cmake/deps.txt
83-
displayName: "Build Host Protoc"
84-
8581
# create and test mobile pods
8682
- script: |
8783
python tools/ci_build/github/apple/build_and_assemble_apple_pods.py \
@@ -91,8 +87,7 @@ stages:
9187
--test \
9288
--variant ${{ parameters.packageVariant }} \
9389
--build-settings-file "${{ variables.buildSettingsFile }}" \
94-
${{ variables.optionalIncludeOpsByConfigOption }} \
95-
-b="--path_to_protoc_exe=$(Build.BinariesDirectory)/protobuf_install/bin/protoc"
90+
${{ variables.optionalIncludeOpsByConfigOption }}
9691
displayName: "Build macOS/iOS framework and assemble pod package files"
9792
9893
- script: |

0 commit comments

Comments
 (0)