@@ -75,19 +75,34 @@ async function cloneOnnxSource() {
7575 if ( existsSync ( ONNX_SOURCE_DIR ) ) {
7676 printStep ( 'ONNX Runtime source already exists' )
7777
78- const depsPath = path . join ( ONNX_SOURCE_DIR , 'cmake' , 'deps.txt' )
79- const cmakePath = path . join ( ONNX_SOURCE_DIR , 'cmake' , 'onnxruntime_webassembly.cmake' )
80- const postBuildPath = path . join ( ONNX_SOURCE_DIR , 'js' , 'web' , 'script' , 'wasm_post_build.js' )
81-
82- // Check if patches have been applied.
83- const eigenPatched = existsSync ( depsPath ) &&
84- ( await fs . readFile ( depsPath , 'utf-8' ) ) . includes ( '51982be81bbe52572b54180454df11a3ece9a934' )
85- const cmakePatched = existsSync ( cmakePath ) &&
86- ( await fs . readFile ( cmakePath , 'utf-8' ) ) . includes ( '# add_compile_definitions(\n # BUILD_MLAS_NO_ONNXRUNTIME' )
87- const postBuildPatched = existsSync ( postBuildPath ) &&
88- ( await fs . readFile ( postBuildPath , 'utf-8' ) ) . includes ( 'if (matches.length === 0) {' )
89-
90- if ( ! eigenPatched || ! cmakePatched || ! postBuildPatched ) {
78+ // Define patches to verify.
79+ const patches = [
80+ {
81+ name : 'Eigen hash' ,
82+ path : path . join ( ONNX_SOURCE_DIR , 'cmake' , 'deps.txt' ) ,
83+ marker : '51982be81bbe52572b54180454df11a3ece9a934' ,
84+ } ,
85+ {
86+ name : 'MLFloat16 build' ,
87+ path : path . join ( ONNX_SOURCE_DIR , 'cmake' , 'onnxruntime_webassembly.cmake' ) ,
88+ marker : '# add_compile_definitions(\n # BUILD_MLAS_NO_ONNXRUNTIME' ,
89+ } ,
90+ {
91+ name : 'wasm_post_build.js' ,
92+ path : path . join ( ONNX_SOURCE_DIR , 'js' , 'web' , 'script' , 'wasm_post_build.js' ) ,
93+ marker : 'if (matches.length === 0) {' ,
94+ } ,
95+ ]
96+
97+ // Check if all patches have been applied.
98+ const allPatchesApplied = ( await Promise . all (
99+ patches . map ( async ( { path : filePath , marker } ) =>
100+ existsSync ( filePath ) &&
101+ ( await fs . readFile ( filePath , 'utf-8' ) ) . includes ( marker )
102+ )
103+ ) ) . every ( Boolean )
104+
105+ if ( ! allPatchesApplied ) {
91106 // Source exists but patches not applied - need to re-clone.
92107 printWarning ( 'Source exists but patches not applied' )
93108 printStep ( 'Removing old source to re-clone with patches...' )
0 commit comments