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

Remove cargo from cargo shuttle #765

Merged
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.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ homepage = "https://www.shuttle.rs"
anyhow = { workspace = true }
async-trait = { workspace = true }
bollard = { workspace = true }
cargo = { workspace = true }
cargo-edit = { version = "0.11.9", features = ["cli"] }
cargo_metadata = { workspace = true }
chrono = { workspace = true }
Expand Down Expand Up @@ -56,6 +55,7 @@ tracing-subscriber = { workspace = true, features = [
url = "2.3.1"
uuid = { workspace = true, features = ["v4"] }
webbrowser = "0.8.2"
semver = "1.0.17"

[dependencies.shuttle-common]
workspace = true
Expand Down
15 changes: 6 additions & 9 deletions cargo-shuttle/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::io::Write;
use std::path::{Path, PathBuf};

use anyhow::Result;
use cargo::ops::NewOptions;
use cargo_edit::{find, get_latest_dependency, registry_url};
use indoc::indoc;
use toml_edit::{value, Array, Document, Table};
Expand Down Expand Up @@ -866,14 +865,12 @@ impl ShuttleInit for ShuttleInitNoOp {

/// Interoprates with `cargo` crate and calls `cargo init [path]`.
pub fn cargo_init(path: PathBuf) -> Result<()> {
let opts = NewOptions::new(None, true, false, path, None, None, None)?;
let cargo_config = cargo::util::config::Config::default()?;
let init_result = cargo::ops::init(&opts, &cargo_config)?;

// Mimic `cargo init` behavior and log status or error to shell
cargo_config
.shell()
.status("Created", format!("{init_result} (shuttle) package"))?;
std::process::Command::new("cargo")
.arg("init")
.arg("--bin")
.arg(path)
.output()
.expect("Failed to initialize with cargo init.");

Ok(())
}
Expand Down
21 changes: 12 additions & 9 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub mod config;
mod init;
mod provisioner_server;

use cargo::util::ToSemver;
use indicatif::ProgressBar;
use shuttle_common::models::deployment::get_deployments_table;
use shuttle_common::models::project::{State, IDLE_MINUTES};
Expand Down Expand Up @@ -936,7 +935,9 @@ impl Shuttle {
}

fn check_version(runtime_path: &Path) -> Result<()> {
let valid_version = VERSION.to_semver().unwrap();
let valid_version = semver::Version::from_str(VERSION)
.context("failed to convert runtime version to semver")?
.to_string();

if !runtime_path.try_exists()? {
bail!("shuttle-runtime is not installed");
Expand All @@ -952,13 +953,15 @@ fn check_version(runtime_path: &Path) -> Result<()> {

// Parse the version, splitting the version from the name and
// and pass it to `to_semver()`.
let runtime_version = std::str::from_utf8(&runtime_version)
.expect("shuttle-runtime version should be valid utf8")
.split_once(' ')
.expect("shuttle-runtime version should be in the `name version` format")
.1
.to_semver()
.context("failed to convert runtime version to semver")?;
let runtime_version = semver::Version::from_str(
std::str::from_utf8(&runtime_version)
.expect("shuttle-runtime version should be valid utf8")
.split_once(' ')
.expect("shuttle-runtime version should be in the `name version` format")
.1,
)
.context("failed to convert runtime version to semver")?
.to_string();

if runtime_version == valid_version {
Ok(())
Expand Down