summaryrefslogtreecommitdiff
path: root/src/rust/cargo/README.md
blob: 4e6d59a694336650ca2369bbfec092abb14599eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Importing cargo dependencies

The [rules for rust](https://github.com/just-buildsystem/rules-rust) also
bring a tool to import dependencies from cargo. Here we give an overview of
its usage, using the subidrectory `circle` as a dependency.

## Files written by hand

Cargo dependencies are described as dependencies of a crate. So all the
files you would normally write by hand when writing a crate have to be
manually added. As we define a binary, those are
  - `Cargo.toml`, and
  - `src/main.rs`.

## Using `just-import-cargo`

As other import tools, `just-import-cargo` expects a repository specification
on standard input and returns one on standard output. It needs to know
 - the root of the pyhsical repository, and
 - the location of the crate directory, relative to the root of the physical
   repository.
 - the name of the already imported `rules-rust` repository, if desired
   (otherwise it will default to the upstream rust rules).

The name of the imported main repository is the crate name (without version),
as specified in the `Cargo.toml` file. Some care should be taken that is does
not conflict with already existing repositories; repositories from the
`etc/repos.templace.json` can have a binding to that still to be imported
repository, as usual.

As opposed to other import tools, however, `just-import-cargo` also creates
files in the pysical repository. Those are the following.
 - In the crate the file `Cargo.lock` generated by the call to cargo, as
   well as a target file,
 - The file `etc/defaults/rust/TARGETS.cargo_import` relative to
   in the top-level of the physical repository (with a content
   independent of the respective crate).
 - In the directory `etc/deps-rust` target files for all the imported crates.
   As their name encode crate name and version, calling `just-import-cargo`
   for several crates should not cause a conflict here.