use std::path::PathBuf;

fn main() {
    println!("cargo:rustc-check-cfg=cfg(coverage)");

    let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("manifest dir"));
    let workspace_dir = manifest_dir;

    let server_uvc = workspace_dir
        .join("server/src/bin/lesavka-uvc.rs")
        .canonicalize()
        .expect("canonical server uvc bin path");
    let server_main = workspace_dir
        .join("server/src/main.rs")
        .canonicalize()
        .expect("canonical server main path");
    let server_video = workspace_dir
        .join("server/src/video.rs")
        .canonicalize()
        .expect("canonical server video path");
    let server_gadget = workspace_dir
        .join("server/src/gadget.rs")
        .canonicalize()
        .expect("canonical server gadget path");
    let server_video_sinks = workspace_dir
        .join("server/src/video_sinks.rs")
        .canonicalize()
        .expect("canonical server video_sinks path");
    let client_main = workspace_dir
        .join("client/src/main.rs")
        .canonicalize()
        .expect("canonical client main path");
    let client_app = workspace_dir
        .join("client/src/app.rs")
        .canonicalize()
        .expect("canonical client app path");
    let client_inputs = workspace_dir
        .join("client/src/input/inputs.rs")
        .canonicalize()
        .expect("canonical client inputs path");
    let client_camera = workspace_dir
        .join("client/src/input/camera.rs")
        .canonicalize()
        .expect("canonical client camera path");
    let client_keyboard = workspace_dir
        .join("client/src/input/keyboard.rs")
        .canonicalize()
        .expect("canonical client keyboard path");
    let client_microphone = workspace_dir
        .join("client/src/input/microphone.rs")
        .canonicalize()
        .expect("canonical client microphone path");
    let client_mouse = workspace_dir
        .join("client/src/input/mouse.rs")
        .canonicalize()
        .expect("canonical client mouse path");
    let client_output_audio = workspace_dir
        .join("client/src/output/audio.rs")
        .canonicalize()
        .expect("canonical client output audio path");
    let client_output_display = workspace_dir
        .join("client/src/output/display.rs")
        .canonicalize()
        .expect("canonical client output display path");
    let client_output_video = workspace_dir
        .join("client/src/output/video.rs")
        .canonicalize()
        .expect("canonical client output video path");
    let client_video_support = workspace_dir
        .join("client/src/video_support.rs")
        .canonicalize()
        .expect("canonical client video_support path");
    let client_relayctl = workspace_dir
        .join("client/src/bin/lesavka-relayctl.rs")
        .canonicalize()
        .expect("canonical client relayctl bin path");
    let common_cli = workspace_dir
        .join("common/src/bin/cli.rs")
        .canonicalize()
        .expect("canonical common cli bin path");

    println!(
        "cargo:rustc-env=LESAVKA_SERVER_UVC_BIN_SRC={}",
        server_uvc.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_SERVER_MAIN_SRC={}",
        server_main.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_SERVER_VIDEO_SRC={}",
        server_video.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_SERVER_GADGET_SRC={}",
        server_gadget.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_SERVER_VIDEO_SINKS_SRC={}",
        server_video_sinks.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_MAIN_SRC={}",
        client_main.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_APP_SRC={}",
        client_app.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_INPUTS_SRC={}",
        client_inputs.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_CAMERA_SRC={}",
        client_camera.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_KEYBOARD_SRC={}",
        client_keyboard.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_MICROPHONE_SRC={}",
        client_microphone.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_MOUSE_SRC={}",
        client_mouse.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_OUTPUT_AUDIO_SRC={}",
        client_output_audio.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_OUTPUT_DISPLAY_SRC={}",
        client_output_display.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_OUTPUT_VIDEO_SRC={}",
        client_output_video.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_VIDEO_SUPPORT_SRC={}",
        client_video_support.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_CLIENT_RELAYCTL_BIN_SRC={}",
        client_relayctl.display()
    );
    println!(
        "cargo:rustc-env=LESAVKA_COMMON_CLI_BIN_SRC={}",
        common_cli.display()
    );
}
