Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit f083260

Browse files
authored
Version C header (#105)
1 parent 6c10d91 commit f083260

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

token/build.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,45 @@ use std::env;
44

55
fn main() {
66
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
7-
cbindgen::generate(&crate_dir)
7+
let config = cbindgen::Config {
8+
header: Some("/* Autogenerated SPL Token program C Bindings */".to_string()),
9+
after_includes: Some(format!(
10+
"{}{}{}",
11+
format!(
12+
"\n#define TOKEN_MAJOR_VERSION {}",
13+
env!("CARGO_PKG_VERSION_MAJOR")
14+
),
15+
format!(
16+
"\n#define TOKEN_MINOR_VERSION {}",
17+
env!("CARGO_PKG_VERSION_MINOR")
18+
),
19+
format!(
20+
"\n#define TOKEN_PATCH_VERSION {}",
21+
env!("CARGO_PKG_VERSION_PATCH")
22+
)
23+
)),
24+
language: cbindgen::Language::C,
25+
line_length: 80,
26+
style: cbindgen::Style::Both,
27+
tab_width: 4,
28+
cpp_compat: true,
29+
pragma_once: true,
30+
export: cbindgen::ExportConfig {
31+
prefix: Some("Token_".to_string()),
32+
include: vec!["TokenInstruction".to_string(), "State".to_string()],
33+
..cbindgen::ExportConfig::default()
34+
},
35+
parse: cbindgen::ParseConfig {
36+
parse_deps: true,
37+
include: Some(vec!["solana-sdk".to_string()]),
38+
..cbindgen::ParseConfig::default()
39+
},
40+
..cbindgen::Config::default()
41+
};
42+
cbindgen::Builder::new()
43+
.with_crate(crate_dir)
44+
.with_config(config)
45+
.generate()
846
.unwrap()
947
.write_to_file("inc/token.h");
1048
}

token/inc/token.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <stdint.h>
88
#include <stdlib.h>
99

10+
#define TOKEN_MAJOR_VERSION 0
11+
#define TOKEN_MINOR_VERSION 1
12+
#define TOKEN_PATCH_VERSION 0
13+
1014
/**
1115
* Maximum number of multisignature signers (max N)
1216
*/

0 commit comments

Comments
 (0)