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
//! Embed the client library into the loader so what ships is a single file.
//!
//! The library is a sibling build artefact rather than a source file, so this
//! points `include_bytes!` at it and re-runs when it changes. If it has not
//! been built yet an empty placeholder is emitted instead, which keeps the
//! loader compiling on its own — it simply falls back to a path argument.
use std::path::PathBuf;
fn main() {
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let target = std::env::var("TARGET").unwrap_or_default();
// A cdylib is a .dll on Windows and a lib*.so on Linux.
let artifact = if target.contains("windows") {
"lodestone_client.dll"
} else {
"liblodestone_client.so"
};
let lib = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../target")
.join(&target)
.join("release")
.join(artifact);
println!("cargo:rerun-if-changed={}", lib.display());
let embedded = out.join("client.bin");
match std::fs::read(&lib) {
Ok(bytes) => {
std::fs::write(&embedded, bytes).unwrap();
println!("cargo:rustc-cfg=has_embedded_client");
}
Err(_) => {
std::fs::write(&embedded, []).unwrap();
}
}
println!("cargo:rustc-env=LODESTONE_CLIENT_DLL={}", embedded.display());
}