summaryrefslogtreecommitdiff
path: root/engine/build.rs
blob: 7ad5a9b4f160c5c279bfbc2e8378515c1493e416 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::path::{Path, PathBuf};
use std::process::Command;

use cfg_aliases::cfg_aliases;
use serde::Deserialize;

fn main()
{
    let slang_artifacts = std::env::var("DEP_CRATE_SHADER_SLANG_ARTIFACTS").unwrap();

    let cargo_metadata_output = Command::new(build_rs::input::cargo())
        .args([
            "metadata",
            "--format-version=1",
            "-q",
            "--no-deps",
            "--color=never",
            "--manifest-path",
            build_rs::input::cargo_manifest_path().to_str().unwrap(),
        ])
        .output()
        .unwrap();

    if !cargo_metadata_output.status.success() {
        panic!(
            "'cargo metadata' command failed:\n\nstdout:\n{}\n\nstderr:\n{}",
            String::from_utf8_lossy(&cargo_metadata_output.stdout),
            String::from_utf8_lossy(&cargo_metadata_output.stderr),
        );
    }

    let cargo_metadata = serde_json::from_str::<CargoMetadata>(
        str::from_utf8(&cargo_metadata_output.stdout).unwrap(),
    )
    .unwrap();

    let final_artifact_dir = (if build_rs::input::target() == build_rs::input::host() {
        cargo_metadata.target_directory
    } else {
        cargo_metadata
            .target_directory
            .join(build_rs::input::target())
    })
    .join(build_rs::input::profile());

    for artifact_path in slang_artifacts.split(";") {
        let artifact_path = Path::new(artifact_path);

        std::fs::copy(
            artifact_path,
            final_artifact_dir.join(artifact_path.file_name().unwrap()),
        )
        .unwrap();
    }

    // Setup alias to reduce `cfg` boilerplate.
    cfg_aliases! {
        // Systems.
        android_platform: { target_os = "android" },
        wasm_platform: { target_family = "wasm" },
        macos_platform: { target_os = "macos" },
        ios_platform: { target_os = "ios" },
        apple: { any(ios_platform, macos_platform) },
        free_unix: { all(unix, not(apple), not(android_platform)) },

        // Native displays.
        x11_platform: { all(free_unix, not(wasm_platform)) },
        wayland_platform: { all(free_unix, not(wasm_platform)) },
        // x11_platform: { all(feature = "x11", free_unix, not(wasm_platform)) },
        // wayland_platform: { all(feature = "wayland", free_unix, not(wasm_platform)) },

        // Backends.
        egl_backend: {
            all(any(windows, unix), not(apple), not(wasm_platform))
        },
        glx_backend: { all(x11_platform, not(wasm_platform)) },
        wgl_backend: { all(windows, not(wasm_platform)) },
        cgl_backend: { all(macos_platform, not(wasm_platform)) },

        // Backends.
        // egl_backend: {
        //     all(feature = "egl", any(windows, unix), not(apple), not(wasm_platform))
        // },
        // glx_backend: { all(feature = "glx", x11_platform, not(wasm_platform)) },
        // wgl_backend: { all(feature = "wgl", windows, not(wasm_platform)) },
        // cgl_backend: { all(macos_platform, not(wasm_platform)) },
    }
}

#[derive(Debug, Deserialize)]
struct CargoMetadata
{
    target_directory: PathBuf,
}