fix: rewrite cmake and pkg-config paths after Linux tarball reshape - #28147
Open
Rishi-Dave wants to merge 2 commits into
Open
fix: rewrite cmake and pkg-config paths after Linux tarball reshape#28147Rishi-Dave wants to merge 2 commits into
Rishi-Dave wants to merge 2 commits into
Conversation
The Linux release packaging script `copy_strip_binary.sh` renames `lib64/` to `lib/` and flattens `include/onnxruntime/*` into `include/` after the cmake install step. However the files generated by `install(EXPORT ...)` (`onnxruntimeTargets-release.cmake` etc.) and the pkg-config file (`libonnxruntime.pc`) still contain the pre-reshape paths, causing `find_package(onnxruntime CONFIG)` and `pkg-config --libs onnxruntime` to fail for tarball consumers. Patch the stale paths in place after the reshape steps using narrow `sed` substitutions, guarded by existence checks so builds without pkg-config or cmake exports are unaffected. Fixes microsoft#23642
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Linux packaging reshape step so that the generated CMake package export files and pkg-config metadata match the post-reshape tarball layout (lib64 → lib and include/onnxruntime → include), restoring downstream usability of find_package(onnxruntime CONFIG) and pkg-config --libs onnxruntime.
Changes:
- After reshaping
lib64/tolib/, rewrites stale/lib64/and/include/onnxruntimereferences in installed*.cmakefiles underlib/cmake. - Rewrites
libdir/includedirinlib/pkgconfig/libonnxruntime.pcto match the reshaped layout.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+58
| # Fix stale paths baked into cmake config files by `install(EXPORT ...)` | ||
| # - lib64/ was renamed to lib/ above | ||
| # - include/onnxruntime/ was flattened into include/ above | ||
| if [ -d "$ARTIFACT_NAME/lib/cmake" ]; then | ||
| find "$ARTIFACT_NAME/lib/cmake" -type f -name "*.cmake" -exec \ | ||
| sed -i -e 's|/lib64/|/lib/|g' -e 's|/include/onnxruntime"|/include"|g' {} + | ||
| fi | ||
| # Fix pkg-config file similarly | ||
| if [ -f "$ARTIFACT_NAME/lib/pkgconfig/libonnxruntime.pc" ]; then | ||
| sed -i -e 's|/lib64$|/lib|' -e 's|/lib64/|/lib/|g' \ | ||
| -e 's|/include/onnxruntime$|/include|' -e 's|/include/onnxruntime/|/include/|g' \ | ||
| "$ARTIFACT_NAME/lib/pkgconfig/libonnxruntime.pc" | ||
| fi |
The cmake include-path rewrite (include/onnxruntime -> include) was
previously only applied in the Linux branch, but macOS tarballs also
flatten the include directory at line 21 and install cmake config files
under lib/cmake/. Hoist the cmake include-path rewrite to run after the
branch so it covers both Linux and macOS.
Additionally, replace `sed -i` with the portable `sed -i.bak ... && rm
*.bak` pattern throughout, since BSD sed (macOS) requires an explicit
backup extension argument while GNU sed (Linux) accepts an empty string.
The `-exec sh -c '...' _ {} \;` form processes one file at a time,
which is compatible with both implementations.
Contributor
Author
|
Thanks for the review. Addressed both points in 1a1a32d:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib64/andinclude/onnxruntime/paths in the generated cmake export and pkg-config files after the Linux tarball packaging script reshapes the directory layout.find_package(onnxruntime CONFIG)andpkg-config --libs onnxruntimework against the released Linux tarball.Motivation
Fixes #23642.
On x86-64 Linux,
GNUInstallDirssetsCMAKE_INSTALL_LIBDIR=lib64and the build installs headers underinclude/onnxruntime/. The packaging scripttools/ci_build/github/linux/copy_strip_binary.shthen reshapes the tarball:mv $ARTIFACT_NAME/lib64 $ARTIFACT_NAME/libmv $ARTIFACT_NAME/include/onnxruntime/* $ARTIFACT_NAME/include && rmdir $ARTIFACT_NAME/include/onnxruntimeThe files produced by
install(EXPORT onnxruntimeTargets ...)(onnxruntimeTargets-release.cmake, etc.) andconfigure_file(libonnxruntime.pc.cmake.in ...)still reference the pre-reshape locations, so downstream consumers see:IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib64/libonnxruntime.so.X"— file does not existINTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/onnxruntime"— directory does not existlibdir=${prefix}/lib64/includedir=${prefix}/include/onnxruntimeinlibonnxruntime.pcAn earlier attempt (#26104) tried to eliminate the reshape itself and was reverted (#26767) because downstream release pipelines and example repos depended on the
lib/+ flatinclude/layout. This change takes the opposite approach: keep the existing tarball layout and fix the metadata to match it — fully self-contained in the packaging step.Changes
tools/ci_build/github/linux/copy_strip_binary.sh— after the existingmv lib64 libstep, add two guardedsedblocks:/lib64/→/lib/and/include/onnxruntime"→/include"in every*.cmakeunder$ARTIFACT_NAME/lib/cmake(coversonnxruntimeConfig.cmake,onnxruntimeTargets.cmake, and per-configonnxruntimeTargets-*.cmake).libdirandincludedirentries in$ARTIFACT_NAME/lib/pkgconfig/libonnxruntime.pc.Patterns are anchored (trailing
/, trailing", or end-of-line) to avoid over-matching. Guarded with[ -d ]/[ -f ]so builds that don't install cmake exports or pkg-config files are unaffected. No cmake build-system changes; no effect on the macOS branch.Test Plan
bash -n tools/ci_build/github/linux/copy_strip_binary.sh— syntax clean.lib/cmake/onnxruntime/onnxruntimeTargets-release.cmakewith${_IMPORT_PREFIX}/lib64/libonnxruntime.so.Xand${_IMPORT_PREFIX}/include/onnxruntime, andlib/pkgconfig/libonnxruntime.pcwithlibdir=${prefix}/lib64/includedir=${prefix}/include/onnxruntime. After running the new block,grep -r 'lib64\|include/onnxruntime' lib/returns no matches; the rewrittenIMPORTED_LOCATION_RELEASEandlibdirpoint at the real, reshaped locations.