Skip to content

Commit

Permalink
feat: beta builder args (#1813)
Browse files Browse the repository at this point in the history
* feat: beta builder args

* feat: more flags

* fix

* nit

* feat: mold flag

* adjacent enum tag

* fix: features = None when not used
  • Loading branch information
jonaro00 authored Jun 28, 2024
1 parent f0e770f commit 9fe7e56
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
22 changes: 15 additions & 7 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use ignore::WalkBuilder;
use indicatif::ProgressBar;
use indoc::{formatdoc, printdoc};
use shuttle_common::models::deployment::{
BuildMetaBeta, DeploymentRequestBuildArchiveBeta, DeploymentRequestImageBeta,
BuildArgsBeta, BuildMetaBeta, DeploymentRequestBuildArchiveBeta, DeploymentRequestImageBeta,
};
use shuttle_common::{
constants::{
Expand Down Expand Up @@ -1821,23 +1821,31 @@ impl Shuttle {
};

if self.beta {
let mut build_args = BuildArgsBeta::default();

let metadata = async_cargo_metadata(manifest_path.as_path()).await?;
let packages = find_shuttle_packages(&metadata)?;
// TODO: support overriding this
let package = packages
.first()
.expect("at least one shuttle crate in the workspace");
let package_name = package.name.to_owned();
deployment_req_buildarch_beta.package_name = package_name;
build_args.package_name = Some(package_name);

// TODO: add these to the request and builder
let (_no_default_features, _features) = if package.features.contains_key("shuttle") {
(true, vec!["shuttle".to_owned()])
// activate shuttle feature is present
let (no_default_features, features) = if package.features.contains_key("shuttle") {
(true, Some(vec!["shuttle".to_owned()]))
} else {
(false, vec![])
(false, None)
};
build_args.no_default_features = no_default_features;
build_args.features = features.map(|v| v.join(","));

// TODO: determine which (one) binary to build
// TODO: have the above be configurable in CLI and Shuttle.toml

deployment_req_buildarch_beta.build_args = Some(build_args);

// TODO: have all of the above be configurable in CLI and Shuttle.toml
}

if let Ok(repo) = Repository::discover(working_directory) {
Expand Down
6 changes: 1 addition & 5 deletions common/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ pub struct LogItem {

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LogItemBeta {
/// Time log was captured
pub timestamp: DateTime<Utc>,

/// Stdout/stderr
/// Which container / log stream this line came from
pub source: String,

/// The log line
pub line: String,
}

Expand Down
55 changes: 51 additions & 4 deletions common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub struct DeploymentRequest {
}

#[derive(Deserialize, Serialize)]
#[serde(untagged)]
#[serde(tag = "type", content = "content")]
pub enum DeploymentRequestBeta {
/// Build an image from the source code in an attached zip archive
BuildArchive(DeploymentRequestBuildArchiveBeta),
Expand All @@ -298,15 +298,62 @@ pub enum DeploymentRequestBeta {
pub struct DeploymentRequestBuildArchiveBeta {
/// Zip archive
pub data: Vec<u8>,
/// The cargo package name to compile and run.
pub package_name: String,
// TODO: Binary name, feature flags?, other cargo args?
pub build_args: Option<BuildArgsBeta>,
/// Secrets to add before this deployment.
/// TODO: Remove this in favour of a separate secrets uploading action.
pub secrets: Option<HashMap<String, String>>,
pub build_meta: Option<BuildMetaBeta>,
}

#[derive(Deserialize, Serialize)]
pub struct BuildArgsBeta {
/// Use the built in cargo chef setup for caching
pub cargo_chef: bool,
/// Build with the built in `cargo build` setup
pub cargo_build: bool,
/// The cargo package name to compile
pub package_name: Option<String>,
/// The cargo binary name to compile
pub binary_name: Option<String>,
/// comma-separated list of features to activate
pub features: Option<String>,
/// Passed on to `cargo build`
pub no_default_features: bool,
/// Use the mold linker
pub mold: bool,
}

impl Default for BuildArgsBeta {
fn default() -> Self {
Self {
cargo_chef: true,
cargo_build: true,
package_name: Default::default(),
binary_name: Default::default(),
features: Default::default(),
no_default_features: Default::default(),
mold: Default::default(),
}
}
}

impl BuildArgsBeta {
pub fn into_vars(&self) -> [(&str, &str); 7] {
[
("CARGO_CHEF", if self.cargo_chef { "true" } else { "" }),
("CARGO_BUILD", if self.cargo_build { "true" } else { "" }),
("PACKAGE", self.package_name.as_deref().unwrap_or_default()),
("BIN", self.binary_name.as_deref().unwrap_or_default()),
("FEATURES", self.features.as_deref().unwrap_or_default()),
(
"NO_DEFAULT_FEATURES",
if self.no_default_features { "true" } else { "" },
),
("MOLD", if self.mold { "true" } else { "" }),
]
}
}

#[derive(Default, Deserialize, Serialize)]
pub struct BuildMetaBeta {
pub git_commit_id: Option<String>,
Expand Down

0 comments on commit 9fe7e56

Please sign in to comment.