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
//! Embed the client DLL into the loader so what ships is a single file.
//!
//! The DLL 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();
let dll = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../target")
.join(&target)
.join("release/lodestone_client.dll");
println!("cargo:rerun-if-changed={}", dll.display());
let embedded = out.join("client.dll");
match std::fs::read(&dll) {
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());
}