@@ -167,26 +167,6 @@ async function cloneOnnxSource() {
167167 printSuccess ( 'wasm_post_build.js (source) patched' )
168168 }
169169
170- // Delete stale cached copies in build directory.
171- // This ensures CMake will recopy the patched version from source during configure.
172- // Without this, GitHub Actions cached builds would use old unpatched version.
173- printStep ( 'Removing stale wasm_post_build.js from build cache...' )
174- const platform = process . platform === 'darwin' ? 'Darwin' : 'Linux'
175- const postBuildBuildPath = path . join ( ONNX_SOURCE_DIR , 'build' , platform , 'Release' , 'wasm_post_build.js' )
176- if ( existsSync ( postBuildBuildPath ) ) {
177- await safeDelete ( postBuildBuildPath )
178- printSuccess ( 'Stale wasm_post_build.js removed (CMake will recopy from patched source)' )
179- }
180-
181- // Clear CMake cache to force full reconfiguration.
182- // This ensures CMake recopies all files from source, picking up our patch.
183- printStep ( 'Clearing CMake cache to force reconfiguration...' )
184- const cmakeCachePath = path . join ( ONNX_SOURCE_DIR , 'build' , platform , 'Release' , 'CMakeCache.txt' )
185- if ( existsSync ( cmakeCachePath ) ) {
186- await safeDelete ( cmakeCachePath )
187- printSuccess ( 'CMake cache cleared' )
188- }
189-
190170 await createCheckpoint ( 'onnxruntime' , 'cloned' )
191171}
192172
@@ -202,6 +182,27 @@ async function build() {
202182
203183 const startTime = Date . now ( )
204184
185+ // Clean stale cached files before build.
186+ // GitHub Actions may have restored old unpatched files from cache after clone step.
187+ // Delete them now to force CMake to recopy patched versions from source.
188+ printStep ( 'Checking for stale cached build files...' )
189+ const platform = process . platform === 'darwin' ? 'Darwin' : 'Linux'
190+ const buildCacheDir = path . join ( ONNX_SOURCE_DIR , 'build' , platform , 'Release' )
191+
192+ // Delete cached wasm_post_build.js (CMake will recopy from patched source).
193+ const postBuildBuildPath = path . join ( buildCacheDir , 'wasm_post_build.js' )
194+ if ( existsSync ( postBuildBuildPath ) ) {
195+ await safeDelete ( postBuildBuildPath )
196+ printSuccess ( 'Removed stale wasm_post_build.js from cache' )
197+ }
198+
199+ // Clear CMake cache to force full reconfiguration.
200+ const cmakeCachePath = path . join ( buildCacheDir , 'CMakeCache.txt' )
201+ if ( existsSync ( cmakeCachePath ) ) {
202+ await safeDelete ( cmakeCachePath )
203+ printSuccess ( 'Cleared CMake cache' )
204+ }
205+
205206 // ONNX Runtime has its own build script: ./build.sh --config Release --build_wasm
206207 // We need to pass WASM_ASYNC_COMPILATION=0 via EMCC_CFLAGS environment variable.
207208
0 commit comments