Skip to content

Commit

Permalink
build onnxruntime as x
Browse files Browse the repository at this point in the history
  • Loading branch information
moyo1997 committed Nov 29, 2023
1 parent dd355e3 commit 423cfb4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,4 @@ Package.pins
Package.resolved
.build/
.swiftpm/
repros/
5 changes: 5 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1774,3 +1774,8 @@ if(TARGET onnxruntime)
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif()

if(DEFINED BUILD_AS_ARM64X)
set(ARM64X_TARGETS onnxruntime)
include("${CMAKE_SOURCE_DIR}/arm64x.cmake")
endif()
33 changes: 33 additions & 0 deletions cmake/arm64x.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(arm64ReproDir "${CMAKE_SOURCE_DIR}/repros")

if("${BUILD_AS_ARM64X}" STREQUAL "ARM64")
foreach (n ${ARM64X_TARGETS})
add_custom_target(mkdirs_${n} ALL COMMAND cmd /c (if exist \"${arm64ReproDir}/${n}_temp/\" rmdir /s /q \"${arm64ReproDir}/${n}_temp\") && mkdir \"${arm64ReproDir}/${n}_temp\" )
add_dependencies(${n} mkdirs_${n})
target_link_options(${n} PRIVATE "/LINKREPRO:${arm64ReproDir}/${n}_temp")
add_custom_target(${n}_checkRepro ALL COMMAND cmd /c if exist \"${n}_temp/*.obj\" if exist \"${n}\" rmdir /s /q \"${n}\" 2>nul && if not exist \"${n}\" ren \"${n}_temp\" \"${n}\" DEPENDS ${n}
WORKING_DIRECTORY ${arm64ReproDir})
endforeach()


elseif("${BUILD_AS_ARM64X}" STREQUAL "ARM64EC")
foreach (n ${ARM64X_TARGETS})
set(ARM64_LIBS)
set(ARM64_OBJS)
set(ARM64_DEF)

file(GLOB ARM64_OBJS "${arm64ReproDir}/${n}/*.obj")
file(GLOB ARM64_DEF "${arm64ReproDir}/${n}/*.def")
file(GLOB ARM64_LIBS "${arm64ReproDir}/${n}/*.LIB")

if(NOT "${ARM64_DEF}" STREQUAL "")
set(ARM64_DEF "/defArm64Native:${ARM64_DEF}")
endif()
target_sources(${n} PRIVATE ${ARM64_OBJS})
target_link_options(${n} PRIVATE /machine:arm64x "${ARM64_DEF}")

if(NOT "${ARM64_LIBS}" STREQUAL "")
target_link_libraries(${n} PUBLIC ${ARM64_LIBS})
endif()
endforeach()
endif()
12 changes: 11 additions & 1 deletion tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def convert_arg_line_to_args(self, arg_line):
help="[cross-compiling] Create ARM64EC makefiles. Requires --update and no existing cache "
"CMake setup. Delete CMakeCache.txt if needed",
)
parser.add_argument(
"--buildasx",
action="store_true",
help="[cross-compiling] Create ARM64X Binary.",
)
parser.add_argument("--msvc_toolset", help="MSVC toolset to use. e.g. 14.11")
parser.add_argument("--windows_sdk_version", help="Windows SDK version to use. e.g. 10.0.19041.0")
parser.add_argument("--android", action="store_true", help="Build for Android")
Expand Down Expand Up @@ -2496,8 +2501,12 @@ def main():
cmake_extra_args = ["-A", "ARM"]
elif args.arm64:
cmake_extra_args = ["-A", "ARM64"]
if args.buildasx:
cmake_extra_args += ["-D", "BUILD_AS_ARM64X=ARM64"]
elif args.arm64ec:
cmake_extra_args = ["-A", "ARM64EC"]
cmake_extra_args = ["-A", "ARM64EC", "-D", "BUILD_AS_ARM64X=ARM64EC"]
if args.buildasx:
cmake_extra_args += ["-D", "BUILD_AS_ARM64X=ARM64EC"]
cmake_extra_args += ["-G", args.cmake_generator]
# Cannot test on host build machine for cross-compiled
# builds (Override any user-defined behaviour for test if any)
Expand Down Expand Up @@ -2532,6 +2541,7 @@ def main():
cmake_extra_args = ["-A", target_arch, "-T", toolset, "-G", args.cmake_generator]
if args.enable_wcos:
cmake_extra_defines.append("CMAKE_USER_MAKE_RULES_OVERRIDE=wcos_rules_override.cmake")

elif args.cmake_generator is not None:
cmake_extra_args += ["-G", args.cmake_generator]

Expand Down

0 comments on commit 423cfb4

Please sign in to comment.