1
1
// TODO: Implement tests similar to the other generators.
2
2
// This requires that we have any dependencies either included here or published to NuGet or similar.
3
- use std:: path:: Path ;
3
+ use std:: {
4
+ env, fs,
5
+ path:: { Path , PathBuf } ,
6
+ process:: { Command , Stdio } ,
7
+ } ;
4
8
use wit_component:: StringEncoding ;
5
9
6
10
macro_rules! codegen_test {
@@ -31,6 +35,7 @@ macro_rules! codegen_test {
31
35
"lists" ,
32
36
"many-arguments" ,
33
37
"multi-return" ,
38
+ "multiversion" ,
34
39
"option-result" ,
35
40
"records" ,
36
41
"rename-interface" ,
@@ -47,11 +52,14 @@ macro_rules! codegen_test {
47
52
"result-empty" ,
48
53
"ret-areas" ,
49
54
"return-resource-from-export" ,
55
+ "same-names2" ,
50
56
"same-names5" ,
51
57
"simple-functions" ,
52
58
"simple-http" ,
53
59
"simple-lists" ,
54
60
"small-anonymous" ,
61
+ "smoke-default" ,
62
+ "strings" ,
55
63
"unused-import" ,
56
64
"use-across-interfaces" ,
57
65
"variants" ,
@@ -77,6 +85,165 @@ macro_rules! codegen_test {
77
85
}
78
86
test_helpers:: codegen_tests!( ) ;
79
87
80
- fn verify ( _dir : & Path , _name : & str ) {
81
- // TODO?
88
+ fn verify ( dir : & Path , name : & str ) {
89
+ #[ cfg( all( target_os = "windows" , feature = "aot" ) ) ]
90
+ aot_verify ( dir, name) ;
91
+ }
92
+
93
+ fn aot_verify ( dir : & Path , name : & str ) {
94
+ let mut wasm_filename = dir. join ( name) ;
95
+ wasm_filename. set_extension ( "wasm" ) ;
96
+
97
+ fs:: write (
98
+ dir. join ( "nuget.config" ) ,
99
+ r#"<?xml version="1.0" encoding="utf-8"?>
100
+ <configuration>
101
+ <config>
102
+ <add key="globalPackagesFolder" value=".packages" />
103
+ </config>
104
+ <packageSources>
105
+ <!--To inherit the global NuGet package sources remove the <clear/> line below -->
106
+ <clear />
107
+ <add key="nuget" value="https://api.nuget.org/v3/index.json" />
108
+ <add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
109
+ <!--<add key="dotnet-experimental" value="C:\github\runtimelab\artifacts\packages\Debug\Shipping" />-->
110
+ </packageSources>
111
+ </configuration>"# ,
112
+ ) . unwrap ( ) ;
113
+
114
+ fs:: write (
115
+ dir. join ( "rd.xml" ) ,
116
+ format ! (
117
+ r#"<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
118
+ <Application>
119
+ <Assembly Name="{name}">
120
+ </Assembly>
121
+ </Application>
122
+ </Directives>"#
123
+ ) ,
124
+ )
125
+ . unwrap ( ) ;
126
+
127
+ let mut csproj = format ! (
128
+ "<Project Sdk=\" Microsoft.NET.Sdk\" >
129
+
130
+ <PropertyGroup>
131
+ <TargetFramework>net8.0</TargetFramework>
132
+ <LangVersion>preview</LangVersion>
133
+ <RootNamespace>{name}</RootNamespace>
134
+ <ImplicitUsings>enable</ImplicitUsings>
135
+ <Nullable>enable</Nullable>
136
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
137
+ </PropertyGroup>
138
+
139
+ <PropertyGroup>
140
+ <PublishTrimmed>true</PublishTrimmed>
141
+ <AssemblyName>{name}</AssemblyName>
142
+ </PropertyGroup>
143
+ "
144
+ ) ;
145
+
146
+ csproj. push_str (
147
+ r#"
148
+ <ItemGroup>
149
+ <RdXmlFile Include="rd.xml" />
150
+ </ItemGroup>
151
+
152
+ "# ,
153
+ ) ;
154
+
155
+ csproj. push_str ( "\t <ItemGroup>\n " ) ;
156
+ csproj. push_str ( & format ! (
157
+ "\t \t <NativeLibrary Include=\" the_world_component_type.o\" />\n "
158
+ ) ) ;
159
+ csproj. push_str ( "\t </ItemGroup>\n \n " ) ;
160
+
161
+ csproj. push_str (
162
+ r#"
163
+ <ItemGroup>
164
+ <CustomLinkerArg Include="-Wl,--export,_initialize" />
165
+ <CustomLinkerArg Include="-Wl,--no-entry" />
166
+ <CustomLinkerArg Include="-mexec-model=reactor" />
167
+ </ItemGroup>
168
+ "# ,
169
+ ) ;
170
+
171
+ // In CI we run out of disk space if we don't clean up the files, we don't need to keep any of it around.
172
+ csproj. push_str ( & format ! (
173
+ "<Target Name=\" CleanAndDelete\" AfterTargets=\" Clean\" >
174
+ <!-- Remove obj folder -->
175
+ <RemoveDir Directories=\" $(BaseIntermediateOutputPath)\" />
176
+ <!-- Remove bin folder -->
177
+ <RemoveDir Directories=\" $(BaseOutputPath)\" />
178
+ <RemoveDir Directories=\" {}\" />
179
+ <RemoveDir Directories=\" .packages\" />
180
+ </Target>
181
+
182
+ " ,
183
+ wasm_filename. display( )
184
+ ) ) ;
185
+
186
+ csproj. push_str (
187
+ r#"
188
+ <ItemGroup>
189
+ <PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" Version="8.0.0-*" />
190
+ <PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="8.0.0-*" />
191
+ </ItemGroup>
192
+ </Project>
193
+ "# ,
194
+ ) ;
195
+
196
+ fs:: write ( dir. join ( format ! ( "{name}.csproj" ) ) , csproj) . unwrap ( ) ;
197
+
198
+ let dotnet_root_env = "DOTNET_ROOT" ;
199
+ let dotnet_cmd: PathBuf ;
200
+ match env:: var ( dotnet_root_env) {
201
+ Ok ( val) => dotnet_cmd = Path :: new ( & val) . join ( "dotnet" ) ,
202
+ Err ( _e) => dotnet_cmd = "dotnet" . into ( ) ,
203
+ }
204
+
205
+ let mut cmd = Command :: new ( dotnet_cmd. clone ( ) ) ;
206
+
207
+ cmd. current_dir ( & dir) ;
208
+
209
+ // add .arg("/bl") to diagnose dotnet build problems
210
+ cmd. arg ( "build" )
211
+ . arg ( dir. join ( format ! ( "{name}.csproj" ) ) )
212
+ . arg ( "-r" )
213
+ . arg ( "wasi-wasm" )
214
+ . arg ( "-c" )
215
+ . arg ( "Debug" )
216
+ . arg ( "/p:PlatformTarget=AnyCPU" )
217
+ . arg ( "/p:MSBuildEnableWorkloadResolver=false" )
218
+ . arg ( "--self-contained" )
219
+ . arg ( "/p:UseAppHost=false" )
220
+ . arg ( "-o" )
221
+ . arg ( & wasm_filename) ;
222
+ let output = match cmd. output ( ) {
223
+ Ok ( output) => output,
224
+ Err ( e) => panic ! ( "failed to spawn compiler: {}" , e) ,
225
+ } ;
226
+
227
+ if !output. status . success ( ) {
228
+ println ! ( "status: {}" , output. status) ;
229
+ println ! ( "stdout: ------------------------------------------" ) ;
230
+ println ! ( "{}" , String :: from_utf8_lossy( & output. stdout) ) ;
231
+ println ! ( "stderr: ------------------------------------------" ) ;
232
+ println ! ( "{}" , String :: from_utf8_lossy( & output. stderr) ) ;
233
+ panic ! ( "failed to compile" ) ;
234
+ }
235
+
236
+ let mut cmd = Command :: new ( dotnet_cmd) ;
237
+ match cmd
238
+ . stdout ( Stdio :: null ( ) )
239
+ . current_dir ( & dir)
240
+ . arg ( "clean" )
241
+ . spawn ( )
242
+ {
243
+ Err ( e) => println ! (
244
+ "failed to clean project which may cause disk pressure in CI. {}" ,
245
+ e
246
+ ) ,
247
+ _ => { }
248
+ }
82
249
}
0 commit comments