How rust get rand crate in building?

In building rust, I see there are two version of rand have been downloaded into my CARGO_HOME directory, one is 0.6.1, one is 0.7.0. I aslo see the layout of the souce code is quite differnt than what we can see from https://github.com/rust-random/rand.

So my quesiton is how/where rust fetch the rand crate source code? In other word, if I want to add something to rand and build it with rust, how should I setup my work environment so the rust could use my local rand copy?

Thanks, Baoshan

You probably want either path dependencies: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies or a patch section https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section.

Also, this question sounds like it might be a better fit for the neighboring users forum: https://users.rust-lang.org/ :slight_smile:

NOTE: This internals forum is for discussion of problems with, or proposed enhancements to, the rustc compiler and other related tools.

@matklad @Tom-Phinney

Sorry if I didn't say it more clearly, I am talking about the problem what I have seen in building rust from source because I am trying to port rust for a OS. Shouldn't such question be posted here?

You can use a [patch] section as @matklad mentioned in rust's own Cargo.toml. Given the mix of rand versions though, you might need to use corresponding versions in a [replace] section instead.

As for the rand repo, note that it's a workspace of all of the rand crates, whereas you'll have fetched them individually from crates.io when building rust. You may have to dig in the history and branches to find the published versions you want to modify.

@cuviper

Thanks a lot for your help.

After I adding this to the end of Cargo.toml which is in the top directory of rust source code:

+
+[replace]
+"rand:0.6.1" = { path = '../rand_061' }
+"rand:0.7.0" = { path = '../rand_070' }

I get this error:

Updating only changed submodules
Submodules updated in 0.02 seconds
error: failed to parse manifest at `/home/bpang/rust_rand/rust/Cargo.toml`

Caused by:
  cannot specify both [replace] and [patch]

Any idea how to fix it?

Thanks, Baoshan

@cuviper @matklad

Thanks for the useful informain.

I get what I need by adding this in Cargo.toml in section [patch.crates-io]:

rand = { git = 'https://github.com/BaoshanPang/rand.git', branch = 'vxworks_061' }

The rust would get all rand crates from my private branch .

It seems rand 0.7.0 is not really used(at least when building libstd unit test) although it has been downloaded.

Glad that it helps! And yeah, questions about building rust compiler itself are definitely a good fit for this forum, sorry for misreading your question!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.