pykeio / ort

Fast ML inference & training for Rust with ONNX Runtime
https://ort.pyke.io/
Apache License 2.0
786 stars 91 forks source link

C-staticlib does not contain static ort-libs anymore #214

Closed sainteckes closed 2 months ago

sainteckes commented 2 months ago

Hey! The project is really great and using the static libs by default makes it so much nicer to use onnx runtime!

I wanted to give one of our models to a client that needs a C-Interface. I can create a static (.a) library out of the project with crate-type = ["staticlib"]. When trying to build a C++ project linking to this library it does not find the references to ort functions. So it seems like the static library does not get re-exported into the .a file. I know that I can link in the C++ project again to the static library, but do you know of a solution how rust can export the library into the .a?

Platform: Linux 6.9.5-arch1-1, x86_64 ORT-version: ort = { version = "2.0.0-rc.2", features = ["ndarray", "download-binaries"] }

Best, Stephan

decahedron1 commented 2 months ago

I believe this is just a side effect of how staticlibs are produced, since they don't include code from dependencies. The only way around this is to either link to libonnxruntime manually or build with the lib crate-type.

sainteckes commented 2 months ago

Okay thank you, but when I download the libs myself from the location of the ort-sys/dist.txt and set the env-variable ORT_LIB_LOCATION=<onnxruntime/lib> cargo build --release, the library will be included in the .a and the C project works! I just have to redownload them, as you are deleting the downloaded libs after the build?

decahedron1 commented 2 months ago

I'm not sure I understand, ort shouldn't be deleting anything. Is the library in onnxruntime/lib being automatically deleted after each build?

sainteckes commented 2 months ago

Maybe I am just not finding the ones that are automatically downloaded. Should they not be in the target folder?

decahedron1 commented 2 months ago

The automatically downloaded libraries are located in ~/.cache/ort.pyke.io/dfbin on Linux, ~/Library/Caches/ort.pyke.io/dfbin on macOS, and %LOCALAPPDATA%\ort.pyke.io\dfbin on Windows.

sainteckes commented 2 months ago

Got it, thank you!! :)

sainteckes commented 2 months ago

But why is there a difference when I build with ORT_LIB_LOCATION=~/.cache/ort.pyke.io/dfbin/x86_64-unknown-linux-gnu/6FAF334246A635808FCDAC6D5550C4D56814B1E92CCA5FC0642AF41437BF071F/onnxruntime/lib cargo build --release or without? The version above now works in the C project as well.

cagnolone commented 2 months ago

Hey @decahedron1, I think I fixed the issue with this Pull Request. Let me know with a review if it is ok.