corrosion-rs / corrosion

Marrying Rust and CMake - Easy Rust and C/C++ Integration!
https://corrosion-rs.github.io/corrosion/
MIT License
1.1k stars 106 forks source link

Fetch dependencies during configuration for offline build #548

Closed LDeakin closed 3 months ago

LDeakin commented 3 months ago

I use corrosion in environments where network access is available for CMake configuration, but not for building. While corrosion_import_crate can be run with FLAGS --offline for an offline build, this fails if the dependencies have not been downloaded.

I believe cargo fetch during configuration would make this possible. What are your thoughts on such a change/feature?

jschwe commented 3 months ago

Is there any reason why you can't use cargo vendor to download your required dependencies?

LDeakin commented 3 months ago

Maybe I am missing something, but it seems like cargo vendor is a bit inconvenient to use as Cargo.toml changes are needed.

I've ended up just doing the following with cargo fetch:

FetchContent_Declare(example ...)
FetchContent_Populate(example)
get_property(CARGO_EXECUTABLE TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION)
execute_process(COMMAND ${CARGO_EXECUTABLE} fetch --locked WORKING_DIRECTORY ${example_SOURCE_DIR})
corrosion_import_crate(MANIFEST_PATH ${example_SOURCE_DIR}/Cargo.toml FLAGS --frozen ...)