corrosion-rs / corrosion

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

Is it not possible to tell corrosion to use pre-fetched crates and NOT attempt to download? #578

Open jrmarino opened 1 week ago

jrmarino commented 1 week ago

for example:

# Import taskchampion-lib as a CMake library. This implements the Rust side of
# the cxxbridge, and depends on the `taskchampion` crate.
corrosion_import_crate(
  MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml"
  LOCKED
  CRATES "taskchampion-lib"
  FEATURES "${TASKCHAMPION_FEATURES}")

# Set up `taskchampion-cpp`, the C++ side of the bridge.
corrosion_add_cxxbridge(taskchampion-cpp
  CRATE taskchampion_lib
  FILES lib.rs
)

In this sandbox, internet connectivity is intentionally disabled, so the crates have been prefetched and placed at /myloc/cargo-crates. I haven't been able to figure out how to tell corrosion_import_crate this location (so downloading isn't required).

This is an example of how I typically do this with cargo directly:

        # create directives
        ${MKDIR} ${WRKSRC}/.cargo
        echo "[source.cargo]" >> ${WRKSRC}/.cargo/config.toml
        echo "directory = '${CARGO_VENDOR_DIR}'" >> ${WRKSRC}/.cargo/config.toml
        echo "[source.crates-io]" >> ${WRKSRC}/.cargo/config.toml
        echo "replace-with = 'cargo'" >> ${WRKSRC}/.cargo/config.toml

So is it possible to use corrosion offline with prepositioned crates?

jschwe commented 1 week ago

Adding a .cargo/config.toml should work. Under the hood corrosion just calls cargo. There is no mechanism in corrosion to generate a config.toml, but you could do that in your own cmake code if you wanted. Let me know if you run into any issues with that. I think you may also need to pass some additional cargo flags to cargo via corrosion, (perhaps it was --frozen ) to avoid cargo metadata accessing the Internet.