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

Does not collect plugins defined outside of crate root #9

Closed
phrohdoh opened this issue Apr 17, 2019 · 4 comments
Closed

Does not collect plugins defined outside of crate root #9

phrohdoh opened this issue Apr 17, 2019 · 4 comments

Comments

@phrohdoh
Copy link

Using:

  • inventory version 0.1.3 (have ^0.1 defined in my manifest)
  • rustc 1.34.0-nightly (b139669f3 2019-02-06)
  • cargo 1.34.0-nightly (4e74e2fc0 2019-02-02)

main.rs

pub mod commands; // added `pub` to see if that would change anything, but it didn't

pub struct Command {
    name: &'static str,
}

impl Command {
    pub fn new(name: &'static str) -> Self {
        Self {
            name,
        }
    }
}

inventory::collect!(Command);

// I tested moving the `mod` to here, after the `collect!`, but no dice

inventory::submit! {
    Command::new("barf")
}

fn main() {
    println!("available commands:");

    for cmd in inventory::iter::<Command> {
        println!("  {}", cmd.name);
    }
}

commands/mod.rs

inventory::submit! {
    crate::Command::new("parse")
}

Output is as follows:

available commands:
  barf
@mathstuf
Copy link
Contributor

Hmm. I'm not having issues with my usage of inventory where I definitely register far out of the crate root. If you have other code (say, a function) in commands/mod.rs does it work? If that doesn't work, what if you call that function before iterating?

@caelunshun
Copy link

caelunshun commented Mar 16, 2020

I'm having a similar issue where plugins are only registered if the module they are submitted in has publicly-exposed functions. Is there a fix for this?

(If it's important, I'm running this on Ubuntu. I haven't tried anything yet on Windows.)

@mathstuf
Copy link
Contributor

That may be a limitation of the linker model. I know at least on Mach-O (macOS), statics are not guaranteed to be initialized before a symbol from the object they live in is needed (this affects static builds in particular). Maybe ELF has a similar mode, but it isn't being used here? Feels like more of an LLVM codegen thing to me though.

@dtolnay
Copy link
Owner

dtolnay commented Jun 30, 2022

This is fixed in rustc 1.62.0 / inventory 0.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants