diff --git a/token/build.rs b/token/build.rs index c0aa47eb071..ea158025ef5 100644 --- a/token/build.rs +++ b/token/build.rs @@ -4,7 +4,45 @@ use std::env; fn main() { let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - cbindgen::generate(&crate_dir) + let config = cbindgen::Config { + header: Some("/* Autogenerated SPL Token program C Bindings */".to_string()), + after_includes: Some(format!( + "{}{}{}", + format!( + "\n#define TOKEN_MAJOR_VERSION {}", + env!("CARGO_PKG_VERSION_MAJOR") + ), + format!( + "\n#define TOKEN_MINOR_VERSION {}", + env!("CARGO_PKG_VERSION_MINOR") + ), + format!( + "\n#define TOKEN_PATCH_VERSION {}", + env!("CARGO_PKG_VERSION_PATCH") + ) + )), + language: cbindgen::Language::C, + line_length: 80, + style: cbindgen::Style::Both, + tab_width: 4, + cpp_compat: true, + pragma_once: true, + export: cbindgen::ExportConfig { + prefix: Some("Token_".to_string()), + include: vec!["TokenInstruction".to_string(), "State".to_string()], + ..cbindgen::ExportConfig::default() + }, + parse: cbindgen::ParseConfig { + parse_deps: true, + include: Some(vec!["solana-sdk".to_string()]), + ..cbindgen::ParseConfig::default() + }, + ..cbindgen::Config::default() + }; + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_config(config) + .generate() .unwrap() .write_to_file("inc/token.h"); } diff --git a/token/inc/token.h b/token/inc/token.h index 4d38e593a90..b9eef7e39e1 100644 --- a/token/inc/token.h +++ b/token/inc/token.h @@ -7,6 +7,10 @@ #include #include +#define TOKEN_MAJOR_VERSION 0 +#define TOKEN_MINOR_VERSION 1 +#define TOKEN_PATCH_VERSION 0 + /** * Maximum number of multisignature signers (max N) */