polyhorn_cli/ios/tasks/
build_runtime_library_v2.rs

1use super::{IOSContext, IOSError};
2use crate::core::{CargoRustc, Manager, Task};
3
4/// This tasks builds the runtime library for the given target and with the
5/// given profile.
6pub struct BuildRuntimeLibraryV2 {
7    /// Custom cfg to use when building this library.
8    pub cfg: &'static str,
9
10    /// The target for which this library will be built.
11    pub target: &'static str,
12
13    /// The profile to pass to Cargo, e.g. `debug` or `release`.
14    pub profile: &'static str,
15
16    /// Additional flags passed to `rustc`.
17    pub flags: &'static [&'static str],
18}
19
20impl Task for BuildRuntimeLibraryV2 {
21    type Context = IOSContext;
22    type Error = IOSError;
23
24    fn verb(&self) -> &str {
25        "Building"
26    }
27
28    fn message(&self) -> &str {
29        "runtime library"
30    }
31
32    fn detail(&self) -> &str {
33        "for iOS"
34    }
35
36    fn run(&self, mut context: IOSContext, _manager: &mut Manager) -> Result<IOSContext, IOSError> {
37        eprintln!("");
38
39        let path = CargoRustc::new(&context.config.manifest_dir.join("Cargo.toml"))
40            .crate_type("staticlib")
41            .cfg(self.cfg)
42            .profile(self.profile)
43            .release(self.profile == "release")
44            .target(self.target)
45            .flags(self.flags)
46            .build()?;
47
48        context.products.insert(self.target.to_owned(), path);
49
50        Ok(context)
51    }
52}