-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support linking Rust into C++ as rlibs #14215
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
Comments
See also: rust-lang/rust#111594 (comment) |
This would be a solution to #8828, but it's also desirable and kind of necessary to be able to link dylibs to c++, not just cdylibs. |
One possibility could be to add a Separate from this is the question of how to do
Furthermore, staticlibs and
More information: |
Strongly agreed. I think you're absolutely correct on this; the staticlib targets are primarily busted for having libstd in them. Though another thing that's desirable is being able to link rust dylibs directly into c++ without an intermediary cdylib crate, since the rust symbols are expected to be used by other crates so they need to be in a rust abi target (so if you're following the "rules" you need 1 dylib, 1 cdylib, 1 c++ shared_library), but the crate also needs to export symbols to c++. The most ideal thing for my use case is actually if we could produce c++ targets which are rust dylib targets from the perspective of rustc: they can export both c++ and rust symbols to downstream dylib/rlib crates and c++ libs and can link internally between their c++ and rust code. Then if you build them in static mode, they can export rust symbols as if as an rlib as well, ideally. This may be overly optimistic and maybe I will get my unicorn instead; perhaps what I would have to do for that is turn the c++ target into a staticlib shoved into a rust abi target that's either dynamic or static depending on overall build mode, but we still would need the ability for meson to link rust abi targets directly into c++. There may need to be some adjustment of how the libstd itself is distributed so it is not part of the main rustc package outputs: rust-lang/rust#136373 |
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as mesonbuild#8828 and mesonbuild#14215. Signed-off-by: Paolo Bonzini <[email protected]>
Yes, this is unsupported, but it is effectively critical for usable linking to Rust targets in C++ static libs without substantial pain since without the ability to link rlibs, you cannot combine C++ targets arbitrarily anymore if there is any rust in-tree. One of the unintended consequences of #11722 is that it prevents linking rlibs into C++ targets.
Specifically, you cannot combine two
static_library
C++ targets together if they depend on ruststaticlib
crates due to duplicate copies oflibstd
or other crates. The linking oflibstd
and other stuff from the sysroot must be deferred to the end at the time of linking the executable.There's a few documented hacks at rust-lang/rust#73632 and bazel/buck2
rules_rust
implement rust linking of staticlibs via these methods.The following is possible but it still needs to correctly generate the link args to link to libstd and the sysroot as a whole, which is not yet a thing.
The text was updated successfully, but these errors were encountered: