rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
137 stars 8 forks source link

Custom source standard library #7

Open ehuss opened 5 years ago

ehuss commented 5 years ago

This issue is for tracking the possibility of using custom source for the standard library.

It should be acknowledged that this is unlikely to be on a path to be stabilized for the foreseeable future.

crlf0710 commented 5 years ago

In my mind it would be better to just to enable the user to supply prebuilt-binary for every crate in the dependency graph using some Cargo.toml syntax.

This will solve this use case automatically. But it's worth a separate topic alone, and absolutely doesn't beyond to the MVP.

plauche commented 4 years ago

Is this feature still pretty far out on the road map? I was looking at transitioning away from xargo but the ability to build std from custom source is a must for me at the moment.

Ericson2314 commented 3 years ago

So we want to fetch the source in a distro context, so rustup isn't appropriate. It's fine for us if it's quite unstable, but I would be nice if there was an escape hatch in Cargo.

CC @kloenk

RalfJung commented 2 years ago

Miri needs to do its own sysroot build, which it currently does via xargo -- but using -Zbuild-std would be nicer, of course.

However, this issue is one (not the only) blocker on that road: Miri currently supports the MIRI_LIB_SRC env var to configure where to get the sources for the sysroot build from, and that feature is useful often enough that I'd rather not lose it.

Ericson2314 commented 2 years ago

https://github.com/kolloch/crate2nix/ is project I've given cross support and enough stuff to replicate -Z build-std with equivalent hacks. We an substitute custom stdlib sources in just fine.

My point in bringing this up is that it should be really easy to get this feature for free once the implementation isn't extremely rigid mixing mechanism and policy.

est31 commented 1 year ago

cc also https://github.com/rust-lang/rust/issues/101691 which is about making it possible to just compile the standard library in rustc and then using rustup toolchain link.

vadixidav commented 1 year ago

In my case I am using msp430 and the linker provides builtins for the hardware multiplier. See https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/msp430/lib2hw_mul.S for relevant code. I want to submit a PR to compiler_builtins to remedy the situation, mostly by making it not generate duplicate symbols for this architecture, but it looks like I need to build the whole toolchain from scratch, which is a bit prohibitive. It would be really nice to be able to swap out the compiler_builtins.

bjorn3 commented 1 year ago

If the project with which you want to test it only depends on libcore and not liballoc, I think you can use -Zbuild-std=core and then add the version of compiler_builtins you want to test as regular dependency to Cargo.toml and maybe add a use compiler_builtins;.

vadixidav commented 1 year ago

If the project with which you want to test it only depends on libcore and not liballoc, I think you can use -Zbuild-std=core and then add the version of compiler_builtins you want to test as regular dependency to Cargo.toml and maybe add a use compiler_builtins;.

I tried this, but it still complains about duplicate compiler_builtins rlib.

evanrichter commented 1 year ago

I believe I found a suitable, though unstable escape hatch

Set the __CARGO_TESTS_ONLY_SRC_ROOT environment variable when you do -Zbuild-std and cargo will use the specified path to the custom source

TDecking commented 1 year ago

`__CARGO_TESTS_ONLY_SRC_ROOT´ unfortunatly does not work. It allows for building, but not for linking.

evanrichter commented 1 year ago

hmm, that might be correct for dynamic linking, I haven't verified. but it certainly works with RUSTFLAGS="-C target-feature=+crt-static" and musl targets

TDecking commented 1 year ago

So, I've managed do diagnose my case.

In my case, I only made changes to core, and I passed -Z build-std=core as additional flags. However, my program used std, which was not specified as a component. Which meant that the original standard library was linked. Passing -Z build-std=std,core instead fixed things.

This is likely going to trip up a lot more users.

dullbananas commented 1 year ago

Here's a workaround for experimenting with changes to std