-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Error cargo build
ing std
as a dylib
#36501
Comments
Looks good to me! (I hope once make is gone we can put things in their normal locations and the entire IIUC, we eventually want cargo to be smart enough to build deps (and later still, only public deps) as dylibs. This would be the decision of the bottom crate / builder not any library, so hacking rustbuild for now is a step in the right direction. All these changes anticipate what I want to do once my RFC is merged, so keep 'em coming! |
For this specific error, I wonder if perhaps a more targeted fix would suffice? It looks like it's because jemalloc isn't compiled which the the target the standard library is being compiled for assumes will exist. Basically, on this line, we'd link This does have interesting implications, though, for jemalloc. Does mean that building std in a custom fashion is a bit harder. |
mmm, how's that better? Custom |
The problem is that when the compiler builds a dylib it attempts to link the default dylib allocator. For many targets that's jemalloc, but jemalloc isn't compiled unless you enable a feature. |
(Alternatively, we could default to system alloc everywhere. Less C is always good in my book) |
The "default dylib allocator" stuff is just a stopgap until we get general needs-provides, so I wouldn't sweat it. |
@japaric eventually hopefully! |
I read this and was confused, so to elaborate for other readers - dylibs are partitioned into 'dylibs used as rust dependencies' and 'other dylibs'. The former (the definition being encountered here) use the same allocator as the current rust compiler will give to executables, typically jemalloc. The latter is basically always the system allocator. See rust/src/librustc_metadata/creader.rs Line 822 in ff591b6
|
Oh, and (again, just for the record) I think the issue here is relatively easily solved if your |
I think this is likely fixed with jemalloc now removed in #55238 so closing |
Or should
cargo build
ingstd
only produce a .rlib?Now that #35021 landed and compiler-rt intrinsics are built as part of the std crate dependencies,
one can (cross) compile binaries if the
alloc_system
(oralloc_jemalloc
),panic_unwind
andstd
crates are listed under the crate Cargo.toml:if and only if the Cargo.toml of the std crate is modified as follows
[lib] name = "std" path = "lib.rs" -crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../liballoc" }
to not build a dylib. Without this change
cargo build
inghello
fails with:during the compilation of the
std
crate. (On that note, I'm sure why buildingstd
as a dylibfails? Is it because rustc injects a
extern crate alloc_jemalloc
intostd
source when compilinga dylib but alloc_jemalloc is an optional dependency of
std
that's not build (the feature isdisabled) in this example?)
I discussed this with @alexcrichton and we were wondering if we should modify the std crate to only
compile the rlib to make this case work out of the box. And then hack
bootstrap
to force it to buildstd
as dylib because it is needed to link rustc.cc @Ericson2314 I don't how/if this change would affect your Cargo+std RFC. (Probably not?)
The text was updated successfully, but these errors were encountered: