Skip to content

Emit separate headers for each sub-crate #48

Description

@nickpdemarco

With #43 merged, the likelihood of creating massive generated.h files increases exponentially. We should have support for splitting generated.h into multiple headers.

At first glance, I'd suggest creating a header for each crate that contributed symbols to the ZngurSpec. This is easier said than done, since symbols (particularly from std) can be "re-opened" in different zngur files, and we'd expect each zng file that re-opened the symbol to have its FFI code in the crate's generated header.

I think that implies we need to track which .zng files mention which symbols, and then create a header for each set of headers which mention common symbols. That internal, "shared" header would then be included by each individual header to create the desired effect.

// a.zng
mod ::std {
    type option::Option<i32> {
        #layout(size = 8, align = 4);

        constructor None;
        constructor Some(i32);
    }
}

type Box<dyn Fn(i32) -> i32> {
    #layout(size = 8, align = 4);
}
// b.zng
mod ::std {
    type option::Option<i32> {
        #layout(size = 8, align = 4);
        fn unwrap(self) -> i32;
    }

    mod vec {
        type Vec {...}
    }
}
// internal/generated/ab.h (not exposed to users)
// Insert `option::Option FFI` here
// generated/a.h (exposed to users)
#include <internal/generated/ab.h>
// Insert `Box<dyn Fn(i32) -> i32>` FFI here
// generated/b.h (exposed to users)
#include <internal/generated/ab.h>
// Insert `Vec` FFI here

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions