ptx_builder/executable/
mod.rs

1use semver::{Version, VersionReq};
2
3use crate::error::*;
4
5pub mod runner;
6pub use self::runner::{ExecutableRunner, Output};
7
8/// Details and requirements for executables.
9pub trait Executable {
10    /// Returns executable name in `PATH`.
11    fn get_name(&self) -> String;
12
13    /// Returns message about how to install missing executable.
14    fn get_verification_hint(&self) -> String;
15
16    /// Returns message about how to update outdated executable.
17    fn get_version_hint(&self) -> String;
18
19    /// Executable version constraint.
20    fn get_required_version(&self) -> Option<VersionReq>;
21
22    /// Returns the current version of the executable.
23    fn get_current_version(&self) -> Result<Version>
24    where
25        Self: Sized,
26    {
27        self::runner::parse_executable_version(self)
28    }
29}
30
31/// `cargo` command.
32pub struct Cargo;
33
34/// `ptx-linker` command.
35pub struct Linker;
36
37impl Executable for Cargo {
38    fn get_name(&self) -> String {
39        String::from("cargo")
40    }
41
42    fn get_verification_hint(&self) -> String {
43        String::from("Please make sure you have it installed and in PATH")
44    }
45
46    fn get_version_hint(&self) -> String {
47        String::from("Please update Rust and Cargo to latest nightly versions")
48    }
49
50    fn get_required_version(&self) -> Option<VersionReq> {
51        Some(VersionReq::parse(">= 1.34.0-nightly").unwrap())
52    }
53
54    fn get_current_version(&self) -> Result<Version> {
55        // Omit Rust channel name because it's not really semver-correct
56        // https://github.com/steveklabnik/semver/issues/105
57
58        self::runner::parse_executable_version(self).map(|mut version| {
59            version.pre = vec![];
60            version
61        })
62    }
63}
64
65impl Executable for Linker {
66    fn get_name(&self) -> String {
67        String::from("rust-ptx-linker")
68    }
69
70    fn get_verification_hint(&self) -> String {
71        String::from("You can install it with: 'cargo install ptx-linker'")
72    }
73
74    fn get_version_hint(&self) -> String {
75        String::from("You can update it with: 'cargo install -f ptx-linker'")
76    }
77
78    fn get_required_version(&self) -> Option<VersionReq> {
79        Some(VersionReq::parse(">= 0.9.0").unwrap())
80    }
81}