rust-embedded / rust-embedded/meta-rust-bin

Can CARGO_HOME be customized?

Open
#211 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
BitBake
Stars
124
Forks
92
Avg merge
6h 54m
Merged PRs (30d)
2

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with classes/cargo_bin.bbclass at lines 10-11 and the mkdir command at line 65, then compare how DL_DIR and SSTATE_DIR are configured in Yocto. Done means CARGO_HOME can be set through configuration, shared crate downloads avoid per-recipe duplication, and the configured directory is created or handled correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.