Adding a dependency to Rust libstd

I want to add a new dependency to libstd in the Rust compiler. I am trying what is mentioned in Adding a new crate to libstd dependency, but I cannot make it work. Please let me know if you see where I am doing something wrong.

I want to add another crate my-crate to Rust compiler's libstd like:

my-crate = { path = "../../../my-crate" }

https://github.com/rust-lang/rust/blob/971a3f15f02752017e4d067acc01d3793dc72c40/library/std/Cargo.toml#L25

I understand for my-crate to work here, I need to make core a dependency of my-crate. So I add this in my-crate/Cargo.toml which I got from https://github.com/rust-lang/rust/tree/master/library/rustc-std-workspace-core :

[package]
name = "my-crate"
...
edition = "2018"

...

[dependencies]
core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core' }

However, building the compiler with libstd gives me the same error as before:

./x.py build -i --stage=1 --target=a-new-crosscompiling-target
Updating only changed submodules
Submodules updated in 0.02 seconds
    Finished dev [unoptimized] target(s) in 0.22s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling my-crate v19.0.0 (/home/utsav/Desktop/my-crate)
error[E0463]: can't find crate for `core`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `my-crate`.

This should probably be posted on internals.rust-lang.org. Why do you need to add a new dependency, though?

I did not know about that forum! Thanks, I posted my question there.

I am adding another target OS to the Rust compiler for my use, and since it is not intended to go to the official Rust compiler it is OK for me to add a dependency to libstd.

Found cfg-if to be a good example to follow.

I needed to have this in my-crate/Cargo.toml .

[dependencies]
core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core' }
compiler_builtins = { version = "0.1.16", optional = true }

[features]
rustc-dep-of-std = ['core', 'compiler_builtins']

And then in libstd/Cargo.toml , I could do:

[dependencies]
my-crate = { git = "...", features = ['rustc-dep-of-std'] }

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.