Skip to content

Conversation

@ylatuya
Copy link
Contributor

@ylatuya ylatuya commented Nov 24, 2022

Autotools-based project using libtool's -module flag generate plugins with the .so extension that needs to be treated like DynamicLibraries in terms of deployment location and relocation, except they are not linked to the app.

This PR depends on #16706

@rolfbjarne
Copy link
Member

rolfbjarne commented Nov 24, 2022

This PR depends on #16706

OK, let's wait for that one to be complete & merged then, which makes it easier to review and test these changes.

@rolfbjarne rolfbjarne self-assigned this Nov 24, 2022
@rolfbjarne
Copy link
Member

@ylatuya can you rebase this on main and fix the merge conflicts?

@ylatuya
Copy link
Contributor Author

ylatuya commented Dec 16, 2022

Sure! I will also create a new test for it.

@rolfbjarne rolfbjarne added the community Community contribution ❤ label Dec 19, 2022
@ylatuya
Copy link
Contributor Author

ylatuya commented Dec 22, 2022

Integration test added and rebased

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rolfbjarne
Copy link
Member

except they are not linked to the app.

Out of curiosity, why not? It seems to me that .dylibs and .so files should be treated the same way.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@ylatuya
Copy link
Contributor Author

ylatuya commented Dec 22, 2022

except they are not linked to the app.

Out of curiosity, why not? It seems to me that .dylibs and .so files should be treated the same way.

By definition, libtool modules are libraries that are meant to be dlopened: https://www.gnu.org/software/automake/manual/html_node/Libtool-Modules.html. It's usually plugins such as the SVG loader for gdk-pixbuf, GIO modules, GStreamer plugins, etc... that will be loaded at runtime on-demand.

Thinking about that, we might not want to treat all .dylib files the same way and we should probably add a special type for plugins. We don't want these library plugins linked to the application as it would incur in a huge memory footprint, but we still want them to be relocated/reidentified.

Using GStreamer as example, which ships its plugins as .dylib files (it no longer uses autotools/libtool), all those plugins will be linked to the application and loaded at runtime which would result in a huge memory footprint. Instead, those .dylib files should be identified as plugins and relocated/reidentified but not linked to the application, so that they are loaded by GStreamer itself on demand.

@ylatuya
Copy link
Contributor Author

ylatuya commented Jan 12, 2023

@rolfbjarne can you review this one please?

@rolfbjarne
Copy link
Member

/azp run

@rolfbjarne
Copy link
Member

@rolfbjarne can you review this one please?

Will do

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! It would be great if you could make a couple of minor improvements:

  1. Update the documentation in https://github.com/xamarin/xamarin-macios/blob/main/dotnet/BundleContents.md with the new behavior.
  2. Add a test case for *.so files to the BundleStructure test here:

@mandel-macaque
Copy link
Contributor

@ylatuya would be great to land this, can you address @rolfbjarne comment?

Some projects like GStreamer, GIO or GdkPixbuf provide plugins as
dynamic libraries that are loaded on demand at runtime. These libraries
have usually the .dylib extension except for autotools-based projects
using libtool's -module flag that generate libraries with the .so extension.
These libraries need to be re-identified and deployed but that are not
linked to the application.
@ylatuya
Copy link
Contributor Author

ylatuya commented Feb 1, 2023

I am still unable to run the complete test suite locally so I can't run test before pushing and I need to rely in the CI but

Are you able to build xamarin-macios locally? If so, what happens if you run make run-unit-tests in the tests/dotnet directory?

I am able to build xamarin-macios. When I run the tests with make run-unit-tests it takes a lot to build them, some might get stuck for minutes so I end up using TEST_FILTER="--filter BuildAndExecuteAppWithNativeDynamicLibrariesInPackageReference" I have also other errors in the build stage of some of the tests, I didn't have time to look deeper

I can't see the errors since the files are not publicly available.

This is the failure:

    Failed BuildAndExecuteAppWithNativeDynamicLibrariesInPackageReference(MacOSX,"osx-x64") [17 s]
    Error Message:
     There is a library
    Expected: file or directory exists
    But was:  "/Users/builder/azdo/_work/1/s/xamarin-macios/tests/dotnet/AppWithNativeDynamicLibrariesInPackageReference/macOS/bin/Debug/net7.0-macos/osx-x64/AppWithNativeDynamicLibrariesInPackageReference.app/Contents/MonoBundle/subdir/libtest.so"
    Stack Trace:
     at Xamarin.Tests.DotNetProjectTest.AssertThatDylibExistsAndIsReidentified(String appPath, String dylibRelPath) in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/dotnet/UnitTests/ProjectTest.cs:line 1246
     at Xamarin.Tests.DotNetProjectTest.BuildAndExecuteAppWithNativeDynamicLibrariesInPackageReference(ApplePlatform platform, String runtimeIdentifier) in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/dotnet/UnitTests/ProjectTest.cs:line 1221

I had a fix locally for this one that I forgot to commit.

What is the error of the other failing test? The BCL one?

@rolfbjarne
Copy link
Member

What is the error of the other failing test? The BCL one?

That's a random issue unrelated to your PR.

@ylatuya
Copy link
Contributor Author

ylatuya commented Feb 1, 2023

What is the error of the other failing test? The BCL one?

That's a random issue unrelated to your PR.

Ok! The failing test should be passing now.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking better and better! Just a few really minor things left now.

<!-- Bundled, not linked with, install_name_tool must have been executed -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NoneQ.so file you added doesn't seem to be used anywhere, so let's try to do that:

Suggested change
</ItemGroup>
<None Update="NoneQ.so">
<!-- Bundled, not linked with -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

this will require changes in the BundleStructureTest.cs file as well.

Copy link
Contributor Author

@ylatuya ylatuya Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried replicating the same structure as NoneQ, that has NoneQ.dylib and libNoneQ.dylib, so I created NoneQ.so and libNoneQ.so. It seems that NoneQ.dylib is not checked either and that's the reason why I simply added NoneQ.so. I though they just need to be there and simply ignored, since they are not real libraries, it's just a text file with the file extension.

@rolfbjarne
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 9a38405c7559c00a892959cf8d8e69acb6314381 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 9a38405c7559c00a892959cf8d8e69acb6314381 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1042.Monterey'
Hash: 9a38405c7559c00a892959cf8d8e69acb6314381 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 225 tests passed 🎉

Tests counts

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ introspection: All 8 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ mononative: All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 25 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 9a38405c7559c00a892959cf8d8e69acb6314381 [PR build]

@rolfbjarne rolfbjarne changed the title Add support for .so files [dotnet] Add support for .so files Feb 3, 2023
@rolfbjarne rolfbjarne merged commit 97ab148 into dotnet:main Feb 3, 2023
@rolfbjarne
Copy link
Member

Thanks a lot for your contribution!

@rolfbjarne
Copy link
Member

/sudo backport release/7.0.2xx

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Backport Job to branch release/7.0.2xx Created! The magic is happening here

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Hooray! Backport succeeded! Please see https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=7281842 for more details.

@ylatuya
Copy link
Contributor Author

ylatuya commented Feb 3, 2023

Thanks a lot for your contribution!

It was a great learning experience. Thanks a lot for your help during the process!

rolfbjarne pushed a commit that referenced this pull request Feb 6, 2023
Autotools-based project using libtool's -module flag generate plugins with the .so extension that needs to be treated like DynamicLibraries in terms of deployment location and relocation, except they are not linked to the app.

This PR depends on #16706

Backport of #16887

Co-authored-by: Andoni Morales Alastruey <ylatuya@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Community contribution ❤

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants