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: get runtime binary from cargo install #578

Merged
3 changes: 0 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ use uuid::Uuid;
use crate::args::{DeploymentCommand, ProjectCommand};
use crate::client::Client;

const BINARY_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/release/shuttle-runtime"));

pub struct Shuttle {
ctx: RequestContext,
}
Expand Down Expand Up @@ -412,7 +410,6 @@ impl Shuttle {
run_args.port + 1,
));
let (mut runtime, mut runtime_client) = runtime::start(
BINARY_BYTES,
is_wasm,
runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()),
&format!("http://localhost:{}", run_args.port + 1),
Expand Down
3 changes: 0 additions & 3 deletions deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use tracing::{error, trace};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const BINARY_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/release/shuttle-runtime"));

// The `multi_thread` is needed to prevent a deadlock in shuttle_service::loader::build_crate() which spawns two threads
// Without this, both threads just don't start up
#[tokio::main(flavor = "multi_thread")]
Expand Down Expand Up @@ -41,7 +39,6 @@ async fn main() {
.init();

let (mut runtime, mut runtime_client) = runtime::start(
BINARY_BYTES,
false,
runtime::StorageManagerType::Artifacts(args.artifacts_path.clone()),
&args.provisioner_address.uri().to_string(),
Expand Down
49 changes: 28 additions & 21 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ pub mod provisioner {
pub mod runtime {
use std::{
env::temp_dir,
fs::OpenOptions,
io::Write,
path::PathBuf,
process::Command,
time::{Duration, SystemTime},
};

Expand Down Expand Up @@ -240,7 +239,6 @@ pub mod runtime {
}

pub async fn start(
binary_bytes: &[u8],
wasm: bool,
storage_manager_type: StorageManagerType,
provisioner_address: &str,
Expand All @@ -252,7 +250,7 @@ pub mod runtime {
StorageManagerType::WorkingDir(path) => ("working-dir", path),
};

let runtime_executable = get_runtime_executable(binary_bytes);
let runtime_executable = get_runtime_executable();

let runtime = process::Command::new(runtime_executable)
.args([
Expand Down Expand Up @@ -283,26 +281,35 @@ pub mod runtime {
Ok((runtime, runtime_client))
}

fn get_runtime_executable(binary_bytes: &[u8]) -> PathBuf {
fn get_runtime_executable() -> PathBuf {
let tmp_dir = temp_dir();

let path = tmp_dir.join("shuttle-runtime");
let mut open_options = OpenOptions::new();
open_options.write(true).create(true).truncate(true);

#[cfg(target_family = "unix")]
{
use std::os::unix::prelude::OpenOptionsExt;

open_options.mode(0o755);
let dev = std::env::var("SHUTTLE_DEV");
oddgrd marked this conversation as resolved.
Show resolved Hide resolved

if dev.is_ok() {
Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--root")
.arg(&tmp_dir)
.arg("--path")
.arg("../../runtime")
.output()
.expect("failed to install the shuttle runtime");
} else {
Command::new("cargo")
.arg("install")
.arg("shuttle-runtime")
.arg("--root")
.arg(&tmp_dir)
.arg("--git")
.arg("https://github.com/shuttle-hq/shuttle")
.arg("--branch")
.arg("shuttle-next")
.output()
.expect("failed to install the shuttle runtime");
}

let mut file = open_options
.open(&path)
.expect("to create runtime executable file");

file.write_all(binary_bytes)
.expect("to write out binary file");
let path = tmp_dir.join("bin/shuttle-runtime");

path
}
Expand Down