Skip to content

Commit 27eacba

Browse files
authored
Windows (#28)
Windows compatibility * Using xcpQueue32.c for Windows * Windows MSVC stdatomics emulation
1 parent fb5fecf commit 27eacba

33 files changed

+2326
-1669
lines changed

.vscode/settings.json

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
{
22
"files.associations": {
3-
"stdatomic.h": "c"
3+
"stdatomic.h": "c",
4+
"malloc.h": "c"
45
},
56
"cSpell.words": [
7+
"ampl",
8+
"Appl",
9+
"bitflags",
10+
"CALPAGE",
11+
"calseg",
612
"COMPU",
13+
"cycletime",
14+
"DNLOAD",
715
"DONT",
16+
"Histogramm",
17+
"ifdata",
18+
"Informatik",
19+
"INSTS",
20+
"INTIALIZER",
821
"Mainloop",
22+
"nonoverlapping",
23+
"Plite",
24+
"reinit",
925
"SBYTE",
26+
"serv",
1027
"SLONG",
11-
"UBYTE"
28+
"Slonglong",
29+
"thiserror",
30+
"UBYTE",
31+
"Watomic",
32+
"xcplib",
33+
"XCPTL"
1234
]
1335
}

build.rs

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ fn main() {
22
build_info_build::build_script();
33

44
#[allow(unused_assignments, unused_mut)] // due to feature flag
5-
let mut _is_posix = true;
5+
let mut is_posix = true;
66
#[cfg(target_os = "windows")]
77
{
8-
_is_posix = false;
8+
is_posix = false;
99
}
1010

1111
#[allow(unused_assignments, unused_mut)] // due to feature flag
@@ -16,41 +16,41 @@ fn main() {
1616
}
1717

1818
// Generate C code bindings for xcplib
19-
let bindings = bindgen::Builder::default()
20-
.header("xcplib/wrapper.h")
21-
//
22-
//.clang_args(&["-target", "x86_64-pc-windows-msvc"])
23-
.clang_arg("-Ixcplib/src")
24-
.clang_arg("-Ixcplib")
25-
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
26-
//
27-
.blocklist_type("T_CLOCK_INFO")
28-
.allowlist_type("tXcpDaqLists")
29-
// Protocol layer
30-
.allowlist_function("XcpInit")
31-
.allowlist_function("XcpDisconnect")
32-
// Transport layer
33-
.allowlist_function("XcpEthTlGetInfo")
34-
// Server
35-
.allowlist_function("XcpEthServerInit")
36-
.allowlist_function("XcpEthServerShutdown")
37-
.allowlist_function("XcpEthServerStatus")
38-
// DAQ
39-
.allowlist_function("XcpEvent")
40-
.allowlist_function("XcpEventExt")
41-
// Misc
42-
.allowlist_function("XcpSetLogLevel")
43-
.allowlist_function("XcpPrint")
44-
.allowlist_function("XcpSetEpk")
45-
.allowlist_function("XcpSendTerminateSessionEvent")
46-
//.allowlist_function("ApplXcpGetAddr")
47-
.allowlist_function("ApplXcpSetA2lName")
48-
.allowlist_function("ApplXcpRegisterCallbacks")
49-
.allowlist_function("ApplXcpGetClock64")
50-
//
51-
.generate()
52-
.expect("Unable to generate bindings");
53-
bindings.write_to_file("src/xcp/xcplib.rs").expect("Couldn't write bindings!");
19+
if is_posix {
20+
let bindings = bindgen::Builder::default()
21+
.header("xcplib/wrapper.h")
22+
//
23+
//.clang_args(&["-target", "x86_64-pc-windows-msvc"])
24+
.clang_arg("-Ixcplib/src")
25+
.clang_arg("-Ixcplib")
26+
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
27+
//
28+
.blocklist_type("T_CLOCK_INFO")
29+
// Protocol layer
30+
.allowlist_function("XcpInit")
31+
.allowlist_function("XcpDisconnect")
32+
// Transport layer
33+
.allowlist_function("XcpEthTlGetInfo")
34+
// Server
35+
.allowlist_function("XcpEthServerInit")
36+
.allowlist_function("XcpEthServerShutdown")
37+
.allowlist_function("XcpEthServerStatus")
38+
// DAQ
39+
.allowlist_function("XcpEvent")
40+
.allowlist_function("XcpEventExt")
41+
// Misc
42+
.allowlist_function("XcpSetLogLevel")
43+
.allowlist_function("XcpPrint")
44+
.allowlist_function("XcpSetEpk")
45+
.allowlist_function("ApplXcpSetA2lName")
46+
.allowlist_function("ApplXcpRegisterCallbacks")
47+
.allowlist_function("XcpSendTerminateSessionEvent")
48+
.allowlist_function("ApplXcpGetClock64")
49+
//
50+
.generate()
51+
.expect("Unable to generate bindings");
52+
bindings.write_to_file("src/xcp/xcplib.rs").expect("Couldn't write bindings!");
53+
}
5454

5555
// Build xcplib
5656
let mut builder = cc::Build::new();
@@ -60,16 +60,17 @@ fn main() {
6060
.file("xcplib/src/platform.c")
6161
.file("xcplib/src/xcpLite.c")
6262
.file("xcplib/src/xcpQueue64.c")
63+
.file("xcplib/src/xcpQueue32.c")
6364
.file("xcplib/src/xcpEthTl.c")
64-
.file("xcplib/src/xcpEthServer.c")
65-
.flag("-std=c11");
66-
67-
if is_release {
68-
builder.flag("-O2");
69-
} else {
70-
builder.flag("-O0").flag("-g");
65+
.file("xcplib/src/xcpEthServer.c");
66+
if is_posix {
67+
builder.flag("-std=c11");
68+
if is_release {
69+
builder.flag("-O2");
70+
} else {
71+
builder.flag("-O0").flag("-g");
72+
}
7173
}
72-
7374
builder.compile("xcplib");
7475

7576
// Tell cargo to invalidate the built crate whenever any of these files changed.
@@ -86,6 +87,7 @@ fn main() {
8687
println!("cargo:rerun-if-changed=xcplib/src/platform.c");
8788
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue.h");
8889
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue64.c");
90+
println!("cargo:rerun-if-changed=xcplib/src/xcpQueue32.c");
8991
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.h");
9092
println!("cargo:rerun-if-changed=xcplib/src/xcpEthTl.c");
9193
println!("cargo:rerun-if-changed=xcplib/src/xcpEthServer.h");

0 commit comments

Comments
 (0)