Sign in Sign up
kretrod/lodestone Public
Branches
master
30 lines (27 loc) · 1.1 KB Raw
//! 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());
}