SolvedImageSharp Maintain Xamarin iOS support by keeping the library "AOT-proof"
✔️Accepted Answer
Ok wrote a quick&dirty iOS app that loads all the images in the test suite, and didn't run into any AoT/JIT errors. Whatever error it was hitting must have been fixed in #949
@gameleon-dev If you want to send me the specific .png I can double check that it will work going forward.
Here is the sample app with output:
https://github.com/dmanning23/ImageSharpTest.iOS
Other Answers:
You should be good to go, I was able to load the attached image:
2019-08-07 17:24:44.794 ImageSharpTest.iOS[2745:131288] Testing Content/62653769-9175ed80-b95e-11e9-9a8d-348b071cb714.png
2019-08-07 17:24:45.439 ImageSharpTest.iOS[2745:131288] ... SUCCESS!
I had a similar problem with Unity Android IL2CPP, but I found a solution.
Xamarin iOS and Unity Android IL2CPP both work with Mono, so I think you can solve it the same way.
According to the Unity manual, you need to write a specific code to make a particular generic method work.
This should probably cache all interface methods that have generic methods.
For example, this part.
I wanted to shrink a large PNG image, so I created the following code.
/// <summary>
/// Because it calls an internal class, it needs to be placed inside the ImageSharp project.
/// </summary>
static class UnityAoT<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{
/// <summary>
/// call from <see cref="SixLabors.ImageSharp.Advanced.AotCompilerTools.Seed{TPixel}"/>
/// </summary>
internal static void UnitySeed()
{
AotCompileImageProcessor();
AotCompileResampler();
AotCompileEncoder();
}
private static void AotCompileEncoder()
{
default(PngEncoderCore).Encode<TPixel>(default, default, default);
}
private static void AotCompileImageProcessor()
{
AotCompilerPixelSpecifics<ResizeProcessor>();
}
private static void AotCompilerPixelSpecifics<TProc>()
where TProc : class, ICloningImageProcessor
{
default(TProc).CreatePixelSpecificCloningProcessor<TPixel>(default, default, default);
default(TProc).CreatePixelSpecificProcessor<TPixel>(default, default, default);
}
private static void AotCompileResampler()
{
AotCompileResamplers<BicubicResampler>();
}
private static void AotCompileResamplers<TResampler>()
where TResampler : struct, IResampler
{
// TODO : Methodize it.
default(ResizeProcessor<TPixel>).ApplyTransform<TResampler>(default);
default(TResampler).ApplyTransform(default(ResizeProcessor<TPixel>));
}
}
This is working fine, but doesn't allow me to do anything other than shrink.
I think we need to cache more methods to do all the processing.
Description
Xamarin iOS users need to be able to "seed" open-generic library API-s with the help of AotCompilerTools, otherwise it will lead to runtime exceptions on that platform.
Related: #767, #785, #776, #800
Problems
Currently we are struggling to maintain this feature because of the following reasons:
Conclusion
With our current prioritites and resources, the only way to maintain this feature is community support. If you can provide any help (add missing AOT seeds, or fix regressions), feel free to open a Pull Request!
Long term solution
If someone could define a mono AOT test configuration for appveyor, that would be ace.
/CC @vicfergar @davilovick @gameleon-dev @Lapinou42 @dmanning23 @swoolcock
EDIT
PS: Could someone do a favor and chack the latest MyGet dev builds from on Xamarin iOS? (JPEG, PNG, Resize, Quantization etc.)