@@ -4,7 +4,6 @@ use std::process::Stdio;
44
55use anyhow:: { bail, Context , Result } ;
66use cargo_metadata:: { Metadata , Package , Target } ;
7- use shuttle_common:: constants:: RUNTIME_NAME ;
87use tokio:: io:: AsyncBufReadExt ;
98use tracing:: { error, trace} ;
109
@@ -56,7 +55,7 @@ pub async fn build_workspace(
5655 notification. abort ( ) ;
5756
5857 let metadata = async_cargo_metadata ( manifest_path. as_path ( ) ) . await ?;
59- let ( package, target) = find_first_shuttle_package ( & metadata) ?;
58+ let ( package, target, _ ) = find_first_shuttle_package ( & metadata) ?;
6059
6160 let service = cargo_build (
6261 package,
@@ -100,18 +99,24 @@ pub async fn async_cargo_metadata(manifest_path: &Path) -> Result<Metadata> {
10099}
101100
102101/// Find crates with a runtime dependency and main macro
103- fn find_shuttle_packages ( metadata : & Metadata ) -> Result < Vec < ( Package , Target ) > > {
102+ fn find_shuttle_packages ( metadata : & Metadata ) -> Result < Vec < ( Package , Target , Option < String > ) > > {
104103 let mut packages = Vec :: new ( ) ;
105104 trace ! ( "Finding Shuttle-related packages" ) ;
106105 for member in metadata. workspace_packages ( ) {
107- let has_runtime_dep = member
106+ let runtime_dep = member
108107 . dependencies
109108 . iter ( )
110- . any ( |dependency| dependency. name == RUNTIME_NAME ) ;
111- if !has_runtime_dep {
109+ . find ( |dependency| dependency. name == "shuttle-runtime" ) ;
110+ let Some ( runtime_dep ) = runtime_dep else {
112111 trace ! ( "Skipping {}, no shuttle-runtime dependency" , member. name) ;
113112 continue ;
114- }
113+ } ;
114+ let runtime_version = runtime_dep
115+ . req
116+ . comparators
117+ . first ( )
118+ // is "^0.X.0" when `shuttle-runtime = "0.X.0"` is in Cargo.toml, so strip the caret
119+ . and_then ( |c| c. to_string ( ) . strip_prefix ( '^' ) . map ( ToOwned :: to_owned) ) ;
115120
116121 let mut target = None ;
117122 for t in member. targets . iter ( ) {
@@ -134,13 +139,16 @@ fn find_shuttle_packages(metadata: &Metadata) -> Result<Vec<(Package, Target)>>
134139 } ;
135140
136141 trace ! ( "Found {}" , member. name) ;
137- packages. push ( ( member. to_owned ( ) , target. to_owned ( ) ) ) ;
142+ packages. push ( ( member. to_owned ( ) , target. to_owned ( ) , runtime_version ) ) ;
138143 }
139144
140145 Ok ( packages)
141146}
142147
143- pub fn find_first_shuttle_package ( metadata : & Metadata ) -> Result < ( Package , Target ) > {
148+ /// Find first crate in workspace with a runtime dependency and main macro
149+ pub fn find_first_shuttle_package (
150+ metadata : & Metadata ,
151+ ) -> Result < ( Package , Target , Option < String > ) > {
144152 find_shuttle_packages ( metadata) ?. into_iter ( ) . next ( ) . context (
145153 "Expected at least one target that Shuttle can build. \
146154 Make sure your crate has a binary target that uses a fully qualified `#[shuttle_runtime::main]`.",
0 commit comments