Closed luketpeterson closed 1 year ago
This seems to be https://github.com/dtolnay/inventory/issues/52
(safer-ffi
uses inventory
under the hood to handle the list/collection of #[ffi_export]
ed items for which to generate headers; the following static
is probably being removed by the linker):
#[used]
#[doc(hidden)]
#[link_section = "__DATA,__mod_init_func"]
static __init6873130405561783045___rust_ctor___ctor
inventory
outputFrom that issue, and https://github.com/dtolnay/inventory/pull/57/files, it is mentioned that using codegen-units = 1
, at least when on macOS, may work around the issue. I've tested just that, and it seems to work:
# On macOS
CARGO_PROFILE_DEV_CODEGEN_UNITS=1 cargo r --features=headers
or:
# Cargo.toml
[profile.dev]
codegen-units = 1
Alas, I don't know of a reliable way to handle this; in order for the header generation of #[ffi_export]
to work, a way to globally collect header generation snippets is necessary, and at the moment, there are only two crates that offer this: ::inventory
and ::linkme
, and both rely on linker shenanigans, which can be brittle to certain linkers agressively removing stuff. It's thus kind of beyond my capacity to properly fix this 😔
So I'll have to close this issue, but feel free to post any further questions you may have, or ideas related to this 🙂
Check the attachments for a complete reproduction Cargo project.
I have a lib.rs file that re-exports some crate modules. Like this:
Within the exported mod (my_mod.rs), I have an item called
tokenizer
, which does not end up in the generated header, in spite of it being#[ffi_export]
. This is my primary complaint.However, the plot thickens because, if I then uncomment
useless_enum
from the same file, both items are now included in the generated header.Here is a complete repro case, just as described. It follows the same structure as the QuickStart example, so you can generate the header by running:
safer_ffi_bug_regression.zip
Thank you