arrayfire / arrayfire-rust

Rust wrapper for ArrayFire
BSD 3-Clause "New" or "Revised" License
815 stars 57 forks source link

Statically linking arrayfire #192

Open vadixidav opened 5 years ago

vadixidav commented 5 years ago

Right now arrayfire has to be used by linking to the DLL. Since the only parts of arrayfire that are included in the Rust bindings are BSD 3-clause, there should be no problem statically linking arrayfire. Is it possible that we could choose whether or not arrayfire is statically linked to ease distribution? Also, is there any downside to just always statically linking arrayfire? I feel like that would be more in-line with what the Rust community expects: adding a crate to your Cargo.toml should "just work".

9prady9 commented 5 years ago

There is one major problem with doing that I think. Rust crates can't go beyond a certain size. ArrayFire binaries are big right now, definitely not in the range of crate size, the last time I checked it was 10MB

9prady9 commented 5 years ago

Whether you use static or dynamic binaries of ArrayFire, the size can't go to 10MB for sure.

9prady9 commented 5 years ago

Looks like per crate limits were added but I don't know yet if it's released.

9prady9 commented 5 years ago

Also, I am not really sure if it's good idea to club binary along with crate using static linking. Because right now there is an advantage : user can install/modify ArrayFire installation independent of crate version and as long as crate version matches ArrayFire's version, it is ready for use.

vadixidav commented 5 years ago

A feature could be added to enable dynamic linking as well. By default it could be statically linked, but for deployment it could then be dynamically linked by enabling the feature.

9prady9 commented 5 years ago

@vadixidav I have no experience doing such packaging(involving static linking but handling all OSes) in rust crates. Can you please point to another crate that does this.

vadixidav commented 5 years ago

@9prady9 Sure, I actually just did this for the Rust flann bindings here. Check the flann-sys directory. This was being built using CMake, which it looks like ArrayFire is as well. If you would like, I can attempt this myself. This would make it so that, by default, ArrayFire would be built by Cargo and statically linked, but if you enabled the special dynamic link flag then it would try to use the shared library. Does this sound fine?

9prady9 commented 5 years ago

I am concerned by build times of ArrayFire - it takes too much time to be honest. Let me check flann-sys. Sure, give it a try and feel free to contact on slack for quick response if you face problems during static build.

9prady9 commented 4 years ago

https://github.com/arrayfire/arrayfire/issues/313

9prady9 commented 2 years ago

@umar456 Can you please share your findings w.r.t creating a static library of ArrayFire here.

9prady9 commented 2 years ago

@vadixidav Did you get the chance to try it out ?

vadixidav commented 2 years ago

@vadixidav Did you get the chance to try it out ?

I haven't, but I can give it a try when I get a chance.