feat: with rust workspace members
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-03-30 22:33:25 +01:00
parent 0539e375b1
commit 823712e2bf
5 changed files with 114 additions and 23 deletions

View File

@@ -3,12 +3,11 @@ use std::path::PathBuf;
use async_trait::async_trait;
use dagger_rust::source::RustSource;
use dagger_sdk::Container;
use futures::StreamExt;
use crate::{
cli,
rust_service::architecture::{Architecture, Os},
MainAction, PullRequestAction,
rust_workspace, MainAction, PullRequestAction,
};
#[derive(Clone)]
@@ -24,7 +23,7 @@ pub struct RustLib {
impl RustLib {
pub fn new(value: dagger_sdk::Query) -> Self {
Self {
client: value,
client: value.pipeline("rust-lib"),
source: None,
crates: Vec::new(),
arch: None,
@@ -54,6 +53,16 @@ impl RustLib {
self
}
pub async fn with_workspace_crates(&mut self) -> &mut Self {
if let Ok(Some(file)) = rust_workspace::File::read_file().await {
if let Some(members) = file.get_workspace_members() {
return self.with_crates(members);
}
}
self
}
pub fn with_arch(&mut self, arch: Architecture) -> &mut Self {
self.arch = Some(arch);
@@ -72,26 +81,6 @@ impl RustLib {
.unwrap_or(std::env::current_dir().unwrap())
}
fn get_arch(&self) -> Architecture {
self.arch
.clone()
.unwrap_or_else(|| match std::env::consts::ARCH {
"x86" | "x86_64" | "amd64" => Architecture::Amd64,
"arm" => Architecture::Arm64,
arch => panic!("unsupported architecture: {arch}"),
})
}
fn get_os(&self) -> Os {
self.os
.clone()
.unwrap_or_else(|| match std::env::consts::OS {
"linux" => Os::Linux,
"macos" => Os::MacOS,
os => panic!("unsupported os: {os}"),
})
}
pub async fn build_base(&self) -> eyre::Result<Container> {
let rust_src = RustSource::new(self.client.clone());