Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 106 additions & 65 deletions .github/actions/locate-vcvarsall-and-setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
description: 'Target architecture (x64 or x86)'
required: true
default: 'x64'
cache_key:
description: 'a workflow & job qualified unique key to distinguish a cache. used as a suffix for subcaches.'
required: true
outputs:
vcvarsall_path:
description: "Path to vcvarsall.bat"
Expand All @@ -13,68 +16,106 @@ runs:
using: "composite"
steps:

- name: Setup VCPKG
uses: microsoft/onnxruntime-github-actions/setup-build-tools@v0.0.9
with:
vcpkg-version: '2025.08.27'
vcpkg-hash: '9a4b32849792e13bee1d24726f073b3881acae4165206ddf1a6378e44a4ddd05b3ee93f55ff46d8e8873b3cbcd06606212989e248f0bd615a5bf365070074079'
cmake-version: '3.31.6'
cmake-hash: '0f1584e8666cf4a65ec514bd02afe281caabf1d45d2c963f3151c41484f457386aa03273ab25776a670be02725354ce0b46f3a5121857416da37366342a833a0'
add-cmake-to-path: 'true'
disable-terrapin: 'false'

- name: Verify vcpkg setup
shell: pwsh # Use powershell to easily access env var
run: |
Write-Host "VCPKG_INSTALLATION_ROOT is set to: $env:VCPKG_INSTALLATION_ROOT"
& "$env:VCPKG_INSTALLATION_ROOT/vcpkg" version

- name: Find vcvarsall.bat
id: find-vcvarsall
shell: python # Use Python shell
run: |
import os
import subprocess

vswhere_path = os.path.join(os.environ["ProgramFiles(x86)"], "Microsoft Visual Studio", "Installer", "vswhere.exe")

try:
process = subprocess.run([vswhere_path, "-latest", "-property", "installationPath"], capture_output=True, text=True, check=True)
vs_install_path = process.stdout.strip()
vcvarsall_path = os.path.join(vs_install_path, "VC", "Auxiliary", "Build", "vcvarsall.bat")

if os.path.exists(vcvarsall_path):
print(f"vcvarsall found at: {vcvarsall_path}")
# Use GITHUB_OUTPUT environment variable
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"vcvarsall_path={vcvarsall_path}\n")
else:
print(f"vcvarsall.bat not found at expected path: {vcvarsall_path}")
# Use 'exit(1)' for Python to properly signal failure to GitHub Actions
exit(1)


except subprocess.CalledProcessError as e:
print(f"Error running vswhere.exe: {e}")
print(f"vswhere output: {e.stdout}")
print(f"vswhere stderr: {e.stderr}")
exit(1) # Exit with a non-zero code on error
except FileNotFoundError:
print(f"vswhere.exe not found at: {vswhere_path}")
exit(1)


- name: Setup Environment
shell: cmd
run: |
REM Get initial environment variables
set > initial_env.txt

REM Call vcvarsall.bat using the output from the previous step
call "${{ steps.find-vcvarsall.outputs.vcvarsall_path }}" ${{ inputs.architecture }}

REM Get environment variables after calling vcvarsall.bat
set > final_env.txt

REM Call the Python script to update the GitHub Actions environment
python ${{ github.action_path }}\update_environment.py
- name: Setup VCPKG
uses: microsoft/onnxruntime-github-actions/build/setup-build-tools@dev/sanaahamel/download-ninja
with:
ccache-version: 4.13.1
ccache-hash: fe678d8e82f35e1d5f13c7bcd86447c08b67b0831dec8c772ef1257090a0f51678e296bb6d3ea38433f472d0fded52da96445cbc6fa8f945ecf94351d2c149d8
cmake-version: '3.31.6'
cmake-hash: '0f1584e8666cf4a65ec514bd02afe281caabf1d45d2c963f3151c41484f457386aa03273ab25776a670be02725354ce0b46f3a5121857416da37366342a833a0'
ninja-version: 1.13.0
ninja-hash: cffea62711b5a89ec494b48ae5e8df32f24cab0e642363ac20cc250c7d7f75ad43258f8d3721c68b23413e401d42630945c534ff95355cfe664e5da1d36569bf
vcpkg-version: '2025.08.27'
vcpkg-hash: '9a4b32849792e13bee1d24726f073b3881acae4165206ddf1a6378e44a4ddd05b3ee93f55ff46d8e8873b3cbcd06606212989e248f0bd615a5bf365070074079'
add-cmake-to-path: 'true'
disable-terrapin: 'true' # ccache isn't on terrapin

- name: Verify vcpkg setup
shell: pwsh # Use powershell to easily access env var
run: |
Write-Host "VCPKG_INSTALLATION_ROOT is set to: $env:VCPKG_INSTALLATION_ROOT"
& "$env:VCPKG_INSTALLATION_ROOT/vcpkg" version

- name: Find vcvarsall.bat
id: find-vcvarsall
shell: python # Use Python shell
run: |
import os
import subprocess

vswhere_path = os.path.join(os.environ["ProgramFiles(x86)"], "Microsoft Visual Studio", "Installer", "vswhere.exe")

try:
process = subprocess.run([vswhere_path, "-latest", "-property", "installationPath"], capture_output=True, text=True, check=True)
vs_install_path = process.stdout.strip()
vcvarsall_path = os.path.join(vs_install_path, "VC", "Auxiliary", "Build", "vcvarsall.bat")

if os.path.exists(vcvarsall_path):
print(f"vcvarsall found at: {vcvarsall_path}")
# Use GITHUB_OUTPUT environment variable
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"vcvarsall_path={vcvarsall_path}\n")
else:
print(f"vcvarsall.bat not found at expected path: {vcvarsall_path}")
# Use 'exit(1)' for Python to properly signal failure to GitHub Actions
exit(1)


except subprocess.CalledProcessError as e:
print(f"Error running vswhere.exe: {e}")
print(f"vswhere output: {e.stdout}")
print(f"vswhere stderr: {e.stderr}")
exit(1) # Exit with a non-zero code on error
except FileNotFoundError:
print(f"vswhere.exe not found at: {vswhere_path}")
exit(1)

- name: Setup Environment
shell: cmd
run: |
REM Get initial environment variables
set > initial_env.txt

REM Call vcvarsall.bat using the output from the previous step
call "${{ steps.find-vcvarsall.outputs.vcvarsall_path }}" ${{ inputs.architecture }}

REM Get environment variables after calling vcvarsall.bat
set > final_env.txt

REM Call the Python script to update the GitHub Actions environment
python ${{ github.action_path }}\update_environment.py

- name: Set cache dir env vars
env:
github_runner_temp: ${{ runner.temp }}
shell: pwsh
run: |
echo "CCACHE_DIR=${env:github_runner_temp}/.ccache" >> "${env:GITHUB_ENV}"
echo "VCPKG_DEFAULT_BINARY_CACHE=${env:github_runner_temp}/.vcpkg-cache" >> "${env:GITHUB_ENV}"

# vcpkg will error/exit if `VCPKG_DEFAULT_BINARY_CACHE` does not exist as a directory.
# c.f. ccache happily creates the cache dir if it does not exist.
# Don't create ccache's dir so that `action/cache` skips if ccache isn't populated.
New-Item -ItemType Directory -Path "${env:github_runner_temp}/.vcpkg-cache" -Force

# HACK: `actions/cache` will somehow pick up `tar` from the git installation. This bin dir is not on the PATH.
# `tar` tries to find `gzip` (which is right next to it), and fails b/c the git bin dir isn't on the PATH.
# This breaks attempts to download/upload caches.
# Add git's bin dir to the PATH so that `actions/cache`'s invoke of `tar` can find `gzip`.
echo "PATH=${env:PATH};C:\\Program Files\\Git\\usr\\bin" >> "${env:GITHUB_ENV}"

# n.b. Caller is responsible for building w/ ccache enabled via `--use_cache`
# We could set the env var `ORT_BUILD_WITH_CACHE` to indirectly enable it, but this hack seems deprecated.
# Ideally ccache should be auto-enabled by the build system if ccache/sccache is detected on the PATH.
- name: Setup CCache
uses: actions/cache@v5
with:
# Fully qualify by `cache_key`. `actions/cache` does not isolate by workflow, unlike ADO cache actions.
key: ccache | ${{ inputs.cache_key }}
path: ${{ runner.temp }}/.ccache # ensure this is coordinated/matches w/ env-vars step above

- name: Setup VCPKG Cache
uses: actions/cache@v5
with:
key: vcpkg-cache | ${{ inputs.cache_key }}
path: ${{ runner.temp }}/.vcpkg-cache
67 changes: 42 additions & 25 deletions .github/workflows/linux-wasm-ci-build-and-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ jobs:
env:
buildArch: x64
common_build_args: >-
--parallel
--use_cache
${{ inputs.use_vcpkg == true && '--use_vcpkg --use_vcpkg_ms_internal_asset_cache' || '' }}
--config ${{ inputs.build_config }}
--skip_submodule_sync
--build_wasm
--config '${{ inputs.build_config }}'
--enable_wasm_simd
--parallel
--skip_submodule_sync
--use_cache
${{ inputs.enable_wasm_threads == true && '--enable_wasm_threads' || '' }}
${{ inputs.use_vcpkg == true && '--use_vcpkg --use_vcpkg_ms_internal_asset_cache' || '' }}
${{ inputs.extra_build_args }}

reduced_size_build_args: >-
--disable_ml_ops
--disable_generation_ops
--disable_ml_ops
--disable_types string float4 float8 optional sparsetensor
--include_ops_by_config onnxruntime/wasm/reduced_types.config
--enable_reduced_operator_type_support
--include_ops_by_config onnxruntime/wasm/reduced_types.config

steps:
- name: Checkout code
Expand Down Expand Up @@ -106,20 +107,24 @@ jobs:
disable-terrapin: 'true'

- name: Build (simd + threads)
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing \
--build_dir "${GITHUB_WORKSPACE}/build/wasm_inferencing" \
${{ inputs.build_config == 'Release' && '--enable_wasm_api_exception_catching' || '' }} \
--skip_tests
working-directory: ${{ github.workspace }}

- name: Build (simd + threads + JSEP)
if: ${{ inputs.build_jsep == true }}
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing_jsep \
--build_dir "${GITHUB_WORKSPACE}/build/wasm_inferencing_jsep" \
--use_jsep \
--use_webnn \
--target onnxruntime_webassembly \
Expand All @@ -129,10 +134,12 @@ jobs:

- name: Build (simd + threads + WebGPU experimental)
if: ${{ inputs.build_webgpu == true }}
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing_webgpu \
--build_dir "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu" \
--use_webgpu \
--use_webnn \
--target onnxruntime_webassembly \
Expand All @@ -143,10 +150,12 @@ jobs:

- name: Build (simd + threads + WebGPU experimental, JSPI)
if: ${{ inputs.build_webgpu == true }}
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing_webgpu_jspi \
--build_dir "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu_jspi" \
--use_webgpu \
--use_webnn \
--enable_wasm_jspi \
Expand All @@ -157,21 +166,25 @@ jobs:

- name: Create Artifacts
if: ${{ inputs.skip_publish != true }}
shell: bash
env:
build_cfg: ${{ inputs.build_config }}
run: |
mkdir -p ${{ github.workspace }}/artifacts/wasm/
cp ${{ github.workspace }}/build/wasm_inferencing/${{ inputs.build_config }}/ort-wasm-simd-threaded.wasm ${{ github.workspace }}/artifacts/wasm/
cp ${{ github.workspace }}/build/wasm_inferencing/${{ inputs.build_config }}/ort-wasm-simd-threaded.mjs ${{ github.workspace }}/artifacts/wasm/
if [ -d ${{ github.workspace }}/build/wasm_inferencing_jsep ]; then
cp ${{ github.workspace }}/build/wasm_inferencing_jsep/${{ inputs.build_config }}/ort-wasm-simd-threaded.jsep.wasm ${{ github.workspace }}/artifacts/wasm/
cp ${{ github.workspace }}/build/wasm_inferencing_jsep/${{ inputs.build_config }}/ort-wasm-simd-threaded.jsep.mjs ${{ github.workspace }}/artifacts/wasm/
set -euo pipefail
mkdir -p "${GITHUB_WORKSPACE}/artifacts/wasm/"
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing/${build_cfg}/ort-wasm-simd-threaded.wasm" "${GITHUB_WORKSPACE}/artifacts/wasm/"
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing/${build_cfg}/ort-wasm-simd-threaded.mjs" "${GITHUB_WORKSPACE}/artifacts/wasm/"
if [ -d "${GITHUB_WORKSPACE}/build/wasm_inferencing_jsep" ]; then
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_jsep/${build_cfg}/ort-wasm-simd-threaded.jsep.wasm" "${GITHUB_WORKSPACE}/artifacts/wasm/"
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_jsep/${build_cfg}/ort-wasm-simd-threaded.jsep.mjs" "${GITHUB_WORKSPACE}/artifacts/wasm/"
fi
if [ -d ${{ github.workspace }}/build/wasm_inferencing_webgpu ]; then
cp ${{ github.workspace }}/build/wasm_inferencing_webgpu/${{ inputs.build_config }}/ort-wasm-simd-threaded.asyncify.wasm ${{ github.workspace }}/artifacts/wasm/
cp ${{ github.workspace }}/build/wasm_inferencing_webgpu/${{ inputs.build_config }}/ort-wasm-simd-threaded.asyncify.mjs ${{ github.workspace }}/artifacts/wasm/
if [ -d "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu" ]; then
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu/${build_cfg}/ort-wasm-simd-threaded.asyncify.wasm" "${GITHUB_WORKSPACE}/artifacts/wasm/"
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu/${build_cfg}/ort-wasm-simd-threaded.asyncify.mjs" "${GITHUB_WORKSPACE}/artifacts/wasm/"
fi
if [ -d ${{ github.workspace }}/build/wasm_inferencing_webgpu_jspi ]; then
cp ${{ github.workspace }}/build/wasm_inferencing_webgpu_jspi/${{ inputs.build_config }}/ort-wasm-simd-threaded.jspi.wasm ${{ github.workspace }}/artifacts/wasm/
cp ${{ github.workspace }}/build/wasm_inferencing_webgpu_jspi/${{ inputs.build_config }}/ort-wasm-simd-threaded.jspi.mjs ${{ github.workspace }}/artifacts/wasm/
if [ -d "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu_jspi" ]; then
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu_jspi/${build_cfg}/ort-wasm-simd-threaded.jspi.wasm" "${GITHUB_WORKSPACE}/artifacts/wasm/"
cp "${GITHUB_WORKSPACE}/build/wasm_inferencing_webgpu_jspi/${build_cfg}/ort-wasm-simd-threaded.jspi.mjs" "${GITHUB_WORKSPACE}/artifacts/wasm/"
fi

- name: Upload WASM artifacts
Expand All @@ -184,20 +197,24 @@ jobs:
- name: Test (Node.js) (simd + threads)
# unit tests are currently only supported in Debug builds because they require exceptions, which are disabled in Release builds.
if: ${{ inputs.build_config == 'Debug' }}
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing \
--build_dir build/wasm_inferencing \
--test
working-directory: ${{ github.workspace }}

- name: Test (browser) (simd + threads)
# unit tests are currently only supported in Debug builds because they require exceptions, which are disabled in Release builds.
if: ${{ inputs.build_config == 'Debug' }}
shell: bash
run: |
set -euo pipefail
python ./tools/ci_build/build.py \
${{ env.common_build_args }} \
--build_dir ${{ github.workspace }}/build/wasm_inferencing \
--build_dir build/wasm_inferencing \
--wasm_run_tests_in_browser \
--targets onnxruntime_test_all onnxruntime_provider_test \
--update --build --test
Expand Down
Loading
Loading