-
Notifications
You must be signed in to change notification settings - Fork 707
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
Proposal: ParseCallbacks::func_macro #1792
Comments
I think it's fair to expose this given the precedents. I don't think we should expose I think I'd take an API with those constraints as long as the implementation is not too insane, it's well documented, and has tests. |
@emilio I personally would be happiest with exposing one // Given :
// #define jit_addi_d(u,v,w) jit_new_node_wwd(jit_code_addi_d,u,v,w)
// then this `func_macro` does not panic :
fn func_macro(&self, left: &str, right: &str) {
assert_eq!( left, "jit_addi_d(u,v,w)" );
assert_eq!( right, "jit_new_node_wwd(jit_code_addi_d,u,v,w)" );
} If by "whole source range" you mean this : // Given :
// #define jit_addi_d(u,v,w) jit_new_node_wwd(jit_code_addi_d,u,v,w)
// then this `func_macro` does not panic :
fn func_macro(&self, whole: &str) {
assert_eq!( whole, "jit_addi_d(u,v,w) jit_new_node_wwd(jit_code_addi_d,u,v,w)" );
} then I think that would be all right too. I will look into both ways. I am looking into this today to see if it is as straightforward as I hope it is. |
Background
In the
bindgen::callbacks::ParseCallbacks
trait there exist already the following methods :and the documentation of
str_macro
says :Proposal
I propose a
func_macro
callback for functional macros. Its signature might be something like one of the following :It would have the same purpose as
str_macro
: to "generate additional code or configuration."I would like to work on this functionality myself, if the proposal can be made acceptable.
Use case
GNU lightning is a portable C library for JIT compilation. It is wrapped by the
lightning-sys
crate. Most all of GNU lightning's API is provided by function-like macros. Some of the macros' definitions and/or existence depend on the target-architecture-specific#if
branches (the API is slightly different on 64-bit architectures from on 32-bit architectures).I would like to be able to use
ParseCallbacks
duringbuild.rs
inlightning-sys
to find function-like macros like these :so that the build step can generate Rust macros like these :
which can then generate Rust entry points in a less manual and error-prone way than is currently used. I can already generate these Rust macros from a manually-preprocessed C header file, but I need some portable mechanism for determining which macros to generate and with what expansions. If
cc
provided access to a preprocessor (rust-lang/cc-rs#503) I could use that instead, although not quite as nicely as inbindgen
.I believe this request is different from #753 because my use case does not require evaluation of the functional macros, nor even full parsing of them. My own use case requires only the textual content of the name and value, although a tokenization would be fine as well.
bindgen
's scope ?The text was updated successfully, but these errors were encountered: