Problems with building with --enable-rust with RUST_DEPENDENCIES
From #22816 (moved), Chelsea and I realised that there are some problems when trying to build the Rust code currently in tor in "offline mode" with RUST_DEPENDENCIES
specifying a directory where the dependencies should live. (I.e. building with RUST_DEPENDENCIES='path_to_dependencies_directory' ./configure --enable-rust
as noted on the wiki page on building with Rust.)
So one problem was that I had a relative path for RUST_DEPENDENCIES
(now noted on the wiki that it must be the full path).
There are other problems though. Cargo expects a lot of structure to be there (basically everything that would normally be in ~/.cargo
needs to be in the directory we're giving it as our HOME
or CARGO_HOME
). While we could write some scripts or something to basically reimplement a bunch of cargo functionality to set all that up, it's kind of non-trivial and it seems like a potential maintainability hazard. Another, even worse way (IMHO) around this would be to say, "if you use RUST_DEPENDENCIES
then the entire build doesn't use cargo, but instead calls rustc with the flags that cargo would have." (This seems even less maintainable, because then we have two distinct ways to compile the Rust code.)
Instead, I think a solution which is potentially better than either of those would be to say something like: "If you want to use RUST_DEPENDENCIES
, you have to run the following first, which will use cargo to get the dependencies, and then you can re-use the directory it produces offline by specifying it in `RUST_DEPENDENCIES."
mkdir path_to_dependencies_directory
cd src/rust
rm .cargo/config
CARGO_HOME="/whatever/full/path_to_dependencies_directory/.cargo" cargo update
CARGO_HOME="/whatever/full/path_to_dependencies_directory/.cargo" cargo fetch
After this initial set up of the directories which cargo is expecting the normal offline build should be conducted, and instead of passing HOME
to cargo, we should pass CARGO_HOME
as is used above.