forked from chrissly31415/rdkitcffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
101 lines (81 loc) · 3.87 KB
/
build.rs
File metadata and controls
101 lines (81 loc) · 3.87 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
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
//https://rust-lang.github.io/rust-bindgen/tutorial-3.html
//https://michael-f-bryan.github.io/rust-ffi-guide/
//https://medium.com/dwelo-r-d/using-c-libraries-in-rust-13961948c72a
//https://medium.com/dwelo-r-d/wrapping-unsafe-c-libraries-in-rust-d75aeb283c65
//https://github.com/rdkit/rdkit/blob/master/Code/MinimalLib/cffi_test.c
extern crate bindgen;
use std::path::PathBuf;
//use std::env;
//compilation for rdkit commands
//cmake -DRDK_BUILD_MINIMAL_LIB=ON -DRDK_BUILD_CFFI_LIB=ON -DRDK_BUILD_INCHI_SUPPORT=ON -DRDK_BUILD_PYTHON_WRAPPERS=OFF ..
//currently we cannot compile it directory from a submodule approach via a cmake crate because of the additional dependencies e.g. boost
//do not use lib and main both, as -l gets only used for library
//one need to set LD_LIBRARY_PATH manually if binary is called without cargo
//e.g. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/loschen/calc/rust_cheminf/rdkitcffi/lib/rdkitcffi_linux/linux-64
fn main() {
let shared_lib_dir = "./lib/rdkitcffi_linux/linux-64/";
//let key = "LD_LIBRARY_PATH";
//#env::set_var(key, shared_lib_dir);
//this sets the dynamic lib path only during build
//println!("cargo:rustc-link-search={}", shared_lib_dir);
println!("cargo:rustc-link-search=native={}", shared_lib_dir);
println!("cargo:rustc-link-lib=dylib=rdkitcffi");
println!("cargo:rerun-if-changed=wrapper.h");
//use this for dynamic lib path cargo test & run
println!("cargo:rustc-env=LD_LIBRARY_PATH={}",shared_lib_dir);
//pkg_config::Config::new().probe("boost").unwrap();
//pkg_config::Config::new().probe("rdkitcffi").unwrap();
let bindings = bindgen::Builder::default()
//.trust_clang_mangling(false)
.header("include/cffiwrapper.h")
.clang_arg("-Iinclude/boost")
.clang_arg("-Iinclude")
.allowlist_function("version")
.allowlist_function("enable_logging")
.allowlist_function("disable_logging")
.allowlist_function("get_smiles")
.allowlist_function("get_mol")
.allowlist_function("get_inchikey_for_inchi")
.allowlist_function("get_inchi")
.allowlist_function("get_molblock")
.allowlist_function("get_v3kmolblock")
.allowlist_function("get_json")
.allowlist_function("canonical_tautomer")
.allowlist_function("get_descriptors")
.allowlist_function("add_hs")
.allowlist_function("set_3d_coords")
.allowlist_function("set_2d_coords")
.allowlist_function("get_svg")
.allowlist_function("remove_all_hs")
.allowlist_function("get_substruct_matches")
.allowlist_function("get_substruct_match")
.allowlist_function("get_cxsmiles")
.allowlist_function("get_smarts")
.allowlist_function("get_qmol")
.allowlist_function("cleanup")
.allowlist_function("neutralize")
.allowlist_function("reionize")
.allowlist_function("normalize")
.allowlist_function("get_morgan_fp")
.allowlist_function("get_morgan_fp_as_bytes")
.allowlist_function("get_rdkit_fp")
.allowlist_function("get_rdkit_fp_as_bytes")
.allowlist_function("get_pattern_fp")
.allowlist_function("get_pattern_fp_as_bytes")
.allowlist_function("free")
.allowlist_function("free_ptr")
.allowlist_var("size_t")
//TODO
.allowlist_function("charge_parent")
.allowlist_function("fragment_parent")
.allowlist_function("prefer_coordgen")
.allowlist_function("set_2d_coords_aligned")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from("./src");
//let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}