@@ -5,24 +5,26 @@ use anyhow::{anyhow, bail, Result};
5
5
use cargo_toml:: { Manifest , Product } ;
6
6
use config:: Config ;
7
7
use semver:: Version ;
8
- use std:: { fs, path:: PathBuf } ;
8
+ use serde:: Deserialize ;
9
+ use std:: { fmt:: Display , fs, path:: PathBuf } ;
9
10
10
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone ) ]
11
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone ) ]
11
12
#[ serde( rename_all = "snake_case" ) ]
12
13
pub enum LanguageConfig {
13
14
Rust ( RustConfig ) ,
14
15
TinyGo ( TinyGoConfig ) ,
15
16
}
16
17
17
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone ) ]
18
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone ) ]
18
19
#[ serde( rename_all = "snake_case" ) ]
19
20
pub enum TypeConfig {
20
21
Actor ( ActorConfig ) ,
21
22
Provider ( ProviderConfig ) ,
22
23
Interface ( InterfaceConfig ) ,
23
24
}
24
25
25
- #[ derive( serde:: Deserialize , Debug , Clone ) ]
26
+ /// Project configuration, normally specified in the root keys of a wasmcloud.toml file
27
+ #[ derive( Deserialize , Debug , Clone ) ]
26
28
pub struct ProjectConfig {
27
29
/// The language of the project, e.g. rust, tinygo. Contains specific configuration for that language.
28
30
pub language : LanguageConfig ,
@@ -34,7 +36,7 @@ pub struct ProjectConfig {
34
36
pub common : CommonConfig ,
35
37
}
36
38
37
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
39
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
38
40
pub struct ActorConfig {
39
41
/// The list of provider claims that this actor requires. eg. ["wasmcloud:httpserver", "wasmcloud:blobstore"]
40
42
pub claims : Vec < String > ,
@@ -47,11 +49,12 @@ pub struct ActorConfig {
47
49
/// The filename of the signed wasm actor.
48
50
pub filename : Option < String > ,
49
51
/// The target wasm target to build for. Defaults to "wasm32-unknown-unknown".
50
- pub wasm_target : String ,
52
+ pub wasm_target : WasmTarget ,
51
53
/// The call alias of the actor.
52
54
pub call_alias : Option < String > ,
53
55
}
54
- #[ derive( serde:: Deserialize , Debug , PartialEq ) ]
56
+
57
+ #[ derive( Deserialize , Debug , PartialEq ) ]
55
58
struct RawActorConfig {
56
59
/// The list of provider claims that this actor requires. eg. ["wasmcloud:httpserver", "wasmcloud:blobstore"]
57
60
pub claims : Option < Vec < String > > ,
@@ -83,19 +86,20 @@ impl TryFrom<RawActorConfig> for ActorConfig {
83
86
filename : raw_config. filename ,
84
87
wasm_target : raw_config
85
88
. wasm_target
86
- . unwrap_or_else ( || "wasm32-unknown-unknown" . to_string ( ) ) ,
89
+ . map ( WasmTarget :: from)
90
+ . unwrap_or_default ( ) ,
87
91
call_alias : raw_config. call_alias ,
88
92
} )
89
93
}
90
94
}
91
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
95
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
92
96
pub struct ProviderConfig {
93
97
/// The capability ID of the provider.
94
98
pub capability_id : String ,
95
99
/// The vendor name of the provider.
96
100
pub vendor : String ,
97
101
}
98
- #[ derive( serde :: Deserialize , Debug , PartialEq ) ]
102
+ #[ derive( Deserialize , Debug , PartialEq ) ]
99
103
struct RawProviderConfig {
100
104
/// The capability ID of the provider.
101
105
pub capability_id : String ,
@@ -114,14 +118,14 @@ impl TryFrom<RawProviderConfig> for ProviderConfig {
114
118
}
115
119
}
116
120
117
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
121
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
118
122
pub struct InterfaceConfig {
119
123
/// Directory to output HTML.
120
124
pub html_target : PathBuf ,
121
125
/// Path to codegen.toml file.
122
126
pub codegen_config : PathBuf ,
123
127
}
124
- #[ derive( serde :: Deserialize , Debug , PartialEq ) ]
128
+ #[ derive( Deserialize , Debug , PartialEq ) ]
125
129
126
130
struct RawInterfaceConfig {
127
131
/// Directory to output HTML. Defaults to "./html".
@@ -145,15 +149,27 @@ impl TryFrom<RawInterfaceConfig> for InterfaceConfig {
145
149
}
146
150
}
147
151
148
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
152
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
149
153
pub struct RustConfig {
150
154
/// The path to the cargo binary. Optional, will default to search the user's `PATH` for `cargo` if not specified.
151
155
pub cargo_path : Option < PathBuf > ,
152
156
/// Path to cargo/rust's `target` directory. Optional, defaults to the cargo target directory for the workspace or project.
153
157
pub target_path : Option < PathBuf > ,
154
158
}
155
159
156
- #[ derive( serde:: Deserialize , Debug , PartialEq , Default , Clone ) ]
160
+ impl RustConfig {
161
+ pub fn build_target ( & self , wasm_target : & WasmTarget ) -> & ' static str {
162
+ match wasm_target {
163
+ WasmTarget :: CoreModule => "wasm32-unknown-unknown" ,
164
+ // NOTE: eventually "wasm32-wasi" will be renamed to "wasm32-wasi-preview1"
165
+ // https://github.com/rust-lang/compiler-team/issues/607
166
+ WasmTarget :: WasiPreview1 => "wasm32-wasi" ,
167
+ WasmTarget :: WasiPreview2 => "wasm32-wasi-preview2" ,
168
+ }
169
+ }
170
+ }
171
+
172
+ #[ derive( Deserialize , Debug , PartialEq , Default , Clone ) ]
157
173
struct RawRustConfig {
158
174
/// The path to the cargo binary. Optional, will default to search the user's `PATH` for `cargo` if not specified.
159
175
pub cargo_path : Option < PathBuf > ,
@@ -173,7 +189,7 @@ impl TryFrom<RawRustConfig> for RustConfig {
173
189
}
174
190
175
191
/// Configuration common amoung all project types & languages.
176
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone ) ]
192
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone ) ]
177
193
pub struct CommonConfig {
178
194
/// Name of the project.
179
195
pub name : String ,
@@ -186,7 +202,45 @@ pub struct CommonConfig {
186
202
pub wasm_bin_name : Option < String > ,
187
203
}
188
204
189
- #[ derive( serde:: Deserialize , Debug ) ]
205
+ #[ derive( Debug , Deserialize , Default , Clone , Eq , PartialEq ) ]
206
+ pub enum WasmTarget {
207
+ #[ default]
208
+ #[ serde( alias = "wasm32-unknown-unknown" ) ]
209
+ CoreModule ,
210
+ #[ serde( alias = "wasm32-wasi" , alias = "wasm32-wasi-preview1" ) ]
211
+ WasiPreview1 ,
212
+ #[ serde( alias = "wasm32-wasi-preview2" ) ]
213
+ WasiPreview2 ,
214
+ }
215
+
216
+ impl From < & str > for WasmTarget {
217
+ fn from ( value : & str ) -> Self {
218
+ match value {
219
+ "wasm32-wasi-preview1" => WasmTarget :: WasiPreview1 ,
220
+ "wasm32-wasi" => WasmTarget :: WasiPreview1 ,
221
+ "wasm32-wasi-preview2" => WasmTarget :: WasiPreview2 ,
222
+ _ => WasmTarget :: CoreModule ,
223
+ }
224
+ }
225
+ }
226
+
227
+ impl From < String > for WasmTarget {
228
+ fn from ( value : String ) -> Self {
229
+ value. as_str ( ) . into ( )
230
+ }
231
+ }
232
+
233
+ impl Display for WasmTarget {
234
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
235
+ f. write_str ( match & self {
236
+ WasmTarget :: CoreModule => "wasm32-unknown-unknown" ,
237
+ WasmTarget :: WasiPreview1 => "wasm32-wasi" ,
238
+ WasmTarget :: WasiPreview2 => "wasm32-wasi-preview2" ,
239
+ } )
240
+ }
241
+ }
242
+
243
+ #[ derive( Deserialize , Debug ) ]
190
244
struct RawProjectConfig {
191
245
/// The language of the project, e.g. rust, tinygo. This is used to determine which config to parse.
192
246
pub language : String ,
@@ -205,13 +259,13 @@ struct RawProjectConfig {
205
259
pub tinygo : Option < RawTinyGoConfig > ,
206
260
}
207
261
208
- #[ derive( serde :: Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
262
+ #[ derive( Deserialize , Debug , PartialEq , Eq , Clone , Default ) ]
209
263
pub struct TinyGoConfig {
210
264
/// The path to the tinygo binary. Optional, will default to `tinygo` if not specified.
211
265
pub tinygo_path : Option < PathBuf > ,
212
266
}
213
267
214
- #[ derive( serde :: Deserialize , Debug , PartialEq , Default ) ]
268
+ #[ derive( Deserialize , Debug , PartialEq , Default ) ]
215
269
struct RawTinyGoConfig {
216
270
/// The path to the tinygo binary. Optional, will default to `tinygo` if not specified.
217
271
pub tinygo_path : Option < PathBuf > ,
0 commit comments