Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generating a dummy dynamic-loading-like struct when not using libloading #3259

Open
@marcin-serwin

Description

Some crates have the ability to decide whether the shared object file will be dlopened or linked into the executable. For example, ash-rs exposes Entry::linked() and Entry::load() depending whether features linked or loaded were enabled. Achieving this with bindgen is currently possible but the exported symbols have different API which requires using conditional compilation whenever a function from the library is called, e.g.,

impl Foo {
 #[cfg(feature = "linked")]
 pub fn linked() -> Self {
 Self {}
 }
 #[cfg(feature = "loaded")]
 pub fn loaded() -> Self {
 Self {
 lib: FooLib::new("libfoo.so").unwrap(),
 }
 }
 pub fn mk_bar_wrapped(&self) {
 #[cfg(feature = "linked")]
 mk_bar();
 #[cfg(feature = "loaded")]
 self.lib.mk_bar();
 }
}

It would be if it were possible to emit a dummy FooLib struct with impl that ignores self and calls the exported function from the linked binary, something like:

impl FooLib {
 pub fn dummy() -> Self {
 Self { _unused: [] }
 }
 pub fn mk_bar(&self) {
 mk_bar()
 }
}

This way the mk_bar_wrapped implementation could be simplified to always call the mk_bar fn through the self.lib object regardless of whether libfoo is loaded or linked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /