Skip to content

Commit cab2d11

Browse files
authored
[mono][wasm] Include NativeLibrary items to the NativeFileReference items (#101532)
* Include NativeLibary and add test case * Move to common place * Ignore missing NativeLibraries * Move items copying into target
1 parent 4c14fb0 commit cab2d11

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs

+31
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,36 @@ public static int Main()
136136
string cryptoInitMsg = "MONO_WASM: Initializing Crypto WebWorker";
137137
Assert.DoesNotContain(cryptoInitMsg, output);
138138
}
139+
140+
[Theory]
141+
[BuildAndRun(aot: false)]
142+
[BuildAndRun(aot: true)]
143+
public void ProjectWithNativeLibrary(BuildArgs buildArgs, RunHost host, string id)
144+
{
145+
string projectName = $"AppUsingNativeLibrary-a";
146+
buildArgs = buildArgs with { ProjectName = projectName };
147+
buildArgs = ExpandBuildArgs(buildArgs, extraItems: "<NativeLibrary Include=\"native-lib.o\" />\n<NativeLibrary Include=\"DoesNotExist.o\" />");
148+
149+
if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? _))
150+
{
151+
InitPaths(id);
152+
if (Directory.Exists(_projectDir))
153+
Directory.Delete(_projectDir, recursive: true);
154+
155+
Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, "AppUsingNativeLib"), _projectDir);
156+
File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "native-libs", "native-lib.o"), Path.Combine(_projectDir, "native-lib.o"));
157+
}
158+
159+
BuildProject(buildArgs,
160+
id: id,
161+
new BuildProjectOptions(DotnetWasmFromRuntimePack: false));
162+
163+
string output = RunAndTestWasmApp(buildArgs, buildDir: _projectDir, expectedExitCode: 0,
164+
test: output => {},
165+
host: host, id: id);
166+
167+
Assert.Contains("print_line: 100", output);
168+
Assert.Contains("from pinvoke: 142", output);
169+
}
139170
}
140171
}

src/mono/wasm/build/WasmApp.Common.targets

+5
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@
297297
<_WasmShouldAOT Condition="'$(_WasmShouldAOT)' == ''">false</_WasmShouldAOT>
298298
</PropertyGroup>
299299

300+
<ItemGroup>
301+
<_ExistingNativeLibrary Include="@(NativeLibrary->Exists())" />
302+
<NativeFileReference Include="@(_ExistingNativeLibrary->'%(Identity)')" />
303+
</ItemGroup>
304+
300305
<ItemGroup Condition="'$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)' == ''">
301306
<!-- find the path with the assemblies, so we don't have to hardcode the tfm.
302307
Cannot use System.Private.Corelib since that is in a different directory -->

0 commit comments

Comments
 (0)