Skip to content
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

Providing the compiler crates as rlib? #55741

Open
swiftcoder opened this issue Nov 7, 2018 · 5 comments
Open

Providing the compiler crates as rlib? #55741

swiftcoder opened this issue Nov 7, 2018 · 5 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@swiftcoder
Copy link

I'd like to embed rustc_driver in a static library (for complicated embedded deployment reasons that aren't entirely relevant). Dependencies of a static library seem to have to be in rlib format so the compile can read metadata.

Unfortunately, most of the compiler crates are only building dylibs, causing cargo to refuse to build a staticlib:

error: crate `rustc_driver` required to be available in rlib format, but was not found in this form
error: crate `arena` required to be available in rlib format, but was not found in this form
error: crate `rustc_data_structures` required to be available in rlib format, but was not found in this form
error: crate `graphviz` required to be available in rlib format, but was not found in this form
error: crate `rustc_cratesio_shim` required to be available in rlib format, but was not found in this for
error: crate `rustc` required to be available in rlib format, but was not found in this form
error: crate `fmt_macros` required to be available in rlib format, but was not found in this form
error: crate `rustc_target` required to be available in rlib format, but was not found in this form
error: crate `rustc_errors` required to be available in rlib format, but was not found in this form
error: crate `syntax_pos` required to be available in rlib format, but was not found in this form
error: crate `syntax` required to be available in rlib format, but was not found in this form
error: crate `proc_macro` required to be available in rlib format, but was not found in this form
error: crate `rustc_fs_util` required to be available in rlib format, but was not found in this form
error: crate `rustc_allocator` required to be available in rlib format, but was not found in this form
error: crate `rustc_borrowck` required to be available in rlib format, but was not found in this form
error: crate `rustc_mir` required to be available in rlib format, but was not found in this form
error: crate `rustc_passes` required to be available in rlib format, but was not found in this form
error: crate `rustc_lint` required to be available in rlib format, but was not found in this form
error: crate `rustc_plugin` required to be available in rlib format, but was not found in this form
error: crate `rustc_metadata` required to be available in rlib format, but was not found in this form
error: crate `syntax_ext` required to be available in rlib format, but was not found in this form
error: crate `rustc_privacy` required to be available in rlib format, but was not found in this form
error: crate `rustc_typeck` required to be available in rlib format, but was not found in this form
error: crate `rustc_platform_intrinsics` required to be available in rlib format, but was not found in this form
error: crate `rustc_incremental` required to be available in rlib format, but was not found in this form
error: crate `rustc_resolve` required to be available in rlib format, but was not found in this form
error: crate `rustc_save_analysis` required to be available in rlib format, but was not found in this form
error: crate `rustc_codegen_utils` required to be available in rlib format, but was not found in this form
error: crate `rustc_traits` required to be available in rlib format, but was not found in this form

error: aborting due to 29 previous errors

Is there a technical reason why these are all only built as dylib, or is this just because no one has thus far needed to embed them in a staticlib? Would it be a reasonable ask to configure these projects to build both flavours?

@Centril
Copy link
Contributor

Centril commented Aug 6, 2019

@Zoxc is this fixed now given the move away from dylibs?

@mati865
Copy link
Contributor

mati865 commented Aug 6, 2019

There are still few dylibs left.

@jonas-schievink jonas-schievink added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@bjorn3
Copy link
Member

bjorn3 commented Dec 6, 2020

The only dylib only crates left are rustc_driver and rustc_codegen_cranelift.

https://github.com/rust-lang/rust/search?l=TOML&q=crate-type+%3D+%5B%22dylib%22%5D

rustc_codegen_cranelift must always be built as dylib, as it can't be loaded at runtime otherwise. Making rustc_driver available as rlib will cause many tools to accidentally build against it as static lib, which shouldn't normally happen as it greatly increases the size of the tool executables and prevents runtime loading of codegen backends.

@jyn514
Copy link
Member

jyn514 commented Feb 3, 2023

I'm going to close this, this is not a use case we plan to support. If you need to embed rustc_driver as a static library for whatever reason, you can fork the project and remove crate-type = "dylib":

[lib]
crate-type = ["dylib"]

@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2023
@Zoxc
Copy link
Contributor

Zoxc commented Feb 3, 2023

My PR will allow for this. You won't be able to load codegen backends without further modifications though.

@jyn514 jyn514 reopened this Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants