| # Copyright 2025 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import os |
| import requests |
| import shutil |
| |
| # This script updates the current directory with parts of the WindowsAPPSDK headers |
| # needed in Chromium. |
| |
| windows_app_sdk_headers = [ |
| "inc/abi/runtime/WindowsAppSDK-VersionInfo.h", |
| "inc/abi/winml/Microsoft.Windows.AI.MachineLearning.h", |
| "inc/abi/winml/winml/onnxruntime_c_api.h", |
| "inc/abi/winml/winml/onnxruntime_ep_c_api.h", |
| "inc/abi/winml/winml/onnxruntime_ep_device_ep_metadata_keys.h", |
| "inc/abi/winml/winml/onnxruntime_session_options_config_keys.h", |
| ] |
| |
| # The target revision of WindowsAppSDK |
| revision = "c4f951addb693bae1084085f126fa8c392e2787d" |
| # The target version of WindowsAppSDK |
| version = "1.8.1" |
| |
| base_url = "https://raw.githubusercontent.com/microsoft/WindowsAppSDK" |
| # Source URL for the current revision of WindowsAppSDK headers |
| src_url = "/".join([base_url, revision]) |
| |
| abs_path = os.path.dirname(os.path.abspath(__file__)) |
| |
| # Delete the src directory |
| abs_src_dir = os.path.join(abs_path, "src") |
| if os.path.exists(abs_src_dir): |
| shutil.rmtree(abs_src_dir) |
| |
| # Update the WindowsAppSDK headers |
| for header in windows_app_sdk_headers: |
| header_path = os.path.join(abs_src_dir, header) |
| os.makedirs(os.path.dirname(header_path), exist_ok=True) |
| with open(header_path, "wb") as f: |
| file_url = "/".join([src_url, header]) |
| response = requests.get(file_url) |
| if response.status_code != 200: |
| raise Exception("Failed to download", file_url) |
| f.write(response.content) |
| |
| # Update the license file |
| with open(os.path.join(abs_path, "src", "LICENSE"), "wb") as f: |
| response = requests.get("/".join([src_url, "LICENSE"])) |
| if response.status_code != 200: |
| raise Exception("Failed to download", file_url) |
| f.write(response.content) |
| |
| # Generate the BUILD.gn file |
| |
| def format_headers(headers): |
| formatted_string = '[\n' |
| for i in range(len(headers)): |
| header = "/".join(["src", headers[i]]) |
| formatted_string += f' "{header}",\n' |
| formatted_string += ' ]' |
| return formatted_string |
| |
| build_file = '''# Copyright 2025 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This file is generated by Update.py and should not be edited. |
| |
| # windows_app_sdk_headers is used by WebNN on Windows. |
| |
| source_set("windows_app_sdk_headers") {{ |
| sources = {sources} |
| |
| visibility = [ "//services/webnn/*" ] |
| }} |
| '''.format(sources=format_headers(windows_app_sdk_headers)) |
| |
| with open(os.path.join(abs_path, "BUILD.gn"), "w", newline="\n") as f: |
| f.write(build_file) |
| |
| # Generate the README.chromium file |
| |
| readme_file = '''Name: Headers for WindowsAppsSDK |
| Short Name: windows_app_sdk_headers |
| URL: https://github.com/microsoft/WindowsAppSDK |
| Version: {version} |
| Revision: {revision} |
| Update Mechanism: Manual |
| License: MIT |
| License File: src/LICENSE |
| Shipped: Yes |
| Security Critical: Yes |
| |
| Description: |
| This folder is a snapshot of selected WindowsAppSDK headers required by |
| WebNN for inference on Windows using the WindowsML API. |
| |
| To avoid pulling in unnecessary files this snapshot only contains the |
| headers used by WebNN. |
| |
| Local Modifications: None |
| |
| # This file is generated by Update.py and should not be edited. |
| '''.format(version=version, revision=revision) |
| |
| with open(os.path.join(abs_path, "README.chromium"), "w", newline="\n") as f: |
| f.write(readme_file) |