From 8b0f1d8eccfeafa086b81e9d9ca8cca9442878d6 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 13 Feb 2025 15:33:08 -0800 Subject: [PATCH] update --- tools/ci_build/build.py | 17 ++++++++++++++++- tools/python/util/vcpkg_helpers.py | 8 ++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index d86597e409ce0..60b777acbd55c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1242,6 +1242,7 @@ def generate_build_tree( "-DCMAKE_TOOLCHAIN_FILE=" + os.path.join(source_dir, "cmake", "riscv64.toolchain.cmake"), ] emscripten_cmake_toolchain_file = None + emsdk_dir = None if args.build_wasm: emsdk_dir = os.path.join(cmake_dir, "external", "emsdk") emscripten_cmake_toolchain_file = os.path.join( @@ -1274,8 +1275,12 @@ def generate_build_tree( vcpkg_toolchain_path = Path(vcpkg_installation_root) / "scripts" / "buildsystems" / "vcpkg.cmake" if args.build_wasm: + # While vcpkg has a toolchain cmake file for most build platforms(win/linux/mac/android/...), it doesn't have one to wasm. Therefore we need to do some tricks here. + # Here we will generate two toolchain cmake files. One for building the ports, one for building onnxruntime itself. + # The following one is for building onnxruntime itself new_toolchain_file = Path(build_dir) / "toolchain.cmake" old_toolchain_lines = [] + # First, we read the official toolchain cmake file provided by emscripten into memory emscripten_root_path = os.path.join(emsdk_dir, "upstream", "emscripten") with open(emscripten_cmake_toolchain_file, encoding="utf-8") as f: old_toolchain_lines = f.readlines() @@ -1283,16 +1288,21 @@ def generate_build_tree( # This file won't be used by vcpkg-tools when invoking 0.vcpkg_dep_info.cmake or vcpkg/scripts/ports.cmake with open(new_toolchain_file, "w", encoding="utf-8") as f: f.write(f'set(EMSCRIPTEN_ROOT_PATH "{emscripten_root_path_cmake_path}")\n') + + # Copy emscripten's toolchain cmake file to ours. for line in old_toolchain_lines: f.write(line) vcpkg_toolchain_path_cmake_path = str(vcpkg_toolchain_path).replace("\\", "/") + # Add an extra line at the bottom of the file to include vcpkg's toolchain file. f.write(f"include({vcpkg_toolchain_path_cmake_path})") + # Then tell cmake to use this toolchain file. vcpkg_toolchain_path = new_toolchain_file.absolute() - # This file is for vcpkg-tools + # This file is for building the vcpkg ports. empty_toolchain_file = Path(build_dir) / "emsdk_vcpkg_toolchain.cmake" with open(empty_toolchain_file, "w", encoding="utf-8") as f: f.write(f'set(EMSCRIPTEN_ROOT_PATH "{emscripten_root_path_cmake_path}")\n') + # The variable VCPKG_MANIFEST_INSTALL is OFF while building the ports f.write("if(NOT VCPKG_MANIFEST_INSTALL)\n") flags_to_pass = [ "CXX_FLAGS", @@ -1305,11 +1315,14 @@ def generate_build_tree( "LINKER_FLAGS_DEBUG", "LINKER_FLAGS_RELEASE", ] + # Overriding the cmake flags for flag in flags_to_pass: f.write("SET(CMAKE_" + flag + ' "${VCPKG_' + flag + '}")\n') + # Copy emscripten's toolchain cmake file to ours. for line in old_toolchain_lines: f.write(line) f.write("endif()") + # We must define the VCPKG_CHAINLOAD_TOOLCHAIN_FILE cmake variable, otherwise vcpkg won't let us go. add_default_definition( cmake_extra_defines, "VCPKG_CHAINLOAD_TOOLCHAIN_FILE", str(empty_toolchain_file.absolute()) ) @@ -1329,7 +1342,9 @@ def generate_build_tree( # Choose the cmake triplet triplet = None if args.build_wasm: + # The support for wasm64 is still in development. if args.enable_wasm_memory64: + # The triplet wasm64-emscripten doesn't exist in vcpkg's official repo. triplet = "wasm64-emscripten" else: triplet = "wasm32-emscripten" diff --git a/tools/python/util/vcpkg_helpers.py b/tools/python/util/vcpkg_helpers.py index e03838acc6849..ad28377f83200 100644 --- a/tools/python/util/vcpkg_helpers.py +++ b/tools/python/util/vcpkg_helpers.py @@ -512,22 +512,18 @@ def generate_posix_triplets(build_dir: str) -> None: Args: build_dir (str): The directory to save the generated triplet files. """ - crt_linkages = ["static", "dynamic"] for os_name in ["linux", "osx"]: if os_name == "linux": target_abis = ["x86", "x64", "arm", "arm64", "s390x", "ppc64le", "riscv64", "loongarch64", "mips64"] - crt_linkages = ["dynamic"] else: target_abis = ["x64", "arm64", "universal2"] - crt_linkages = ["dynamic"] for enable_rtti in [True, False]: for enable_exception in [True, False]: for enable_binskim in [True, False]: for enable_asan in [True, False]: if enable_asan and enable_binskim: continue - for crt_linkage in crt_linkages: - for target_abi in target_abis: + for target_abi in target_abis: generate_triplet_for_posix_platform( build_dir, os_name, @@ -535,6 +531,6 @@ def generate_posix_triplets(build_dir: str) -> None: enable_exception, enable_binskim, enable_asan, - crt_linkage, + "dynamic", target_abi, )