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

Provide access to a preprocessor #503

Open
kulp opened this issue May 22, 2020 · 0 comments
Open

Provide access to a preprocessor #503

kulp opened this issue May 22, 2020 · 0 comments

Comments

@kulp
Copy link
Member

kulp commented May 22, 2020

Proposal

I propose that Tool provide a way like to_command to invoke a C preprocessor.

I am not sure whether this is feasible.

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).

During build.rs in lightning-sys I want to find function-like macros like these :

#define jit_addi_d(u,v,w)   jit_new_node_wwd(jit_code_addi_d,u,v,w)
#define jit_beqi_d(v,w)     jit_new_node_pwd(jit_code_beqi_d,NULL,v,w)

so that the build step can generate Rust macros like these :

jit_entry!( jit_addi_d(u,v,w) => add => [ i, d ] => jit_new_node_wwd(jit_code_addi_d,u,v,w)    )
jit_entry!( jit_beqi_d(v,w)   => beq => [ i, d ] => jit_new_node_pwd(jit_code_beqi_d,NULL,v,w) )

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, I would have a solution.

I recognize that this request does not fit into the stated purpose of the crate :

The purpose of this crate is to provide the utility functions necessary to compile C code into a static archive which is then linked into a Rust crate.

so if this is out of scope for this crate, then I understand.

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