polyhorn_cli/ios/tasks/
build_runtime_library.rs

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