Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][wasm] Include NativeLibrary items to the NativeFileReference items #101532

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -295,6 +295,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
Loading