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

Best approaches to support docsrs mode in user code #1469

Open
nyurik opened this issue Mar 13, 2025 · 0 comments
Open

Best approaches to support docsrs mode in user code #1469

nyurik opened this issue Mar 13, 2025 · 0 comments

Comments

@nyurik
Copy link
Contributor

nyurik commented Mar 13, 2025

My crate needs to generate the docs.rs documentation despite the fairly involved compilation with the native bindings, which cannot easily happen inside the docsrs docker constraints.

If my cxx bridge includes some header files and types, would it be possible to somehow generate special shims for the native stuff, possibly with a custom attribute, to let cxx simplify the docsrs generation?

#[cxx::bridge(namespace = "mln::bridge")]
pub mod ffi {
    // This should be part of the docs
    #[repr(u32)]
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    enum MapMode {
        Continuous,
        Static,
        Tile,
    }

    unsafe extern "C++" {
        // include! requires git clone of a large library, downloads, etc,
        // and should be avoided in docsrs
        #[cfg(not(docsrs))]  // <-- this should skip including external file, while passing all the other parts
        include!("map_renderer.h");

        // This is an error in docsrs because the type is defined in the header file
        // It needs some fake shim instead
        type MapRenderer;

        fn MapRenderer_new(mapMode: MapMode) -> UniquePtr<MapRenderer>;
    }
}
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

1 participant