@@ -30,6 +30,17 @@ use crate::{lock::LockFile, wit::get_packages};
3030/// The name of the default registry.
3131pub const DEFAULT_REGISTRY_NAME : & str = "default" ;
3232
33+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
34+ pub enum DependencyKind {
35+ Component ,
36+ Wit ,
37+ }
38+
39+ impl Default for DependencyKind {
40+ fn default ( ) -> Self {
41+ Self :: Wit
42+ }
43+ }
3344// TODO: functions for resolving dependencies from a lock file
3445
3546/// Represents a WIT package dependency.
@@ -39,7 +50,7 @@ pub enum Dependency {
3950 Package ( RegistryPackage ) ,
4051
4152 /// The dependency is a path to a local directory or file.
42- Local ( PathBuf ) ,
53+ Local ( PathBuf , DependencyKind ) ,
4354}
4455
4556impl Serialize for Dependency {
@@ -68,13 +79,14 @@ impl Serialize for Dependency {
6879 . serialize ( serializer)
6980 }
7081 }
71- Self :: Local ( path) => {
82+ Self :: Local ( path, kind ) => {
7283 #[ derive( Serialize ) ]
7384 struct Entry < ' a > {
7485 path : & ' a PathBuf ,
86+ kind : & ' a DependencyKind ,
7587 }
7688
77- Entry { path } . serialize ( serializer)
89+ Entry { path, kind } . serialize ( serializer)
7890 }
7991 }
8092 }
@@ -112,30 +124,37 @@ impl<'de> Deserialize<'de> for Dependency {
112124 package : Option < PackageRef > ,
113125 version : Option < VersionReq > ,
114126 registry : Option < String > ,
127+ kind : DependencyKind ,
115128 }
116129
117130 let entry = Entry :: deserialize ( MapAccessDeserializer :: new ( map) ) ?;
118131
119- match ( entry. path , entry. package , entry. version , entry. registry ) {
120- ( Some ( path) , None , None , None ) => Ok ( Self :: Value :: Local ( path) ) ,
121- ( None , name, Some ( version) , registry) => {
132+ match (
133+ entry. path ,
134+ entry. package ,
135+ entry. version ,
136+ entry. registry ,
137+ entry. kind ,
138+ ) {
139+ ( Some ( path) , None , None , None , kind) => Ok ( Self :: Value :: Local ( path, kind) ) ,
140+ ( None , name, Some ( version) , registry, _) => {
122141 Ok ( Self :: Value :: Package ( RegistryPackage {
123142 name,
124143 version,
125144 registry,
126145 } ) )
127146 }
128- ( Some ( _) , None , Some ( _) , _) => Err ( de:: Error :: custom (
147+ ( Some ( _) , None , Some ( _) , _, _ ) => Err ( de:: Error :: custom (
129148 "cannot specify both `path` and `version` fields in a dependency entry" ,
130149 ) ) ,
131- ( Some ( _) , None , None , Some ( _) ) => Err ( de:: Error :: custom (
150+ ( Some ( _) , None , None , Some ( _) , _ ) => Err ( de:: Error :: custom (
132151 "cannot specify both `path` and `registry` fields in a dependency entry" ,
133152 ) ) ,
134- ( Some ( _) , Some ( _) , _, _) => Err ( de:: Error :: custom (
153+ ( Some ( _) , Some ( _) , _, _, _ ) => Err ( de:: Error :: custom (
135154 "cannot specify both `path` and `package` fields in a dependency entry" ,
136155 ) ) ,
137- ( None , None , _, _) => Err ( de:: Error :: missing_field ( "package" ) ) ,
138- ( None , Some ( _) , None , _) => Err ( de:: Error :: missing_field ( "version" ) ) ,
156+ ( None , None , _, _, _ ) => Err ( de:: Error :: missing_field ( "package" ) ) ,
157+ ( None , Some ( _) , None , _, _ ) => Err ( de:: Error :: missing_field ( "version" ) ) ,
139158 }
140159 }
141160 }
@@ -469,10 +488,8 @@ impl<'a> DependencyResolver<'a> {
469488 & mut self ,
470489 name : & PackageRef ,
471490 dependency : & Dependency ,
472- is_wit : bool ,
473491 ) -> Result < ( ) > {
474- self . add_dependency_internal ( name, dependency, false , is_wit)
475- . await
492+ self . add_dependency_internal ( name, dependency, false ) . await
476493 }
477494
478495 /// Add a dependency to the resolver. If the dependency already exists, then it will be
@@ -481,18 +498,15 @@ impl<'a> DependencyResolver<'a> {
481498 & mut self ,
482499 name : & PackageRef ,
483500 dependency : & Dependency ,
484- is_wit : bool ,
485501 ) -> Result < ( ) > {
486- self . add_dependency_internal ( name, dependency, true , is_wit)
487- . await
502+ self . add_dependency_internal ( name, dependency, true ) . await
488503 }
489504
490505 async fn add_dependency_internal (
491506 & mut self ,
492507 name : & PackageRef ,
493508 dependency : & Dependency ,
494509 force_override : bool ,
495- is_wit : bool ,
496510 ) -> Result < ( ) > {
497511 match dependency {
498512 Dependency :: Package ( package) => {
@@ -533,7 +547,7 @@ impl<'a> DependencyResolver<'a> {
533547 } ,
534548 ) ;
535549 }
536- Dependency :: Local ( p) => {
550+ Dependency :: Local ( p, kind ) => {
537551 // A local path dependency, insert a resolution immediately
538552 let res = DependencyResolution :: Local ( LocalResolution {
539553 name : name. clone ( ) ,
@@ -547,13 +561,15 @@ impl<'a> DependencyResolver<'a> {
547561
548562 // // Now that we check we haven't already inserted this dep, get the packages from the
549563 // // local dependency and add those to the resolver before adding the dependency
550- if is_wit {
564+ // if is_wit {
565+ if kind == & DependencyKind :: Wit {
551566 let ( _, packages) = get_packages ( p)
552567 . context ( "Error getting dependent packages from local dependency" ) ?;
553568 Box :: pin ( self . add_packages ( packages) )
554569 . await
555570 . context ( "Error adding packages to resolver for local dependency" ) ?;
556571 }
572+ // }
557573
558574 let prev = self . resolutions . insert ( name. clone ( ) , res) ;
559575 assert ! ( prev. is_none( ) ) ;
@@ -567,17 +583,16 @@ impl<'a> DependencyResolver<'a> {
567583 /// requirements to the resolver
568584 pub async fn add_packages (
569585 & mut self ,
570- packages : impl IntoIterator < Item = ( PackageRef , VersionReq , bool ) > ,
586+ packages : impl IntoIterator < Item = ( PackageRef , VersionReq ) > ,
571587 ) -> Result < ( ) > {
572- for ( package, req, is_wit ) in packages {
588+ for ( package, req) in packages {
573589 self . add_dependency (
574590 & package,
575591 & Dependency :: Package ( RegistryPackage {
576592 name : Some ( package. clone ( ) ) ,
577593 version : req,
578594 registry : None ,
579595 } ) ,
580- is_wit,
581596 )
582597 . await ?;
583598 }
0 commit comments