-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
150 lines (150 loc) · 5.98 KB
/
build.rs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// build.rs
#![allow(
dead_code,
improper_ctypes,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_doc_comments,
unused_imports,
unused_mut
)]
extern crate bindgen;
extern crate cc;
#[macro_use] extern crate cfg_if;
extern crate dotenv;
use std::env;
use std::path::Path;
use std::path::PathBuf;
use std::fs;
use std::io::Write;
use std::process::Command;
fn add_cpp_files(builder: &mut cc::Build, path: &Path) {
for e in path.read_dir().unwrap() {
let e = e.unwrap();
let path = e.path();
if e.file_type().unwrap().is_dir() {
} else if path.extension().and_then(|s| s.to_str()) == Some("cpp") {
builder.file(&path);
}
}
}
fn add_c_files(builder: &mut cc::Build, path: &Path) {
for e in path.read_dir().unwrap() {
let e = e.unwrap();
let path = e.path();
if e.file_type().unwrap().is_dir() {
} else if path.extension().and_then(|s| s.to_str()) == Some("c") {
builder.file(&path);
}
}
}
cfg_if!
{
if #[cfg(unix)] {
fn build() {
// /// Compile C/C++ sources
// let mut builder = cc::Build::new();
// dotenv::dotenv().ok();
// builder.include("./src/include");
// builder.include("./src/include/au");
// builder.include("./compiler");
// builder.flag_if_supported("-B --sysroot");
// // builder.flag_if_supported("-DHAVE_CONFIG_H");
// // builder.flag_if_supported("-DHAVE_POLL");
// // builder.flag_if_supported("-DHAVE_LIBPTHREAD");
// // builder.flag_if_supported("-DENABLE_THREADS");
// // builder.flag_if_supported("-D__PLATFORM_LINUX__");
// // builder.flag_if_supported("-D__LINUX_ALSA__");
// // builder.flag_if_supported("-D__UNIX_JACK__");
// // builder.flag_if_supported("-DUSE_ALSA");
// // builder.flag_if_supported("-DUSE_DLTRICK_ALSA");
// // builder.flag_if_supported("-DUSE_OSS");
// builder.flag_if_supported("-fPIC");
// builder.flag_if_supported("-fno-strict-aliasing");
// builder.flag_if_supported("-fstack-protector-strong");
// builder.flag_if_supported("-fno-plt");
// builder.flag_if_supported("-fpermissive");
// // builder.flag_if_supported("-I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include");
// // builder.flag_if_supported("-I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/c++");
// builder.flag_if_supported("-O3");
// builder.flag_if_supported("-mtune=generic");
// builder.flag_if_supported("-march=native");
// builder.flag_if_supported("-pipe");
// let include_path = Path::new("./src/include");
// add_c_files(&mut builder, include_path);
// builder.cpp(true);
// add_cpp_files(&mut builder, include_path);
// builder.cpp_link_stdlib("stdc++");
// builder.compile("libchuck.so");
let bindings = bindgen::Builder::default()
.generate_inline_functions(true)
.derive_default(true)
.header("./src/include/dsp/llvm-c-dsp.h")
.clang_arg("-B --sysroot")
// .clang_arg("-DHAVE_CONFIG_H")
// .clang_arg("-DHAVE_LIBPTHREAD")
// .clang_arg("-DHAVE_POLL")
// .clang_arg("-DENABLE_THREADS")
// .clang_arg("-D__CK_SNDFILE_NATIVE__")
// .clang_arg("-D__LINUX_ALSA__")
// .clang_arg("-D__PLATFORM_LINUX__")
// .clang_arg("-D__UNIX_JACK__")
// .clang_arg("-DUSE_ALSA")
// .clang_arg("-DUSE_DLTRICK_ALSA")
// .clang_arg("-DUSE_OSS")
.clang_arg("-fPIC")
.clang_arg("-fno-strict-aliasing")
.clang_arg("-fstack-protector-strong")
.clang_arg("-fno-plt")
.clang_arg("-I./src/ck/")
.clang_arg("-I./src/io/")
.clang_arg("-I./src/ck/lo")
.clang_arg("-I./src/ck/rgx")
.clang_arg("-I./src/include")
.clang_arg("-I./src/include/au")
.clang_arg("-I./src/include/audio")
.clang_arg("-I./src/include/dsp")
.clang_arg("-I./src/include/gui")
.clang_arg("-I./src/include/midi")
.clang_arg("-I./src/include/osc")
.clang_arg("-I./src/include/unity")
.clang_arg("-I./src/include/vst")
// .clang_arg("-I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include")
// .clang_arg("-I/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/c++")
.clang_arg("-O3")
.clang_arg("-mtune=generic")
.clang_arg("-march=native")
.clang_arg("-pipe")
.opaque_type("std::.*")
.blacklist_item("in_place_t")
.generate()
.expect("Unable to generate bindings");
let _out_path = PathBuf::from("./src/");
let mut bindings_string = bindings.to_string();
let mut file = fs::File::create("./src/ffi.rs").unwrap();
let _write = match file.write_all(bindings_string.as_bytes()) {
Ok(r) => r,
Err(e) => panic!("Unable to write bindings file: {}", e)
};
let _sync = match file.sync_data() {
Ok(r) => r,
Err(e) => panic!("Unable to sync: {}", e)
};
}
} else {
fn build() {
unimplemented!();
}
}
}
fn main() {
let linkage = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or(String::new());
if linkage.contains("crt-static") {
println!("the C runtime will be statically linked");
} else {
println!("the C runtime will be dynamically linked");
}
build()
}