~starkingdoms/starkingdoms

ref: ca71c045aee1eef8b485ffcde0d8fac591d894aa starkingdoms/spacetime_rs/src/configure/rust.rs -rw-r--r-- 2.9 KiB
ca71c045 — core build assets with compiling the client 2 years ago
                                                                                
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
95
96
97
98
99
100
101
102
103
/*
def gen_rules_for_api(root, env, writer, modules):
    if env == 'dev':
        out_dir = 'debug'
        writer.rule('cargo-api', f'cargo build --bin starkingdoms-api --features "{modules}"',
                    depfile=f'{root}/target/debug/starkingdoms-api.d', pool='console')
    elif env == 'prod':
        out_dir = 'release'
        writer.rule('cargo-api', f'cargo build --bin starkingdoms-api --release --features "{modules}"',
                    depfile=f'{root}/target/release/starkingdoms-api.d', pool='console')

    writer.build([f'{root}/target/{out_dir}/starkingdoms-api'], 'cargo-api', ['server/Cargo.toml'])
    writer.build(['api'], 'phony', [f'{root}/target/{out_dir}/starkingdoms-api'])
 */

use crate::ninja::NinjaWriter;
use std::collections::HashMap;
use std::error::Error;
use std::fs::File;
use std::path::Path;

pub fn configure_rust_target(
    rust_target: &str,
    rust_env: &str,
    writer: &mut NinjaWriter<File>,
    root: &Path,
) -> Result<(), Box<dyn Error>> {
    let out_dir;
    if rust_env == "dev" {
        out_dir = "debug";
        writer.rule(
            &format!("cargo-{}", rust_target),
            &format!("cargo build --bin starkingdoms-{}", rust_target),
            None,
            Some(
                root.join("target/debug/")
                    .join(format!("starkingdoms-{}.d", rust_target))
                    .to_str()
                    .unwrap(),
            ),
            None,
            Some("console"),
            None,
            None,
            None,
            None,
        )?;
    } else {
        out_dir = "release";
        writer.rule(
            &format!("cargo-{}", rust_target),
            &format!("cargo build --bin starkingdoms-{} --release", rust_target),
            None,
            Some(
                root.join("target/release/")
                    .join(format!("starkingdoms-{}.d", rust_target))
                    .to_str()
                    .unwrap(),
            ),
            None,
            Some("console"),
            None,
            None,
            None,
            None,
        )?;
    }

    writer.build(
        vec![root
            .join(format!("target/{}/", out_dir))
            .join(format!("starkingdoms-{}", rust_target))
            .to_str()
            .unwrap()
            .to_string()],
        format!("cargo-{}", rust_target),
        vec![root.join("server/Cargo.toml").to_str().unwrap().to_string()],
        vec![],
        vec![],
        HashMap::new(),
        vec![],
        None,
        None,
    )?;
    writer.build(
        vec![rust_target.to_string()],
        "phony".to_string(),
        vec![root
            .join(format!("target/{}/", out_dir))
            .join(format!("starkingdoms-{}", rust_target))
            .to_str()
            .unwrap()
            .to_string()],
        vec![],
        vec![],
        HashMap::new(),
        vec![],
        None,
        None,
    )?;

    Ok(())
}