Skip to content

build_from_source makes assumptions on internal Cargo details, breaking cargo-miri with new build-dir features #25

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
epage opened this issue May 5, 2025 · 3 comments

Comments

@epage
Copy link

epage commented May 5, 2025

Original report at rust-lang/cargo#14125 (comment)

miri (13e8790949 2025-05-04) fails to run with

$ cargo miri clean
$ cargo miri test
Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... fatal error: failed to build sysroot: failed to read cargo out dir

Caused by:
    No such file or directory (os error 2)

when

[build]
build-dir = "{cargo-cache-home}/build/{workspace-path-hash}"

[unstable]
build-dir=true

is set in ~/.cargo/config.toml.

After disabling these lines, miri can create the sysroot and works when these lines are reenabled.

The problem is

let out_dir = build_target_dir
.join(&target_name)
.join(DEFAULT_SYSROOT_PROFILE)
.join("deps");

According to the Cargo docs

Cargo also creates several other directories and files needed for the build process. Their layout is considered internal to Cargo, and is subject to change. Some of these directories are:

target/debug/deps/

With rust-lang/cargo#14125 (docs), users will be allowed to move deps and many other directories out of target-dir into their `build-dir of choice.

Our expectation is that we will eventually change the default location of build-dir from target-dir to {cargo-cache-home}/build/{workspace-path-hash}.

@RalfJung
Copy link
Owner

RalfJung commented May 6, 2025

Thanks for bringing this up!

We need some way to identify where the build results (including all the rlibs for the dependencies) have been put so that we can copy them to the sysroot. Is there a "less cursed" way of doing that? We don't have to support arbitrary user's choice; we set up our own little workspace for the build anyway so we can configure that to place the build results in a particular location.

Would it be enough to just set CARGO_BUILD_BUILD_DIR to a fixed value?

@epage
Copy link
Author

epage commented May 6, 2025

Providing your own CARGO_BUILD_BUILD_DIR would ensure you don't rely on the users or the systems.

This is also prep work for reorganizing the content within the build directory (rust-lang/cargo#15010).

We need some way to identify where the build results (including all the rlibs for the dependencies) have been put so that we can copy them to the sysroot.

Unsure how officially this is supported but if you specify all packages, including dependencies, with --package, then their rlibs will be uplifted into the target-dir.

@RalfJung
Copy link
Owner

RalfJung commented May 6, 2025

Unsure how officially this is supported but if you specify all packages, including dependencies, with --package, then their rlibs will be uplifted into the target-dir.

We can't hard-code the dependencies of std, so that's not going to work.

rustc bootstrap (./x) must have a similar problem when it prepares the sysroot, but I don't know what they are doing. I assume this is currently equally broken by setting build-dir.

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

2 participants