Skip to content
Merged
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
11 changes: 0 additions & 11 deletions .github/workflows/linux-wasm-ci-build-and-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ jobs:
with:
node-version: "22"

# The image used in this workflow has an old version of Node.js installed at /bin/node and npm at /bin/npm.
# We need to remove the system Node.js and npm, otherwise CMake will not be able to find the correct Node.js and npm executables.
- name: Remove the system Node.js
run: |
if [ -f /bin/node ]; then
rm /bin/node
fi
if [ -f /bin/npm ]; then
rm /bin/npm
fi

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
114 changes: 114 additions & 0 deletions cmake/node_helper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.25)

# Function to get NPM path from Node.js path
function(get_npm_path_from_node result_var node_path)
get_filename_component(NODE_DIR ${node_path} DIRECTORY)
if(WIN32)
set(NPM_CLI_CANDIDATE "${NODE_DIR}/npm.cmd")
if(NOT EXISTS ${NPM_CLI_CANDIDATE})
set(NPM_CLI_CANDIDATE "${NODE_DIR}/npm")
endif()
else()
set(NPM_CLI_CANDIDATE "${NODE_DIR}/npm")
endif()

set(${result_var} ${NPM_CLI_CANDIDATE} PARENT_SCOPE)
endfunction()

# Validator function for Node.js installation (checks both Node.js and NPM versions)
function(validate_nodejs_installation result_var node_path)
# First validate Node.js version
execute_process(
COMMAND ${node_path} --version
OUTPUT_VARIABLE NODE_VERSION_OUTPUT
ERROR_VARIABLE NODE_VERSION_ERROR
RESULT_VARIABLE NODE_VERSION_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(NODE_VERSION_RESULT EQUAL 0)
# Node version output starts with 'v', e.g., "v20.10.0"
string(REGEX MATCH "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)" NODE_VERSION_MATCH ${NODE_VERSION_OUTPUT})
if(NODE_VERSION_MATCH)
set(NODE_VERSION_MAJOR ${CMAKE_MATCH_1})

if(NODE_VERSION_MAJOR LESS 20)
message(STATUS "Node.js at ${node_path} version ${NODE_VERSION_OUTPUT} is too old. Required: >= v20.0.0")
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()

message(STATUS "Found Node.js at ${node_path} with version: ${NODE_VERSION_OUTPUT}")
else()
message(STATUS "Could not parse Node.js version from ${node_path}: ${NODE_VERSION_OUTPUT}")
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()
else()
message(STATUS "Failed to get Node.js version from ${node_path}: ${NODE_VERSION_ERROR}")
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()

# Now validate NPM from the same installation directory
get_npm_path_from_node(NPM_CLI_CANDIDATE ${node_path})

if(NOT EXISTS ${NPM_CLI_CANDIDATE})
get_filename_component(NODE_DIR ${node_path} DIRECTORY)
message(STATUS "Could not find NPM in the same directory as Node.js: ${NODE_DIR}")
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()

# Validate NPM version
execute_process(
COMMAND ${NPM_CLI_CANDIDATE} --version
OUTPUT_VARIABLE NPM_VERSION_OUTPUT
ERROR_VARIABLE NPM_VERSION_ERROR
RESULT_VARIABLE NPM_VERSION_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(NPM_VERSION_RESULT EQUAL 0)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" NPM_VERSION_MATCH ${NPM_VERSION_OUTPUT})
if(NPM_VERSION_MATCH)
set(NPM_VERSION_MAJOR ${CMAKE_MATCH_1})

if(NPM_VERSION_MAJOR LESS 10)
message(STATUS "NPM at ${NPM_CLI_CANDIDATE} version ${NPM_VERSION_OUTPUT} is too old. Required: >= 10.0.0")
set(${result_var} FALSE PARENT_SCOPE)
return()
endif()

message(STATUS "Found NPM at ${NPM_CLI_CANDIDATE} with version: ${NPM_VERSION_OUTPUT}")
set(${result_var} TRUE PARENT_SCOPE)
else()
message(STATUS "Could not parse NPM version from ${NPM_CLI_CANDIDATE}: ${NPM_VERSION_OUTPUT}")
set(${result_var} FALSE PARENT_SCOPE)
endif()
else()
message(STATUS "Failed to get NPM version from ${NPM_CLI_CANDIDATE}: ${NPM_VERSION_ERROR}")
set(${result_var} FALSE PARENT_SCOPE)
endif()
endfunction()

# Check if both Node.js and NPM are already provided
if((NOT NPM_CLI) OR (NOT NODE_EXECUTABLE))
# Find node executable with combined Node.js + NPM validation
find_program(NODE_EXECUTABLE
NAMES "node.exe" "node"
DOC "Node.js executable"
VALIDATOR validate_nodejs_installation
REQUIRED
)

# Set NPM_CLI from the validated Node.js installation
get_npm_path_from_node(NPM_CLI ${NODE_EXECUTABLE})
set(NPM_CLI ${NPM_CLI} CACHE FILEPATH "NPM command line client" FORCE)
message(STATUS "Using Node.js and NPM from the same validated installation:")
message(STATUS " Node.js: ${NODE_EXECUTABLE}")
message(STATUS " NPM: ${NPM_CLI}")
endif()
25 changes: 2 additions & 23 deletions cmake/onnxruntime_nodejs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,8 @@ set(JS_ROOT ${REPO_ROOT}/js)
set(JS_COMMON_ROOT ${JS_ROOT}/common)
set(JS_NODE_ROOT ${JS_ROOT}/node)

find_program(NPM_CLI
NAMES "npm.cmd" "npm"
DOC "NPM command line client"
REQUIRED
)

# verify Node.js and NPM
execute_process(COMMAND node --version
WORKING_DIRECTORY ${JS_NODE_ROOT}
OUTPUT_VARIABLE node_version
RESULT_VARIABLE had_error
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(had_error)
message(FATAL_ERROR "Failed to find Node.js: " ${had_error})
endif()
execute_process(COMMAND ${NPM_CLI} --version
WORKING_DIRECTORY ${JS_NODE_ROOT}
OUTPUT_VARIABLE npm_version
RESULT_VARIABLE had_error
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(had_error)
message(FATAL_ERROR "Failed to find NPM: " ${had_error})
endif()
# Include the Node.js helper for finding and validating Node.js and NPM
include(node_helper.cmake)

# setup ARCH
if (APPLE)
Expand Down
15 changes: 4 additions & 11 deletions cmake/onnxruntime_providers_webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,13 @@
set(WGSL_TEMPLATES_DIR "${ONNXRUNTIME_ROOT}/core/providers/webgpu/wgsl_templates")
set(WGSL_GENERATED_ROOT "${CMAKE_CURRENT_BINARY_DIR}/wgsl_generated")

# Find npm and node executables
find_program(NPM_EXECUTABLE "npm.cmd" "npm" REQUIRED)
if(NOT NPM_EXECUTABLE)
message(FATAL_ERROR "npm is required for WGSL template generation but was not found")
endif()
find_program(NODE_EXECUTABLE "node" REQUIRED)
if (NOT NODE_EXECUTABLE)
message(FATAL_ERROR "Node is required for WGSL template generation but was not found")
endif()
# Include the Node.js helper for finding and validating Node.js and NPM
include(node_helper.cmake)

# Install npm dependencies
add_custom_command(
OUTPUT "${WGSL_TEMPLATES_DIR}/node_modules/.install_complete"
COMMAND ${NPM_EXECUTABLE} ci
COMMAND ${NPM_CLI} ci
COMMAND ${CMAKE_COMMAND} -E touch "${WGSL_TEMPLATES_DIR}/node_modules/.install_complete"
DEPENDS "${WGSL_TEMPLATES_DIR}/package.json" "${WGSL_TEMPLATES_DIR}/package-lock.json"
WORKING_DIRECTORY ${WGSL_TEMPLATES_DIR}
Expand Down Expand Up @@ -203,7 +196,7 @@
# Generate WGSL templates
add_custom_command(
OUTPUT ${WGSL_GENERATED_INDEX_H} ${WGSL_GENERATED_INDEX_IMPL_H} ${WGSL_GENERATED_TEMPLATES_JS}
COMMAND ${NPM_EXECUTABLE} run gen -- ${WGSL_GEN_OPTIONS}
COMMAND ${NPM_CLI} run gen -- ${WGSL_GEN_OPTIONS}
DEPENDS "${WGSL_TEMPLATES_DIR}/node_modules/.install_complete" ${WGSL_TEMPLATE_FILES}
WORKING_DIRECTORY ${WGSL_TEMPLATES_DIR}
COMMENT "Generating WGSL templates from *.wgsl.template files"
Expand Down
9 changes: 2 additions & 7 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,8 @@ function(AddTest)
# xctest_add_test(xctest.${_UT_TARGET} ${_UT_TARGET}_xc)
else()
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# We might have already executed the following "find_program" code when we build ORT nodejs binding.
# Then the program is found the result is stored in the variable and the search will not be repeated.
find_program(NPM_CLI
NAMES "npm.cmd" "npm"
DOC "NPM command line client"
REQUIRED
)
# Include the Node.js helper for finding and validating Node.js and NPM
include(node_helper.cmake)

if (onnxruntime_WEBASSEMBLY_RUN_TESTS_IN_BROWSER)
add_custom_command(TARGET ${_UT_TARGET} POST_BUILD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
echo "File '$path' already exists. Skipping download"
return 0
else
rm -rf $path

Check warning on line 18 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:18:14: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
fi
fi

if [[ -f $uri ]]; then
echo "'$uri' is a file path, copying file to '$path'"
cp $uri $path

Check warning on line 24 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:24:13: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 24 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:24:8: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
return $?
fi

echo "Downloading $uri"
# Use aria2c if available, otherwise use curl
if command -v aria2c > /dev/null; then
aria2c -q -d $(dirname $path) -o $(basename $path) "$uri"

Check warning on line 31 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:31:49: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 31 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Quote this to prevent word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:31:38: warning: Quote this to prevent word splitting. (ShellCheck.SC2046)

Check warning on line 31 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:31:28: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 31 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Quote this to prevent word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:31:18: warning: Quote this to prevent word splitting. (ShellCheck.SC2046)
else
curl "$uri" -sSL --retry $download_retries --retry-delay $retry_wait_time_seconds --create-dirs -o "$path" --fail

Check warning on line 33 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:33:62: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check warning on line 33 in tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh

View workflow job for this annotation

GitHub Actions / Optional Lint

[shellcheck] reported by reviewdog 🐶 Double quote to prevent globbing and word splitting. Raw Output: ./tools/ci_build/github/linux/docker/scripts/manylinux/install_shared_deps.sh:33:30: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
fi

return $?
Expand All @@ -39,6 +39,6 @@
cd /tmp/src

echo "Installing Node.js"
# The EOL for nodejs v18.17.1 LTS is April 2025
GetFile https://nodejs.org/dist/v18.17.1/node-v18.17.1-linux-x64.tar.gz /tmp/src/node-v18.17.1-linux-x64.tar.gz
tar --strip 1 -xf /tmp/src/node-v18.17.1-linux-x64.tar.gz -C /usr
# The EOL for nodejs v22.17.1 LTS is April 2027
GetFile https://nodejs.org/dist/v22.17.1/node-v22.17.1-linux-x64.tar.gz /tmp/src/node-v22.17.1-linux-x64.tar.gz
tar --strip 1 -xf /tmp/src/node-v22.17.1-linux-x64.tar.gz -C /usr
Loading