Skip to content

Can CARGO_HOME be customized? #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cordahi opened this issue May 15, 2025 · 0 comments
Open

Can CARGO_HOME be customized? #211

cordahi opened this issue May 15, 2025 · 0 comments

Comments

@cordahi
Copy link

cordahi commented May 15, 2025

The cargo_bin.bbclass forces CARGO_HOME to be a subdirectory of the recipe's WORKDIR

# Move CARGO_HOME from default of ~/.cargo
export CARGO_HOME = "${WORKDIR}/cargo_home"

the result is that every recipe has its own set of downloaded crates resulting in a lot of duplicate network traffic. As indicated in the comment, a common shared ~/.cargo directory is the Rust default.

IMO for building with Yocto, CARGO_HOME should be similar to DL_DIR and SSTATE_DIR, which are subdirectories of ${TOPDIR} by default, but can be changed by specifying an alternate directory in the local.conf file.

For my use case, release builds are performed using a large, but volatile TMPDIR from which only a select few files from tmp/deploy are made available before the volume is deleted. To minimize the build time and network activity, the build uses custom DL_DIR and SSTATE_DIR on a reasonably small volume that persists its contents between builds. I'd like CARGO_HOME to be a subdirectory of ${DL_DIR} (no changes for me) or a subdirectory of ${TOPDIR} (a trivial line added to local.conf). However once CARGO_HOME can be customized, the default value is no longer critical for me, other than my desire to remain relatively close to standard usage.

Can the following be used in cargo_bin.bbclass to permit my use case?

# Move CARGO_HOME from default of ~/.cargo
CARGO_HOME ?= "${DL_DIR}/cargo_home"
export CARGO_HOME

I'm not positive, but I believe Yocto will automatically create DL_DIR and SSTATE_DIR when they are the default directories in ${TMPDIR}, but require me to create my custom out-of-tree directories. So if CARGO_HOME is not in the TMPDIR tree there may be a potential issue with the command

mkdir -p "${CARGO_HOME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant