-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(xtask): extract artifact args
Signed-off-by: Martin Kröning <[email protected]>
- Loading branch information
Showing
3 changed files
with
80 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use clap::Args; | ||
|
||
use crate::arch::Arch; | ||
use crate::archive::Archive; | ||
|
||
#[derive(Args)] | ||
pub struct Artifact { | ||
/// Target architecture. | ||
#[arg(value_enum, long)] | ||
pub arch: Arch, | ||
|
||
/// Directory for all generated artifacts. | ||
#[arg(long)] | ||
pub target_dir: Option<PathBuf>, | ||
|
||
/// Build artifacts in release mode, with optimizations. | ||
#[arg(short, long)] | ||
pub release: bool, | ||
|
||
/// Build artifacts with the specified profile. | ||
#[arg(long)] | ||
pub profile: Option<String>, | ||
} | ||
|
||
impl Artifact { | ||
pub fn profile(&self) -> &str { | ||
self.profile | ||
.as_deref() | ||
.unwrap_or(if self.release { "release" } else { "dev" }) | ||
} | ||
|
||
pub fn target_dir(&self) -> &Path { | ||
self.target_dir | ||
.as_deref() | ||
.unwrap_or_else(|| Path::new("target")) | ||
} | ||
|
||
pub fn out_dir(&self, triple: impl AsRef<Path>) -> PathBuf { | ||
let mut out_dir = self.target_dir().to_path_buf(); | ||
out_dir.push(triple); | ||
out_dir.push(match self.profile() { | ||
"dev" => "debug", | ||
profile => profile, | ||
}); | ||
out_dir | ||
} | ||
|
||
pub fn builtins_archive(&self) -> Archive { | ||
let mut builtins_archive = self.out_dir(self.arch.hermit_triple()); | ||
builtins_archive.push("libhermit_builtins.a"); | ||
builtins_archive.into() | ||
} | ||
|
||
pub fn build_archive(&self) -> Archive { | ||
let mut built_archive = self.out_dir(self.arch.triple()); | ||
built_archive.push("libhermit.a"); | ||
built_archive.into() | ||
} | ||
|
||
pub fn dist_archive(&self) -> Archive { | ||
let mut dist_archive = self.out_dir(self.arch.name()); | ||
dist_archive.push("libhermit.a"); | ||
dist_archive.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
mod arch; | ||
mod archive; | ||
mod artifact; | ||
mod build; | ||
mod clippy; | ||
|
||
|