I'm trying to set up a local cargo registry so I don't have to download the dependencies because I have them beforehand. I have downloaded the index and each .crate file through get-all-crates. But at the time I want to use these downloaded files without network access, I don't achieve to do so, what is the way to do so?
As soon as I set the net.offline option to false in .cargo/config.toml for a project, it will not use the index I provide to. Concretely I have tried to set registries.my-registry = { index = "file:///path/to/crates.io-index" } and registry.default = "my-registry", but when running cargo add syn I get the next error: error: the crate syn could not be found in registry index.. The next step would be to use the crate files I have downloaded, but I cannot even query the local index.
This has nothing to do, I'm looking for cargo to use the already downloaded crates by enabling a local registry. There is not documentation about how to do so.
To base which comparison? I already have all the packages I need downloaded without belonging to CARGO_HOME, I want them to be used directly without having to access online resources. I also accept to include them in CARGO_HOME, but there is no documentation about how to modify in a consistent way this registry and index.
I didn't think that cargo used a non-crate specific manifest file, I think the dependencies are declares in the manifest and matched to the version number which is the name of the file in the archive.
I don't think you are understanding the issue. Cargo does fetch the dependencies of a crate from a default registry (crates.io), and this can be changed. Despite the dependencies are declared in the Manifest file, they are downloaded using a registry index. Therefore, if I want to build a project without fetching the dependencies (because I already fetched them through another method but they are not included in the registry from CARGO_HOME), I should provoke cargo to either fetch these dependencies from my local registry, but I'm not finding any way.
If the crates kept in .cargo are up to the version you are wanting to archive and that is reflected in the manifest should that not work offline? Then you might only need to check the names of the archive files when setting up a new environment.
Please, stop responding to this post unless you manage to have a local registry working. For the rest of the users in this forum, please reach out if you know how to address the setup of local registries or how to include the downloaded index and corresponding crates in an existing CARGO_HOME.
I'm not sure if it's ever possible to make the local registry available with only file:// URLs, but I've built a small server to be used in this case. It's obviously non-optimal, but, well, it worked, at least back then.
instead of change the default registry, did you try to replace the source of the crates-io registry? I don't know whether it works offline though.
[source.my-source]
local-registry = "path/to/registry"
# besides `local-registry`, other source types can be used, e.g. registry/git/directory
[source.crates-io]
replace-with = "my-source"
Thanks for the comment, this one worked in fact. If anyone has the same problem in the future, to reproduce my solution, run the next:
Create a folder that corresponds to the registry (e.g., /path/to/registry, we map the contents of the registry into the own registry: ln -s /path/to/crates.io-index/ /path/to/registry/index and fd . /path/to/downloaded/crates --extension=crate --exec ln -s {} /path/to/registry/. The contents of .cargo/config.toml within the crate are: