Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to call Cargo from CMake?

I found this: https://github.com/AndrewGaspar/cmake-cargo but couldn't make it work

Anyway, if I were to use a Makefile instead of CMake, I'd simply create a rule that watches for the .rs files to change and recompile.

I couldn't find a solution for calling Cargo from Cmake (not the other way around) so I'm opening one here.

How can I make my CMakeLists.txt watch for .rs file changes and recompile by calling cargo build?

like image 472
PPP Avatar asked Jun 29 '20 23:06

PPP


2 Answers

Following recommendations, I simply added the command cargo build as a dependency to my library

add_library(libsmoltcp_cpp ${libsmoltcp_cpp_sources})

add_custom_target(
    lib_smol_tcp_rust
    COMMAND cargo build
)
add_dependencies(libsmoltcp_cpp lib_smol_tcp_rust)
like image 82
PPP Avatar answered Nov 12 '22 22:11

PPP


I'm the author of the linked project in the OP. I apologize for the sorry state it was in when you found it, but in the last month or so I've invested a bunch of time to really flesh it out, and gave it a more inspiring name: https://github.com/AndrewGaspar/corrosion

I hope you could check out the latest README and let me know if you can get it working for your scenario. And if not, please file an issue, letting me know where in the documentation you ran into issues.

like image 21
Andrew Gaspar Avatar answered Nov 13 '22 00:11

Andrew Gaspar