Skip to content

Can CARGO_HOME be customized? #211

@cordahi

Description

@cordahi

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}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions