Skip to content

Commit

Permalink
[mono][wasm] Include NativeLibrary items to the NativeFileReference i…
Browse files Browse the repository at this point in the history
…tems (dotnet#101532)

* Include NativeLibary and add test case

* Move to common place

* Ignore missing NativeLibraries

* Move items copying into target
  • Loading branch information
mkhamoyan authored and Ruihan-Yin committed May 30, 2024
1 parent 4064150 commit 9271eac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,36 @@ public static int Main()
string cryptoInitMsg = "MONO_WASM: Initializing Crypto WebWorker";
Assert.DoesNotContain(cryptoInitMsg, output);
}

[Theory]
[BuildAndRun(aot: false)]
[BuildAndRun(aot: true)]
public void ProjectWithNativeLibrary(BuildArgs buildArgs, RunHost host, string id)
{
string projectName = $"AppUsingNativeLibrary-a";
buildArgs = buildArgs with { ProjectName = projectName };
buildArgs = ExpandBuildArgs(buildArgs, extraItems: "<NativeLibrary Include=\"native-lib.o\" />\n<NativeLibrary Include=\"DoesNotExist.o\" />");

if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? _))
{
InitPaths(id);
if (Directory.Exists(_projectDir))
Directory.Delete(_projectDir, recursive: true);

Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, "AppUsingNativeLib"), _projectDir);
File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "native-libs", "native-lib.o"), Path.Combine(_projectDir, "native-lib.o"));
}

BuildProject(buildArgs,
id: id,
new BuildProjectOptions(DotnetWasmFromRuntimePack: false));

string output = RunAndTestWasmApp(buildArgs, buildDir: _projectDir, expectedExitCode: 0,
test: output => {},
host: host, id: id);

Assert.Contains("print_line: 100", output);
Assert.Contains("from pinvoke: 142", output);
}
}
}
5 changes: 5 additions & 0 deletions src/mono/wasm/build/WasmApp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@
<_WasmShouldAOT Condition="'$(_WasmShouldAOT)' == ''">false</_WasmShouldAOT>
</PropertyGroup>

<ItemGroup>
<_ExistingNativeLibrary Include="@(NativeLibrary->Exists())" />
<NativeFileReference Include="@(_ExistingNativeLibrary->'%(Identity)')" />
</ItemGroup>

<ItemGroup Condition="'$(MicrosoftNetCoreAppRuntimePackRidLibTfmDir)' == ''">
<!-- find the path with the assemblies, so we don't have to hardcode the tfm.
Cannot use System.Private.Corelib since that is in a different directory -->
Expand Down

0 comments on commit 9271eac

Please sign in to comment.