Importing C macro constants: Proof of concept


#1

Hi, I’ve written a rustc plugin that imports C macro constants from C headers directly from the source code.

Example usage:

#![feature(plugin, custom_attribute)]
#![plugin(c_import)]


#[c_import(h = "limits.h", INT_MAX)]
mod limits
{
    // This module is empty now, but the plugin will import
    // requested constants in here at compile time.
}

fn main()
{
    println!("Yay, got INT_MAX: {}", limits::INT_MAX);
}

Details in blog:

http://vojtech.kral.hk/en/rust-importing-c-constants-proof-of-concept/


#2

If there are Windows users out there wlling to test this I’d be delighted to hear whether it works there :smile:


#3

This looks cool!