Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build deploys in release mode #403

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Shuttle {
"Building".bold().green(),
working_directory.display()
);
let so_path = build_crate(id, working_directory, tx).await?;
let so_path = build_crate(id, working_directory, false, tx).await?;

trace!("loading secrets");
let secrets_path = working_directory.join("Secrets.toml");
Expand Down
2 changes: 1 addition & 1 deletion deployer/src/deployment/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async fn build_deployment(
project_path: &Path,
tx: crossbeam_channel::Sender<Message>,
) -> Result<PathBuf> {
let so_path = build_crate(deployment_id, project_path, tx)
let so_path = build_crate(deployment_id, project_path, true, tx)
.await
.map_err(|e| Error::Build(e.into()))?;

Expand Down
12 changes: 10 additions & 2 deletions service/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use anyhow::{anyhow, Context};
use cargo::core::compiler::{CompileMode, MessageFormat};
use cargo::core::{Manifest, PackageId, Shell, Summary, Verbosity, Workspace};
use cargo::ops::{compile, CompileOptions};
use cargo::util::interning::InternedString;
use cargo::util::{homedir, ToSemver};
use cargo::Config;
use cargo_metadata::Message;
Expand Down Expand Up @@ -103,6 +104,7 @@ impl Loader {
pub async fn build_crate(
deployment_id: Uuid,
project_path: &Path,
release_mode: bool,
tx: Sender<Message>,
) -> anyhow::Result<PathBuf> {
let (read, write) = pipe::pipe();
Expand All @@ -123,7 +125,7 @@ pub async fn build_crate(
check_version(summary)?;
check_no_panic(&ws)?;

let opts = get_compile_options(&config)?;
let opts = get_compile_options(&config, release_mode)?;
let compilation = compile(&ws, &opts);

Ok(compilation?.cdylibs[0].path.clone())
Expand Down Expand Up @@ -167,14 +169,20 @@ pub fn get_config(writer: PipeWriter) -> anyhow::Result<Config> {
}

/// Get options to compile in build mode
fn get_compile_options(config: &Config) -> anyhow::Result<CompileOptions> {
fn get_compile_options(config: &Config, release_mode: bool) -> anyhow::Result<CompileOptions> {
let mut opts = CompileOptions::new(config, CompileMode::Build)?;
opts.build_config.message_format = MessageFormat::Json {
render_diagnostics: false,
short: false,
ansi: false,
};

opts.build_config.requested_profile = if release_mode {
InternedString::new("release")
} else {
InternedString::new("dev")
};

Ok(opts)
}

Expand Down
10 changes: 5 additions & 5 deletions service/tests/integration/build_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use shuttle_service::loader::build_crate;
async fn not_shuttle() {
let (tx, _) = crossbeam_channel::unbounded();
let project_path = format!("{}/tests/resources/not-shuttle", env!("CARGO_MANIFEST_DIR"));
let so_path = build_crate(Default::default(), Path::new(&project_path), tx)
let so_path = build_crate(Default::default(), Path::new(&project_path), false, tx)
.await
.unwrap();

Expand All @@ -27,7 +27,7 @@ async fn not_shuttle() {
async fn not_lib() {
let (tx, _) = crossbeam_channel::unbounded();
let project_path = format!("{}/tests/resources/not-lib", env!("CARGO_MANIFEST_DIR"));
build_crate(Default::default(), Path::new(&project_path), tx)
build_crate(Default::default(), Path::new(&project_path), false, tx)
.await
.unwrap();
}
Expand All @@ -37,7 +37,7 @@ async fn not_cdylib() {
let (tx, _) = crossbeam_channel::unbounded();
let project_path = format!("{}/tests/resources/not-cdylib", env!("CARGO_MANIFEST_DIR"));
assert!(
build_crate(Default::default(), Path::new(&project_path), tx)
build_crate(Default::default(), Path::new(&project_path), false, tx)
.await
.is_ok()
);
Expand All @@ -51,7 +51,7 @@ async fn is_cdylib() {
let (tx, _) = crossbeam_channel::unbounded();
let project_path = format!("{}/tests/resources/is-cdylib", env!("CARGO_MANIFEST_DIR"));
assert!(
build_crate(Default::default(), Path::new(&project_path), tx)
build_crate(Default::default(), Path::new(&project_path), false, tx)
.await
.is_ok()
);
Expand All @@ -68,7 +68,7 @@ async fn not_found() {
"{}/tests/resources/non-existing",
env!("CARGO_MANIFEST_DIR")
);
build_crate(Default::default(), Path::new(&project_path), tx)
build_crate(Default::default(), Path::new(&project_path), false, tx)
.await
.unwrap();
}