-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
60 lines (50 loc) · 1.95 KB
/
build.rs
File metadata and controls
60 lines (50 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
extern crate cbindgen;
use std::env;
use std::fs;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::BufWriter;
use std::io::Write;
use cbindgen::{Config, Language};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let mut config = Config::default();
config.macro_expansion.bitflags = true; // We use bitflags in physis
cbindgen::Builder::new()
.with_config(config.clone())
.with_crate(crate_dir.as_str())
.with_parse_deps(true)
.with_parse_include(&["physis"])
.with_language(Language::C)
.generate()
.expect("Unable to generate C bindings")
.write_to_file("target/public/physis.h");
cbindgen::Builder::new()
.with_config(config.clone())
.with_crate(crate_dir.as_str())
.with_parse_deps(true)
.with_parse_include(&["physis"])
.with_language(Language::Cxx)
.with_pragma_once(true)
.generate()
.expect("Unable to generate C++ bindings")
.write_to_file("target/public/physis.hpp");
// cbindgen always includes <ostream> and <new> even if they aren't used
// some downstream projects like PhysisSharp need to have a cleaner file
{
let file: File = File::open("target/public/physis.hpp").unwrap();
let out_file: File = File::create("target/public/physis.hpp.temp").unwrap();
let reader = BufReader::new(&file);
let mut writer = BufWriter::new(&out_file);
for line in reader.lines() {
let line = line.as_ref().unwrap();
if !line.contains("#include <ostream>") && !line.contains("#include <new>") {
writeln!(writer, "{}", line).expect("Failed to replace include");
}
}
}
fs::rename("target/public/physis.hpp.temp", "target/public/physis.hpp").unwrap();
}