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
use super::{IOSContext, IOSError};
use crate::core::{CargoRustc, Manager, Task};

/// This tasks builds the runtime library for the given target and with the
/// given profile.
pub struct BuildRuntimeLibraryV2 {
    /// Custom cfg to use when building this library.
    pub cfg: &'static str,

    /// The target for which this library will be built.
    pub target: &'static str,

    /// The profile to pass to Cargo, e.g. `debug` or `release`.
    pub profile: &'static str,

    /// Additional flags passed to `rustc`.
    pub flags: &'static [&'static str],
}

impl Task for BuildRuntimeLibraryV2 {
    type Context = IOSContext;
    type Error = IOSError;

    fn verb(&self) -> &str {
        "Building"
    }

    fn message(&self) -> &str {
        "runtime library"
    }

    fn detail(&self) -> &str {
        "for iOS"
    }

    fn run(&self, mut context: IOSContext, _manager: &mut Manager) -> Result<IOSContext, IOSError> {
        eprintln!("");

        let path = CargoRustc::new(&context.config.manifest_dir.join("Cargo.toml"))
            .crate_type("staticlib")
            .cfg(self.cfg)
            .profile(self.profile)
            .release(self.profile == "release")
            .target(self.target)
            .flags(self.flags)
            .build()?;

        context.products.insert(self.target.to_owned(), path);

        Ok(context)
    }
}