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

Issue 175: cargo shuttle init (without bonus) #192

Merged
merged 18 commits into from
Jun 8, 2022
Merged

Issue 175: cargo shuttle init (without bonus) #192

merged 18 commits into from
Jun 8, 2022

Conversation

nahuakang
Copy link
Contributor

@nahuakang nahuakang commented May 27, 2022

Motivation

This PR adds cargo shuttle init feature to #175. This is a partial solution to the feature as it does not include separate cargo shuttle init commands for each supported framework, e.g. axum and rocket.

I hope to continue on these separate commands on a separate PR and then start refactoring Shuttle.init method inside cargo-shuttle/src/main.rs as I think we could extract out some logic and add unit tests to the operations on Cargo.toml.

Changes

  1. Add an Init(InitArgs) variant to Command in args.rs
  2. Call cargo init --lib via the cargo crate
  3. Automatically add the crate-type = ["cdylib"] to Cargo.toml
  4. Add the shuttle-service dependency to Cargo.toml

How it works

  • Run cargo shuttle init initializes Cargo.toml and src/ in the current directory (similar to cargo init)
  • Run cargo shuttle init newproject initializes in ./newproject directory; if the directory newproject does not exist, it will be created
  • Run cargo shuttle init /full/path/to/newproject initializes Cargo.toml and src/ in the given path; if any directory does not exist, it will be recursively created

To-Dos

  • Update documentation?

@nahuakang nahuakang marked this pull request as ready for review May 27, 2022 20:07
Copy link
Contributor

@chesedo chesedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking real good. Thanks @nahuakang !

@nahuakang
Copy link
Contributor Author

@chesedo I opted to use cargo-edit on version "0.8.0" for fetching the latest shuttle-service version (could use cargo to do the same but it'd add quite a bit more code since we'd fetch all Summary instances of shuttle-service and then manually rank them to extract the latest one).

However, I cannot use cargo-edit = "0.9.0" due to a dependency conflict from cargo (not sure if we care?):

Caused by:
  failed to select a version for `libgit2-sys`.
      ... required by package `cargo v0.59.0`
      ... which satisfies dependency `cargo = "^0.59.0"` of package `cargo-shuttle v0.3.0 (/Users/nahua/projects/shuttle-hq/shuttle/cargo-shuttle)`
  versions that meet the requirements `^0.12.24` are: 0.12.26+1.3.0, 0.12.25+1.3.0, 0.12.24+1.3.0

  the package `libgit2-sys` links to the native library `git2`, but it conflicts with a previous package which links to `git2` as well:
  package `libgit2-sys v0.13.0+1.4.1`
      ... which satisfies dependency `libgit2-sys = "^0.13.0"` of package `git2 v0.14.0`
      ... which satisfies dependency `git2 = "^0.14"` of package `cargo-edit v0.9.0`
      ... which satisfies dependency `cargo-edit = "^0.9.0"` of package `cargo-shuttle v0.3.0 (/Users/nahua/projects/shuttle-hq/shuttle/cargo-shuttle)`
  Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='libgit2-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

  failed to select a version for `libgit2-sys` which could resolve this conflict

@nahuakang nahuakang requested a review from chesedo May 31, 2022 13:20
Copy link
Contributor

@chesedo chesedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all happy with this @nahuakang.

If updating to cargo v0.62 is easy and fixes the update for cargo-edit, then feel free to commit it on this PR. Else I'm happy to merge with the older version of cargo-edit

@nahuakang
Copy link
Contributor Author

@chesedo Hey Pieter, thanks and now I merged the conflicts with main branch (like the re-organization you did!).

I tried updating both cargo-shuttle and api with cargo = "0.62.0". But with the updates, running cargo clippy --test --all-targets... would lead to the the following error and I'm not sure how to fix it (changing rocket = "0.5.0.rc-2" doesn't help either).

    Checking api v0.1.0 (/Users/nahua/projects/shuttle-hq/shuttle/api)
error[E0277]: the trait bound `uuid::Uuid: rocket::request::FromParam<'_>` is not satisfied
  --> api/src/main.rs:58:9
   |
58 |     id: Uuid,
   |         ^^^^ the trait `rocket::request::FromParam<'_>` is not implemented for `uuid::Uuid`

error[E0277]: the trait bound `uuid::Uuid: rocket::request::FromParam<'_>` is not satisfied
  --> api/src/main.rs:69:9
   |
69 |     id: Uuid,
   |         ^^^^ the trait `rocket::request::FromParam<'_>` is not implemented for `uuid::Uuid`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `api` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed

Should I leave the versions as the present values instead? I'm not too familiar to understand why this trait bound issue occurs with the version update.

Copy link
Contributor

@chesedo chesedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for this @nahuakang!

@chesedo chesedo merged commit 6524632 into shuttle-hq:main Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants