Add an example for using a build script
This commit is contained in:
parent
cedd1b3cc2
commit
e76b25701d
8
examples/build-script/Cargo.toml
Normal file
8
examples/build-script/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "build-script"
|
||||
version = "0.1.0"
|
||||
authors = ["Ryan Hunt <rhunt@eqrion.net>"]
|
||||
build = "build.rs"
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = { path = "../../" }
|
11
examples/build-script/build.rs
Normal file
11
examples/build-script/build.rs
Normal file
@ -0,0 +1,11 @@
|
||||
extern crate cbindgen;
|
||||
|
||||
use cbindgen::{Config, Library};
|
||||
|
||||
fn main() {
|
||||
let config = Config::default();
|
||||
|
||||
Library::load("../build-script", &config)
|
||||
.build(&config).unwrap()
|
||||
.write_to_file(&config, "bindings.h");
|
||||
}
|
19
examples/build-script/src/lib.rs
Normal file
19
examples/build-script/src/lib.rs
Normal file
@ -0,0 +1,19 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
pub struct Opaque {
|
||||
x: i32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Normal {
|
||||
x: i32,
|
||||
y: f32,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(x: *mut Opaque, y: Normal)
|
||||
{
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
use std::io::Write;
|
||||
use std::collections::BTreeMap;
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::File;
|
||||
|
||||
use syn::*;
|
||||
|
||||
@ -327,6 +328,11 @@ impl BuiltLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_to_file(&self, config: &Config, path: &str) {
|
||||
self.write(&config,
|
||||
&mut File::create(path).unwrap());
|
||||
}
|
||||
|
||||
pub fn write<F: Write>(&self, config: &Config, out: &mut F) {
|
||||
if let Some(ref f) = config.file_header {
|
||||
write!(out, "{}\n", f).unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user