package/pkg-cargo: move CARGO_HOME into DL_DIR

CARGO_HOME is where Cargo stores its downloaded artefacts. See
https://doc.rust-lang.org/cargo/reference/environment-variables.html:

  CARGO_HOME — Cargo maintains a local cache of the registry index and
  of git checkouts of crates. By default these are stored under
  $HOME/.cargo (%USERPROFILE%\.cargo on Windows), but this variable
  overrides the location of this directory. Once a crate is cached it
  is not removed by the clean command. For more details refer to the
  guide.

We currently make it point to $(HOST_DIR)/share/cargo, but this has a
number of drawbacks:

 (1) It is not shared between Buildroot builds. Each Buildroot build
     will re-download the crates index, and the crates themselves,
     unless of course the final vendored tarball is already there.

 (2) With BR2_PER_PACKAGE_DIRECTORIES=y, it is even worse: CARGO_HOME
     is not even shared between packages, as $(HOST_DIR)/share/cargo
     is per package. So each package in the build that needs vendoring
     of Cargo crates will download the crates index and the crates in
     its own CARGO_HOME location.

To solve this, this commit moves CARGO_HOME into $(DL_DIR), so that it
is shared between builds and packages.

Even though not the best/most authoritative source,
https://github.com/rust-lang/cargo/issues/6930 indicates that there is
a lock when accessing CARGO_HOME, because a user even complains that
this lock has even become more coarse-grained than it used to be
(which for us is fine, it just means that two Cargo fetch operations
from two different packages will be serialized, not a big deal).

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Tested-by: Moritz Bitsch <moritz@h6t.eu>
[yann.morin.1998@free.fr: rename directory: s/\.cargo/br-cargo-home/]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Thomas Petazzoni 2022-11-03 23:45:38 +01:00 committed by Yann E. MORIN
parent 3dde279269
commit 8450b76918

View File

@ -20,7 +20,7 @@
# #
################################################################################ ################################################################################
BR_CARGO_HOME = $(HOST_DIR)/share/cargo BR_CARGO_HOME = $(DL_DIR)/br-cargo-home
PKG_COMMON_CARGO_ENV = \ PKG_COMMON_CARGO_ENV = \
CARGO_HOME=$(BR_CARGO_HOME) CARGO_HOME=$(BR_CARGO_HOME)