Repository: microsoft/onnxruntime
File: tools/ci_build/build.py (Python)

Code before:
    # if args.use_jsep and args.use_webgpu:
    #     raise BuildError("JSEP (--use_jsep) and WebGPU (--use_webgpu) cannot be enabled at the same time.")

    if args.enable_wasm_jspi:
        if args.use_jsep:
            raise BuildError("JSEP (--use_jsep) and WASM JSPI (--enable_wasm_jspi) cannot be enabled at the same time.")
        if args.disable_wasm_exception_catching:
            raise BuildError("Cannot set WebAssembly exception catching in JSPI build.")

    if not args.use_webgpu:
        if args.use_external_dawn:
            raise BuildError("External Dawn (--use_external_dawn) must be enabled with WebGPU (--use_webgpu).")

        if is_windows():
            if args.enable_pix_capture:
                raise BuildError(
                    "Enable PIX Capture (--enable_pix_capture) must be enabled with WebGPU (--use_webgpu) on Windows"
                )

    if args.use_snpe:
        cmake_args += ["-Donnxruntime_USE_SNPE=ON"]

    if not args.no_kleidiai:
        cmake_args += ["-Donnxruntime_USE_KLEIDIAI=ON"]
        if args.use_qmx:
            cmake_args += ["-DENABLE_KLEIDIAI_QMX_COEXIST=ON"]

    if args.enable_arm_neon_nchwc:
        cmake_args += ["-Donnxruntime_USE_ARM_NEON_NCHWC=ON"]

    if not args.no_sve:
        cmake_args += ["-Donnxruntime_USE_SVE=ON"]

    if is_macOS() and (args.macos or args.ios or args.visionos or args.tvos):
        # Note: Xcode CMake generator doesn't have a good support for Mac Catalyst yet.
        if args.macos == "Catalyst" and args.cmake_generator == "Xcode":
            raise BuildError("Xcode CMake generator ('--cmake_generator Xcode') doesn't support Mac Catalyst build.")

        if (args.ios or args.visionos or args.tvos or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
            raise BuildError(
                "iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')."
            )

        needed_args = [
            args.apple_sysroot,
            args.apple_deploy_target,
        ]
        arg_names = [
            "--apple_sysroot          " + "<the location or name of the macOS platform SDK>",
            "--apple_deploy_target  " + "<the minimum version of the target platform>",
        ]

Review comment (refactor):
Can the ARM KleidiAI dependency truly co-exist with the QMX version of KleidiAI or can the QMX KleidiAI library only be used without the ARM KleidiAI library to avoid potential link errors due to duplicated symbols if any ?

Code after:
    # TODO: currently we allows building with both --use_jsep and --use_webgpu in this working branch.
    #       This situation is temporary. Eventually, those two flags will be mutually exclusive.
    #
    # if args.use_jsep and args.use_webgpu:
    #     raise BuildError("JSEP (--use_jsep) and WebGPU (--use_webgpu) cannot be enabled at the same time.")

    if args.enable_wasm_jspi:
        if args.use_jsep:
            raise BuildError("JSEP (--use_jsep) and WASM JSPI (--enable_wasm_jspi) cannot be enabled at the same time.")
        if args.disable_wasm_exception_catching:
            raise BuildError("Cannot set WebAssembly exception catching in JSPI build.")

    if not args.use_webgpu:
        if args.use_external_dawn:
            raise BuildError("External Dawn (--use_external_dawn) must be enabled with WebGPU (--use_webgpu).")

        if is_windows():
            if args.enable_pix_capture:
                raise BuildError(
                    "Enable PIX Capture (--enable_pix_capture) must be enabled with WebGPU (--use_webgpu) on Windows"
                )
    elif args.use_webgpu == "static_lib":
        cmake_args += ["-Donnxruntime_BUILD_WEBGPU_EP_STATIC_LIB=ON"]
    else:
        # Shared library build
        cmake_args += ["-Donnxruntime_BUILD_WEBGPU_EP_STATIC_LIB=OFF"]
        if args.build_wasm:
            raise BuildError("Only static library build of WebGPU EP is supported for WebAssembly build.")

    if args.use_snpe:
        cmake_args += ["-Donnxruntime_USE_SNPE=ON"]

    if not args.no_kleidiai:
        cmake_args += ["-Donnxruntime_USE_KLEIDIAI=ON"]
        if args.use_qmx:
            cmake_args += ["-Donnxruntime_USE_QMX_KLEIDIAI_COEXIST=ON"]

    if args.enable_arm_neon_nchwc:
        cmake_args += ["-Donnxruntime_USE_ARM_NEON_NCHWC=ON"]

    if not args.no_sve:
        cmake_args += ["-Donnxruntime_USE_SVE=ON"]

    if is_macOS() and (args.macos or args.ios or args.visionos or args.tvos):
        # Note: Xcode CMake generator doesn't have a good support for Mac Catalyst yet.
        if args.macos == "Catalyst" and args.cmake_generator == "Xcode":
            raise BuildError("Xcode CMake generator ('--cmake_generator Xcode') doesn't support Mac Catalyst build.")

        if (args.ios or args.visionos or args.tvos or args.macos == "MacOSX") and not args.cmake_generator == "Xcode":
            raise BuildError(
                "iOS/MacOS framework build requires use of the Xcode CMake generator ('--cmake_generator Xcode')."