-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Added self-linking support to sys mode #1207
base: main
Are you sure you want to change the base?
Conversation
Do you have an example project where this is useful? |
We use Marco's patch in our project at work. The use case is the one Marco described, we have library we are incrementally porting to rust and we want to bind some of its API since the parts that we are migrating to rust need to call into the C part, however we want to keep generating a single .so/.dll. |
Yeah I meant something public that we can link to for others to understand how this can be used :) |
cf8039b
to
c6d5e91
Compare
book/src/config_ffi.md
Outdated
@@ -35,6 +35,13 @@ work_mode = "sys" | |||
# and build.rs that generated only if not exists. | |||
# Defaults to false | |||
split_build_rs = false | |||
# If true, then build.rs and tests do not get generated, and | |||
# no #[link] attribute is emitted. This is supposed to be used | |||
# when a library consists of an hybrid of C and Rust code, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# when a library consists of an hybrid of C and Rust code, and | |
# when a library consists of a hybrid of C and Rust code, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! Thanks
This sounds very similar to what I did for |
I'll try to resurrect this and provide the example, sorry for the huge delay. |
c6d5e91
to
094b8ba
Compare
The purpose of this is to support a scenario where a single module is half implemented in C and half implemented in Rust (statically linked, resolving circular dependencies at the linker level).
This, while not ideal, is a likely possibility for a codebase which is in the process of migrating from C to Rust. (Note: caveats apply to the execution of
cargo test
, but a stub can be linked in that case to allow unit tests to run).In this scenario, the sys bindings are generated correctly, but with a few caveats that need to be corrected:
#[link(...)]
attribute should not be emitted as there is no external library to link with... yet (the linker is linking everything in that precise moment)build.rs
should not be generated for the same reasontests/
directory does no harm, but is superflous at that pointThis adds a
self_linking
configuration key to thesys
work mode that would skip the above parts, in order to support the self linking scenario I depicted without having to resort to post modification of the generated code.I'm not sure if this fits the intended purpose of the gir tool, but I think it can be possibly useful to others.