Skip to content

Commit d0b74af

Browse files
committed
fix(onnxruntime): clean CMake cache when applying Eigen hash patch
The Eigen hash patch needs to force CMake reconfiguration when applied to existing source. CMake caches the old hash in build artifacts, causing the patch to be ineffective on re-runs. Changes: - Add check to see if file is already patched (idempotent) - Clean CMake build directory after patching to force reconfiguration - This ensures the new hash is used even when source already exists
1 parent 11f6e01 commit d0b74af

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

packages/onnxruntime/scripts/build.mjs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ async function cloneOnnxSource() {
6868

6969
printHeader('Cloning ONNX Runtime Source')
7070

71+
let needsPatch = false
7172
if (existsSync(ONNX_SOURCE_DIR)) {
7273
printStep('ONNX Runtime source already exists, skipping clone')
74+
needsPatch = true
7375
} else {
7476
await fs.mkdir(BUILD_DIR, { recursive: true })
7577

@@ -80,19 +82,36 @@ async function cloneOnnxSource() {
8082
})
8183

8284
printSuccess(`ONNX Runtime ${ONNX_VERSION} cloned`)
85+
needsPatch = true
8386
}
8487

8588
// Patch eigen.cmake to accept the current Eigen hash from GitLab.
8689
// GitLab changed the archive format, causing hash mismatch.
87-
printStep('Patching eigen.cmake to accept current Eigen hash...')
88-
const eigenCmakePath = path.join(ONNX_SOURCE_DIR, 'cmake', 'external', 'eigen.cmake')
89-
const eigenCmake = await fs.readFile(eigenCmakePath, 'utf-8')
90-
const updatedEigenCmake = eigenCmake.replace(
91-
/URL_HASH SHA1=be8be39fdbc6e60e94fa7870b280707069b5b81a/g,
92-
'URL_HASH SHA1=32b145f525a8308d7ab1c09388b2e288312d8eba'
93-
)
94-
await fs.writeFile(eigenCmakePath, updatedEigenCmake, 'utf-8')
95-
printSuccess('Eigen hash updated')
90+
if (needsPatch) {
91+
printStep('Patching eigen.cmake to accept current Eigen hash...')
92+
const eigenCmakePath = path.join(ONNX_SOURCE_DIR, 'cmake', 'external', 'eigen.cmake')
93+
const eigenCmake = await fs.readFile(eigenCmakePath, 'utf-8')
94+
95+
// Check if already patched.
96+
if (eigenCmake.includes('32b145f525a8308d7ab1c09388b2e288312d8eba')) {
97+
printStep('Eigen hash already patched')
98+
} else {
99+
const updatedEigenCmake = eigenCmake.replace(
100+
/URL_HASH SHA1=be8be39fdbc6e60e94fa7870b280707069b5b81a/g,
101+
'URL_HASH SHA1=32b145f525a8308d7ab1c09388b2e288312d8eba'
102+
)
103+
await fs.writeFile(eigenCmakePath, updatedEigenCmake, 'utf-8')
104+
printSuccess('Eigen hash updated')
105+
106+
// Clean CMake cache to force reconfiguration with new hash.
107+
const cmakeBuildDir = path.join(ONNX_SOURCE_DIR, 'build')
108+
if (existsSync(cmakeBuildDir)) {
109+
printStep('Cleaning CMake cache to apply patch...')
110+
await fs.rm(cmakeBuildDir, { recursive: true, force: true })
111+
printSuccess('CMake cache cleaned')
112+
}
113+
}
114+
}
96115

97116
await createCheckpoint('onnxruntime', 'cloned')
98117
}

0 commit comments

Comments
 (0)