goToMain / libosdp

Implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol); provides a C library with support for C++, Rust and Python3
https://libosdp.sidcha.dev
Apache License 2.0
128 stars 69 forks source link

Unable to compile Rust libosdp #146

Closed Sympatron closed 7 months ago

Sympatron commented 7 months ago

The current documentation of the libosdp seems to be missing information. I am unable to compile my project with just cargo add libosdp .

Describe the bug I get this error:

error: failed to run custom build command for `libosdp v0.1.3`

Caused by:
  process didn't exit successfully: `/mnt/c/Users/User/Rust/osdp-test/target/debug/build/libosdp-edb4c7171095275b/build-script-build` (exit status: 1)
  --- stderr
  Error: Failed: copy /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libosdp-0.1.3/src/osdp_config.h.in -> /mnt/c/Users/User/Rust/osdp-test/target/debug/build/libosdp-11cef39218654108/out/osdp_config.h

  Caused by:
      No such file or directory (os error 2)

Additional context The build script seems to be trying to copy the osdp_config.h.in file from the libosdp directory, but there are no C files in this directory.

Sympatron commented 7 months ago

In Rust it's common to have a libosdp-sys crate that contains only the bindgen-generated FFI and a libosdp crate which contains the safe wrapper types and functions.

The libosdp-sys crate would also need to contain all the C source and header files required to build the library.

I don't quite understand how it is currently meant to work.

sidcha commented 7 months ago

Thank you for checking out the rust support. At this point rust support is super experimental and has many rough edges. I'd wait until the upcoming v3.0.0 of libosdp or v0.0.1 of osdpctl tool (rewritten in rust) before trying it out.

I have only been building it locally from sources so I didn't encounter this issue in crates.io crate. I have reproduced this issue locally, next crates.io release should fix it.

sidcha commented 7 months ago

This issue should be fixed in the latest version v0.1.5 (https://crates.io/crates/libosdp)

Sympatron commented 7 months ago

Wow, that was quick! Thank you very much.

I already used libosdp in a C project and it worked great. So I wanted to try it in Rust, too. Maybe I can help in the future.

What do you think about splitting the crate? I think it would be more idiomatic in Rust.

sidcha commented 7 months ago

Sure, we can do that, but not right now. Are there any advantages in doing so? I mean apart from being idiomatic rust.

I haven't given much thought to this yet. Maybe the split would help manage different versions of C library against different versions of the "safe-rust" wrapper.

sidcha commented 7 months ago

Looks like we do have a reason to have a libosdp-sys crate after all :)

https://users.rust-lang.org/t/sys-crate-c-source-files-from-a-different-directory/103657/11