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

Make use of a specific iOS + MacCatalyst TFM #2243

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

bijington
Copy link
Contributor

@bijington bijington commented Oct 1, 2024

Description of Change

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

@brminnick
Copy link
Collaborator

brminnick commented Oct 1, 2024

Hey Shaun! Two quick thoughts:

  1. If we make this change for iOS, let's also do it for MacCatalyst too
  2. Is it possible to create unit test that validates this fixes the NativeAOT/Trimming bugs?
    • We may need to first merge the Device Tests PR
    • If you can figure out how to get CI / CD pipeline working for the Device Tests PR, we can merge it now to help you complete this bug fix
      • i.e. We don't need to write a complete DeviceTest suite in order to first merge the Device Tests PR

(Also - If this is PR still a work-in-progress, could you flip it to be a Draft PR please? I get distracted by shiny new PRs and want to review them, but I wait when the PR is still in Draft.)

@bijington
Copy link
Contributor Author

Hey Shaun! Two quick thoughts:

  1. If we make this change for iOS, let's also do it for MacCatalyst too

  2. Is it possible to create unit test that validates this fixes the NativeAOT/Trimming bugs?

    • We may need to first merge the Device Tests PR

    • If you can figure out how to get CI / CD pipeline working for the Device Tests PR, we can merge it now to help you complete this bug fix

      • i.e. We don't need to write a complete DeviceTest suite in order to first merge the Device Tests PR

(Also - If this is PR still a work-in-progress, could you flip it to be a Draft PR please? I get distracted by shiny new PRs and want to review them, but I wait when the PR is still in Draft.)

This isn't aimed at fixing any NativeAOT or Trimming bugs but aimed at the TypeLoadException due to mismatched TFMs when developers consume our library. Based on this issue/discussion xamarin/xamarin-macios#21335
I mostly just wanted to see if it would build for now which it does not.

I'll be happy to work on any possible testing options although I am not sure how we can right now.

@bijington bijington added the needs discussion Discuss it on the next Monthly standup label Oct 1, 2024
@bijington
Copy link
Contributor Author

I am actually starting to wonder whether this might also fix other issues such as #1374 based on this documentation page https://learn.microsoft.com/en-us/dotnet/standard/frameworks#precedence I read it as apps could be built targeting net8.0 support as this may be closer to what the developer is targeting. It's either going to help or make it worse...

@bijington bijington marked this pull request as ready for review October 1, 2024 20:18
@bijington
Copy link
Contributor Author

bijington commented Oct 2, 2024

@brminnick I'm not convinced we can create a unit test for this. I do wonder if we could add something to the pipeline to make sure that the packaged information meets what we expect. What do you think?

@brminnick
Copy link
Collaborator

Let's chat about it in tomorrow's standup!

I'm fairly confident that as long as we set up our CI / CD pipeline correctly to match our targeted frameworks and run the Device Tests in RELEASE configuration with NativeAOT enabled, <PublishAot>true</PublishAot>, it should replicate any errors our users are experiencing.

@filipnavara
Copy link
Contributor

We can replicate the error in a CI pipelines but it’s not straightforward. The latest breakage required .NET 9 RC SDK installed side-by-side to trigger it. Alternatively you can deliberately install old (fixed) workload set instead of the latest one. The trouble with that is that you either need to use custom manifests or start with 8.0.4xx SDK which introduced the workload set support.

@bijington
Copy link
Contributor Author

I was thinking of just inspecting the nuget package generated and verifying it targets the expected TFMs for Apple platforms

@bijington
Copy link
Contributor Author

I guess a nice test would be to try consuming the nightly build and see if that still exhibits the issue. I've not be able to reproduce the issue @filipnavara is this something that you could easily test/verify?

@filipnavara
Copy link
Contributor

filipnavara commented Oct 2, 2024

I guess a nice test would be to try consuming the nightly build and see if that still exhibits the issue. I've not be able to reproduce the issue @filipnavara is this something that you could easily test/verify?

Nightly build of what? CommunityToolkit.Maui? If you have a link I can test the scenarios easily and report back.

I assume I just need to use this feed:

    <add key="CommunityToolkit-PullRequests" value="https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-PullRequests/nuget/v3/index.json" />

...and then reference the build number from this PR, right?

@bijington
Copy link
Contributor Author

There might be a neater way but I have just knocked up a little console app that could be published as a dotnet tool to perform this verification. The code is:

using System.IO.Compression;
using CommandLine;

namespace PackageVerifier;

class Program
{
    static void Main(string[] args)
    {
        Parser.Default.ParseArguments<Options>(args)
            .WithParsed<Options>(o =>
            {
                Console.WriteLine($"Verifying package '{o.PackagePath}'");

                var extractDirectory = Path.Join(Environment.CurrentDirectory, "abc");
                Console.WriteLine($@"Extracting package to directory '{extractDirectory}'");
                
                ZipFile.ExtractToDirectory(o.PackagePath, extractDirectory);

                Console.WriteLine($"Checking for TFMs: '{string.Join(',', o.TargetFrameworkMonikers)}'");
                
                var libDirectory = Path.Join(extractDirectory, "lib");
                var directories = new DirectoryInfo(libDirectory).GetDirectories().Select(x => x.Name).ToList();

                foreach (var unexpectedDirectory in directories.Except(o.TargetFrameworkMonikers))
                {
                    Console.WriteLine($"WARNING: TFM '{unexpectedDirectory}' was not expected");
                }
                
                foreach (var unexpectedDirectory in o.TargetFrameworkMonikers.Except(directories))
                {
                    Console.WriteLine($"ERROR: TFM '{unexpectedDirectory}' is missing");
                }
                
                foreach (var unexpectedDirectory in o.TargetFrameworkMonikers.Intersect(directories))
                {
                    Console.WriteLine($"SUCCESS: Expected TFM '{unexpectedDirectory}' exists");
                }
            });
    }
}

Usage is something like:

dotnet packageverifier --tfms "net9.0-ios17.5" --package-path "/Users/shaunlawrence/Documents/work/projects/toolkits/mct/src/Maui/src/CommunityToolkit.Maui/bin/Release/CommunityToolkit.Maui.1.0.0-pre1.nupkg.zip"

And the output currently looks something like:

Verifying package '/Users/shaunlawrence/Documents/work/projects/toolkits/mct/src/Maui/src/CommunityToolkit.Maui/bin/Release/CommunityToolkit.Maui.1.0.0-pre1.nupkg.zip'
Extracting package to directory '/Users/shaunlawrence/Documents/work/projects/investigations/PackageVerifier/PackageVerifier/bin/Debug/net8.0/abc'
Checking for TFMs: 'net9.0-ios17.5'
WARNING: TFM 'net9.0-maccatalyst17.5' was not expected
WARNING: TFM 'net9.0' was not expected
WARNING: TFM 'net9.0-android35.0' was not expected
SUCCESS: Expected TFM 'net9.0-ios17.5' exists

With a bit more effort it could be modified to be more user friendly and allow it to cause a pipeline build to fail. What do you think?

@bijington
Copy link
Contributor Author

I guess a nice test would be to try consuming the nightly build and see if that still exhibits the issue. I've not be able to reproduce the issue @filipnavara is this something that you could easily test/verify?

Nightly build of what? CommunityToolkit.Maui? If you have a link I can test the scenarios easily and report back.

I assume I just need to use this feed:

    <add key="CommunityToolkit-PullRequests" value="https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-PullRequests/nuget/v3/index.json" />

...and then reference the build number from this PR, right?

Yes that looks like it is the correct feed and approach for the build number as per here https://github.com/CommunityToolkit/Maui/wiki/Preview-Packages#pull-requests-

Let me find the build number

@filipnavara
Copy link
Contributor

Let me find the build number

99.0.0-build-2243.110238+e95e119 .. no need, it's in the Checks.

@filipnavara
Copy link
Contributor

Yes, I can confirm that with .NET 9 RC 1 SDK I now get the correct iOS assets. With 9.1.0 on NuGet.org I get the generic net8.0 assets.

@bijington
Copy link
Contributor Author

Yes, I can confirm that with .NET 9 RC 1 SDK I now get the correct iOS assets. With 9.1.0 on NuGet.org I get the generic net8.0 assets.

That's fantastic news! Thank you so much for testing this and all of the input to get us to this stage!

@filipnavara
Copy link
Contributor

Thank you so much for testing this and all of the input to get us to this stage!

Thanks for addressing it so quickly. :-) Let me know if there's anything else you need to test.

@bijington
Copy link
Contributor Author

I have had some fun playing around with this so I have stuck it in a GitHub repo: https://github.com/bijington/package-verifier

@brminnick brminnick changed the title Make use of a specific ios version in the TFM Make use of a specific iOS + MacCatalyst TFM Oct 3, 2024
@brminnick brminnick added the hacktoberfest-accepted A PR that has been approved during Hacktoberfest label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted A PR that has been approved during Hacktoberfest needs discussion Discuss it on the next Monthly standup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Could not set up parent class, due to: Invalid generic instantiation
5 participants