Skip to content

Conversation

@mattjohnsonpint
Copy link

@mattjohnsonpint mattjohnsonpint commented Nov 6, 2022

  • Supports either regular framework or xcframework files coming from nuget packages
  • Updates the Unzip task to properly create symbolic links, which may occur within resource zips containing xcframeworks (removed per comment)

Fixes #16571

@rolfbjarne

@mattjohnsonpint
Copy link
Author

@microsoft-github-policy-service agree

@mattjohnsonpint mattjohnsonpint changed the title Handle frameworks and binding packages in Hot Restart Handle frameworks and binding resource packages in Hot Restart Nov 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@mattjohnsonpint mattjohnsonpint requested review from rolfbjarne and removed request for mauroa November 8, 2022 02:15
@dalexsoto
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.

@dalexsoto
Copy link
Member

Looks like there is a build error going on

Build FAILED.

       "/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.MacDev.Tasks.sln" (default target) (1:2) ->
       "/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj" (default target) (4:6) ->
       (CoreCompile target) -> 
         /Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs(55,37): error CS1061: 'FileInfo' does not contain a definition for 'LinkTarget' and no accessible extension method 'LinkTarget' accepting a first argument of type 'FileInfo' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj]
         /Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs(68,15): error CS0117: 'Directory' does not contain a definition for 'CreateSymbolicLink' [/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj]
         /Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs(76,11): error CS0117: 'File' does not contain a definition for 'CreateSymbolicLink' [/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj]
         /Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Zip.cs(100,73): error CS1061: 'ZipArchiveEntry' does not contain a definition for 'ExternalAttributes' and no accessible extension method 'ExternalAttributes' accepting a first argument of type 'ZipArchiveEntry' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/azdo/_work/4/s/xamarin-macios/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj]

    4 Warning(s)
    4 Error(s)

@mattjohnsonpint
Copy link
Author

Am I not allowed to use .NET 6 APIs?

@mattjohnsonpint
Copy link
Author

mattjohnsonpint commented Nov 9, 2022

I added a net6.0 target, and updated the code to only extract symlinks for net6+. Is that allowed? Will the net6 version make its way to the correct package to be used by VS at runtime? I'm not set up to fully build and test end-to-end, nor can I see the azp build results, so I'm flying blind a bit here. I'd appreciate any assistance.

BTW - The other approach I considered would be to not rely on these new symlink APIs but instead to re-implement the readlink algorithm in C# to work directly against the zip archive. The result would be files on disk are always fully materialized, even if there's multiple copies of them. It is much more difficult than it seems though, as links can point to links, or contain links as portions of the path.

@rolfbjarne
Copy link
Member

So there are a few problems here:

I added a net6.0 target, and updated the code to only extract symlinks for net6+. Is that allowed?

Yes, it's allowed, but...

Will the net6 version make its way to the correct package to be used by VS at runtime?

No, not at the moment. We'll eventually get there, but we're not there yet.

BTW - The other approach I considered would be to not rely on these new symlink APIs but instead to re-implement the readlink algorithm in C# to work directly against the zip archive. The result would be files on disk are always fully materialized, even if there's multiple copies of them. It is much more difficult than it seems though, as links can point to links, or contain links as portions of the path.

Unfortunately there are a few problems here:

  • I believe Windows may require admin privileges to create symlinks in some cases.
  • I don't think the code that installs the app on the device knows about windows symlinks.

On the other hand I realize that zipped xcframeworks might contain symlinks that won't be needed (if they're for a different platform), so it certainly makes sense to find a solution here.

However, given that implementing and testing this solution is likely to take a while, my suggestion would be to split this PR in two: one PR that only adds Hot Restart support for (xc)frameworks and binding resource packages, and then another one that tackles the symlink problem.

From what you've done in this PR it looks like the first part would only contain changes to .props and .targets files, so that's much easier to test yourself (you can just change these files locally).

@mattjohnsonpint
Copy link
Author

OK, I will update this tomorrow and remove the zip changes.

Indeed in my own library, we only have symlink in the maccatalyst target. The ios target has none, and the zip extract finds them just fine. Since only the ios target is needed for hot restart, I think it is fine to not support symlinks for now.

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

Thanks! I'll have a look and see if I can write tests for this (and update the PR accordingly).

@mattjohnsonpint
Copy link
Author

Found and fixed a small but important bug with an extra trailing backslash, which was throwing off some subsequent checks such as creating the correct stamp file in the DynamicFrameworks folder.

@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 (Breaking changes)

Legacy Xamarin (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: b5e6db47a305c26f97208c4722b79c0dbb025f16 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1100.Monterey'
Hash: b5e6db47a305c26f97208c4722b79c0dbb025f16 [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: b5e6db47a305c26f97208c4722b79c0dbb025f16 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build] Test results 🚀

Test results

✅ All tests passed on VSTS: simulator tests.

🎉 All 223 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 23 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: $(GIT_HASH) [PR build]

@rolfbjarne rolfbjarne added the community Community contribution ❤ label Dec 21, 2022
@mandel-macaque
Copy link
Contributor

@rolfbjarne can you take a second view on this.

@rolfbjarne
Copy link
Member

@rolfbjarne can you take a second view on this.

Yes, I'm working on adding tests for this scenario.

Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

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

Awesome work! Once get the tests up we'll merge it! Thanks a lot @mattjohnsonpint ❤️

@mattjohnsonpint
Copy link
Author

Thanks! Now if we can just #16001 fixed, we'll have all the iOS on Windows stuff working well. 🙂

@rolfbjarne
Copy link
Member

Thanks! Now if we can just #16001 fixed, we'll have all the iOS on Windows stuff working well. 🙂

Yep, I'm working on that one together with adding a test case for this issue.

@rolfbjarne
Copy link
Member

So I wrote a test for this scenario, and it revealed that this wasn't as simple as we first thought - in fact it was much more complicated.

The good news is that I fixed all those issues, and the corresponding PR as been merged, so this PR is no longer needed (this means that xcframeworks and binding projects will finally work correctly with Hot Restart - but since the changes required were quite invasive, they won't be shipped until .NET 8. If you're willing to try a preview, they'll be available in the upcoming .NET 8 Preview 4).

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.

Hot Restart does not support xcframeworks or binding resource packages

6 participants