-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.rs
More file actions
113 lines (106 loc) · 4.39 KB
/
Copy pathbuild.rs
File metadata and controls
113 lines (106 loc) · 4.39 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
102
103
104
105
106
107
108
109
110
111
112
113
fn main() {
build_info_build::build_script();
#[allow(unused_assignments, unused_mut)] // due to feature flag
let mut is_posix = true;
#[cfg(target_os = "windows")]
{
is_posix = false;
}
#[allow(unused_assignments, unused_mut)] // due to feature flag
let mut is_release = true;
#[cfg(debug_assertions)]
{
is_release = false;
}
// Generate C code bindings for xcplib
if is_posix {
let bindings = bindgen::Builder::default()
.header("xcplib/inc/xcplib.h")
//
//.clang_args(&["-target", "x86_64-pc-windows-msvc"])
.clang_arg("-Ixcplib_cfg")
.clang_arg("-Ixcplib/src")
.clang_arg("-Ixcplib")
.clang_arg("-DXCPLIB_FOR_RUST")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
//
.blocklist_type("T_CLOCK_INFO")
// Protocol layer
.allowlist_function("XcpInit")
.allowlist_function("XcpReset")
.allowlist_function("XcpDisconnect")
// Server
.allowlist_function("XcpEthServerGetInfo")
.allowlist_function("XcpEthServerInit")
.allowlist_function("XcpEthServerShutdown")
.allowlist_function("XcpEthServerStatus")
// CAL
.allowlist_function("XcpCreateCalSeg")
.allowlist_function("XcpFindCalSeg")
.allowlist_function("XcpGetCalSegCount")
.allowlist_function("XcpGetCalSegName")
.allowlist_function("XcpGetCalSegSize")
.allowlist_function("XcpLockCalSeg")
.allowlist_function("XcpUnlockCalSeg")
// DAQ
.allowlist_function("XcpEventExt")
// Misc
.allowlist_function("XcpSetLogLevel")
.allowlist_function("XcpPrint")
.allowlist_function("XcpSetA2lName")
.allowlist_function("ApplXcpRegisterConnectCallback")
.allowlist_function("XcpSendTerminateSessionEvent")
.allowlist_function("ApplXcpGetClock64")
//
.generate()
.expect("Unable to generate bindings");
bindings.write_to_file("src/xcp/xcplib.rs").expect("Couldn't write bindings!");
}
// Build xcplib
let mut builder = cc::Build::new();
let builder = builder
.include("xcplib_cfg/")
.include("xcplib/inc/")
.include("xcplib/src/")
.file("xcplib/src/xcpAppl.c")
.file("xcplib/src/persistence.c")
.file("xcplib/src/platform.c")
.file("xcplib/src/xcpLite.c")
.file("xcplib/src/xcpQueue64.c")
.file("xcplib/src/xcpQueue32.c")
.file("xcplib/src/xcpEthTl.c")
.file("xcplib/src/xcpEthServer.c");
builder.define("XCPLIB_FOR_RUST", None);
if is_posix {
//builder.define("_POSIX_C_SOURCE", "200112L");
builder.flag("-std=c11");
if is_release {
builder.flag("-O2");
} else {
builder.flag("-O0").flag("-g");
}
}
builder.compile("xcplib");
// Tell cargo to invalidate the built crate whenever any of these files changed.
println!("cargo:rerun-if-changed=xcplib_cfg/xcplib_cfg.h");
println!("cargo:rerun-if-changed=xcplib/inc/xcplib.h");
println!("cargo:rerun-if-changed=xcplib/src/main_cfg.h");
println!("cargo:rerun-if-changed=xcplib/src/xcptl_cfg.h");
println!("cargo:rerun-if-changed=xcplib/src/xcp_cfg.h");
println!("cargo:rerun-if-changed=xcplib/src/a2l.h");
println!("cargo:rerun-if-changed=xcplib/src/a2l.c");
println!("cargo:rerun-if-changed=xcplib/src/xcpAppl.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpAppl.c");
println!("cargo:rerun-if-changed=xcplib/src/platform.h");
println!("cargo:rerun-if-changed=xcplib/src/platform.c");
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue64.c");
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue32.c");
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.c");
println!("cargo:rerun-if-changed=xcplib/src/xcpEthServer.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpEthServer.c");
println!("cargo:rerun-if-changed=xcplib/src/xcp.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpLite.h");
println!("cargo:rerun-if-changed=xcplib/src/xcpLite.c");
}