Skip to content

Conversation

@jordanozang
Copy link
Contributor

@jordanozang jordanozang commented Sep 23, 2024

Description

See the example repository for a minimal example of using the static CMake Config.

  • Add libraries built during the static onnxruntime build (onnxruntime_common, onnxruntime_mlas, etc.) to the onnxruntime export set. Additionally, add an onnxruntime::onnxruntime interface target that behaves much the same as that target in the shared build case.
    find_package(onnxruntime REQUIRED)
    target_link_libraries(example PRIVATE onnxruntime::onnxruntime)
    should now work.
  • Minor modifications to ensure that dependency targets like Boost::mp11 are treated as imported targets and not part of the build interface.
  • Static webgpu builds will currently not generate this CMake export

Motivation and Context

@jordanozang
Copy link
Contributor Author

jordanozang commented Sep 23, 2024 via email

@jordanozang jordanozang force-pushed the cmake_config_static_builds branch 4 times, most recently from 4a274e0 to 6e977f1 Compare September 24, 2024 17:25
@jordanozang jordanozang marked this pull request as ready for review September 24, 2024 17:34
@jordanozang jordanozang marked this pull request as draft September 24, 2024 17:48
@jordanozang jordanozang marked this pull request as ready for review September 24, 2024 17:59
@jordanozang
Copy link
Contributor Author

I think @snnn probably has the most context on this. Hopefully tagging is ok. I don't think I have permission to add reviewers as suggested in the contributing guidelines.

@zwillikon
Copy link

@skottmckay Hey, may you please merge this?

@jordanozang jordanozang force-pushed the cmake_config_static_builds branch from 6e977f1 to 7ad1188 Compare October 14, 2024 18:38
@snnn
Copy link
Contributor

snnn commented Oct 15, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Contributor

snnn commented Oct 15, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline,

@snnn
Copy link
Contributor

snnn commented Oct 15, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline,

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@azure-pipelines
Copy link

Azure Pipelines successfully started running 9 pipeline(s).

@jordanozang jordanozang force-pushed the cmake_config_static_builds branch from bbebf04 to 77f7188 Compare October 16, 2024 18:51
This was referenced Oct 18, 2024
snnn pushed a commit that referenced this pull request Oct 21, 2024
### Description
1. Remove the onnxruntime::OrtMutex class and replace it with
~absl::Mutex~ std::mutex.
2. After this change, most source files will not include <Windows.h>
indirectly.


### Motivation and Context
To reduce the number of deps we have, and address some Github issues
that are related to build ONNX Runtime from source.
In PR #3000 , I added a custom implementation of std::mutex . It was
mainly because at that time std::mutex's default constructor was not
trivial on Windows. If you had such a mutex as a global var, it could
not be initialized at compile time. Then VC++ team fixed this issue.
Therefore we don't need this custom implementation anymore.

This PR also removes nsync. I ran several models tests on Linux. I
didn't see any perf difference.
This PR also reverts PR #21005 , which is no longer needed since conda
has updated its msvc runtime DLL.

This PR unblocks #22173 and resolves #22092 . We have a lot of open
issues with nsync. This PR can resolve all of them.
@jordanozang jordanozang force-pushed the cmake_config_static_builds branch 3 times, most recently from 5f52e48 to b3aa2b7 Compare October 22, 2024 13:03
@snnn
Copy link
Contributor

snnn commented Oct 22, 2024

/azp run Big Models, Linux Android Emulator QNN CI Pipeline, Linux CPU CI Pipeline, Linux CPU Minimal Build E2E CI Pipeline, Linux GPU CI Pipeline, Linux GPU TensorRT CI Pipeline

@snnn
Copy link
Contributor

snnn commented Oct 22, 2024

/azp run Linux OpenVINO CI Pipeline, Linux QNN CI Pipeline, MacOS CI Pipeline, ONNX Runtime Web CI Pipeline, Windows ARM64 QNN CI Pipeline

@snnn
Copy link
Contributor

snnn commented Oct 22, 2024

/azp run Windows CPU CI Pipeline, Windows GPU CUDA CI Pipeline, Windows GPU DML CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows GPU TensorRT CI Pipeline, Windows x64 QNN CI Pipeline, onnxruntime-binary-size-checks-ci-pipeline, orttraining-linux-ci-pipeline, orttraining-linux-gpu-ci-pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

On my system, Protobuf major version 4 causes
a build failure. However, newer versions seem to
work on other platforms and the vcpkg build
depends on using version 4.25, since it builds
upstream dependencies with that version.
onnxruntime_providers_qnn needs to be exported for
static builds.

ABSL_ENABLE_INSTALL option conflicts with using
XNNPACK.

Static builds with training enabled were failing
because of missing tensorboard exports.
As tensorboard has no CMake scripts, add them.
On Android, Protobuf needs to link with the log
system library. When passed directly to
target_link_libraries, CMake treats this as any
other dependency. In particular, it reports an
error for the static build because it isn't
imported or in an export set. Instead of passing
log, instead pass -llog, so CMake will treat it
as an external system library as expected.
Many headers are added as interface includes
by onnxruntime-extensions but are only required
for building that library. Only one include,
${onnxruntime_EXTENSIONS_PATH}/includes, is
required to consume the library. Additionally,
because the include of onnxruntime_extensions.h is
limited to onnxruntime_c_api.cc, not any api
headers, this include can safely be scoped to the
build interface, even for consumers of static
builds.

This should fix the wasm CI runs for pr microsoft#22173.
@jordanozang jordanozang force-pushed the cmake_config_static_builds branch from 4254fbe to 286db64 Compare May 10, 2025 20:28
@jordanozang jordanozang force-pushed the cmake_config_static_builds branch from 286db64 to 6aa872b Compare May 10, 2025 20:33
@jordanozang
Copy link
Contributor Author

Hi @snnn, I have brought this pr back up to date and tested it locally on Linux and Windows for static and shared builds.

@snnn
Copy link
Contributor

snnn commented May 14, 2025

/azp run Windows x64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows ARM64 QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Linux QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@snnn
Copy link
Contributor

snnn commented May 14, 2025

The wasm pipeline failed

@jordanozang
Copy link
Contributor Author

It should build now

@snnn
Copy link
Contributor

snnn commented May 14, 2025

/azp run Windows x64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline, Windows ARM64 QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Linux QNN CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@snnn snnn added build build issues; typically submitted using template and removed waiting-for-customer labels May 14, 2025
@snnn snnn merged commit e55ce52 into microsoft:main May 14, 2025
80 of 82 checks passed
@snnn
Copy link
Contributor

snnn commented May 14, 2025

Thank you!

quic-ankus pushed a commit to CodeLinaro/onnxruntime that referenced this pull request Nov 25, 2025
### Description

See the [example
repository](https://github.com/jordanozang/onnxruntime_minimal_static)
for a minimal example of using the static CMake Config.
- Add libraries built during the static onnxruntime build
(onnxruntime_common, onnxruntime_mlas, etc.) to the onnxruntime export
set. Additionally, add an onnxruntime::onnxruntime interface target that
behaves much the same as that target in the shared build case.
``find_package(onnxruntime REQUIRED)``
``target_link_libraries(example PRIVATE onnxruntime::onnxruntime)``
should now work.
- Minor modifications to ensure that dependency targets like Boost::mp11
are treated as imported targets and not part of the build interface.
- Static webgpu builds will currently not generate this CMake export




### Motivation and Context
- Resolves Issue microsoft#21351
- Builds on Pull Request microsoft#21348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build build issues; typically submitted using template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants