1. We're not using Mono for macOS in .NET.
2. Even if we were, we're not using a system mono anymore, which means we can't run
into unexpected mono versions at runtime.
Add nullability attributes to the Runtime class and fix the code accordingly.
This snowballed a bit, because it ended up requiring changes in multiple other
classes. While at it, I also updated the code to:
* Use 'is' and 'is not' instead of '==' and '!=' for object identity.
* Use CFString.CreateNative/ReleaseNative instead of other means to create
native strings (the fasets and least memory hungry option).
* Use 'nameof (parameter)' instead of string constants.
* Update dependencies from https://github.com/dotnet/installer build 20211014.1
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21512.45 -> To Version 6.0.100-rtm.21514.1
* Update dependencies from https://github.com/dotnet/installer build 20211014.70
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21512.45 -> To Version 6.0.100-rtm.21514.70
* Update dependencies from https://github.com/dotnet/installer build 20211016.9
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21512.45 -> To Version 6.0.100-rtm.21516.9
* Update dependencies from https://github.com/dotnet/installer build 20211016.10
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21512.45 -> To Version 6.0.100-rtm.21516.10
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* Don't execute .NET tests in the 'legacy' targets (it's wasteful because
we're already executing those .NET tests elsewhere).
* Fix reporting failures in the legacy tests.
This makes it easier to iterate over the platforms we're building for, because
we can use "macOS" to compute the variable names we're interested in (like we
already can for iOS, tvOS, watchOS and MacCatalyst).
* Subclass NativeObject to reuse object lifetime code.
* Merge the CGDataProvider-2.cs file into the CGDataProvider.cs file.
* Enable nullability and fix code accordingly.
* Use 'is' and 'is not' instead of '==' and '!=' for object identity.
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21512.4 -> To Version 6.0.100-rtm.21512.45
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21508.19 -> To Version 6.0.100-rtm.21512.4
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* Create all INativeObject subclasses using 'Runtime.GetINativeObject<T>' instead
of 'new T ()'. Although it's somewhat slower, it automatically handles any IntPtr.Zero
handles, and it also makes the generator code simpler. If something turns out to
be a performance problem, we can always add custom static creation methods (like
some of the existing types already have).
* This makes it so that the zero pointer check logic in the generator isn't necessary
anymore.
* The most important part is where we use IntPtr as the marshalling type for returned
INativeObjects in blocks (instead of the INativeObject class - which doesn't make
sense really, because I have no idea how that's marshalled).
Example:
```diff
diff --git a/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs b/build-new/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
index 97e58f3a91b..8a40748de8b 100644
--- a/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
+++ b/build-new/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs
@@ -214,7 +214,7 @@ namespace ObjCRuntime {
} /* class NIDAVAudioEngineManualRenderingBlock */
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
[UserDelegateType (typeof (global::AVFoundation.AVAudioIONodeInputBlock))]
- internal delegate global::AudioToolbox.AudioBuffers DAVAudioIONodeInputBlock (IntPtr block, uint frameCount);
+ internal delegate IntPtr DAVAudioIONodeInputBlock (IntPtr block, uint frameCount);
//
// This class bridges native block invocations that call into C#
//
@@ -223,11 +223,11 @@ namespace ObjCRuntime {
[Preserve (Conditional = true)]
[global::System.Diagnostics.CodeAnalysis.DynamicDependency ("Handler")]
[MonoPInvokeCallback (typeof (DAVAudioIONodeInputBlock))]
- static unsafe global::AudioToolbox.AudioBuffers Invoke (IntPtr block, uint frameCount) {
+ static unsafe IntPtr Invoke (IntPtr block, uint frameCount) {
var descriptor = (BlockLiteral *) block;
var del = (global::AVFoundation.AVAudioIONodeInputBlock) (descriptor->Target);
AudioToolbox.AudioBuffers retval = del (frameCount);
- return retval;
+ return retval.GetHandle ();
}
} /* class SDAVAudioIONodeInputBlock */
internal sealed class NIDAVAudioIONodeInputBlock : TrampolineBlockBase {
@@ -249,7 +249,7 @@ namespace ObjCRuntime {
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
unsafe global::AudioToolbox.AudioBuffers Invoke (uint frameCount)
{
- var ret = invoker (BlockPointer, frameCount);
+ var ret = Runtime.GetINativeObject<global::AudioToolbox.AudioBuffers> (invoker (BlockPointer, frameCount), false);
return ret!;
}
} /* class NIDAVAudioIONodeInputBlock */
```
* Update dependencies from https://github.com/dotnet/installer build 20211007.9
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21506.22 -> To Version 6.0.100-rtm.21507.9
* Update dependencies from https://github.com/dotnet/installer build 20211008.19
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21506.22 -> To Version 6.0.100-rtm.21508.19
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Fixes: https://github.com/xamarin/xamarin-macios/issues/12955
Update the .NET 6 project templates to include "(Preview)" in the title
and include the "Mobile" classification where applicable. The phrase
".NET 6" has also been added to the description to help them stand out
from the regular Xamarin templates.
* Update dependencies from https://github.com/dotnet/installer build 20211004.5
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21480.21 -> To Version 6.0.100-rtm.21504.5
* Update dependencies from https://github.com/dotnet/installer build 20211005.64
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21480.21 -> To Version 6.0.100-rtm.21505.64
* [src] Bump bgen to .NET 6
* Update dependencies from https://github.com/dotnet/installer build 20211006.22
Microsoft.Dotnet.Sdk.Internal
From Version 6.0.100-rtm.21480.21 -> To Version 6.0.100-rtm.21506.22
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
I had to change the first argument from 'string' to 'IntPtr', because 'string'
isn't blittable. In order to diverge the code paths as little as possible, I
also made this change for the legacy Xamarin version.
Ref https://github.com/xamarin/xamarin-macios/issues/10470.
* Add an (IntPtr, bool) constructor so that AudioUnit works with Runtime.GetINativeObject.
* Keep track of ownership, so that AudioUnit doesn't free the native resources
when it doesn't own them.
* Update a test to verify that calling 'AVAudioIONode.AudioUnit' multiple
times and disposing the result between them works (this fails if AudioUnit
doesn't keep track of ownership).
Now that macOS runs on ARM64 (and also the simulators soon), we need to have to same logic for all platforms.
Fixes:
Introspection.iOSApiPInvokeTest
[FAIL] Could not find the field 'objc_msgSend_stret' in /usr/lib/libobjc.dylib
[FAIL] Could not find the field 'objc_msgSendSuper_stret' in /usr/lib/libobjc.dylib
[FAIL] SymbolExists : 2 errors found in 5300 functions validated: objc_msgSend_stret, objc_msgSendSuper_stret
Expected: 0
But was: 2
at Introspection.ApiPInvokeTest.SymbolExists() in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/introspection/ApiPInvokeTest.cs:line 182
Fixes this when running our test suites on macOS 10.14:
dyld: Library not loaded: /System/Library/Frameworks/AuthenticationServices.framework/Versions/A/AuthenticationServices
Referenced from: /Users/runner/work/1/s/artifacts/mac-test-package/tests/./introspection/dotnet/macOS/bin/Debug/net6.0-macos/osx-x64/introspection.app/Contents/MacOS/introspection
Reason: image not found
make[2]: *** [exec-mac-dotnet-x64-introspection] Abort trap: 6
Fixes warnings such as these:
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(coreclr-bridge-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(runtime-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(bindings-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(bindings-generated-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(xamarin-support-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(shared-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(trampolines-invoke-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(nsstring-localization-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(monotouch-main-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(trampolines-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(monotouch-debug-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
ld: warning: object file ([...]/libxamarin-dotnet-coreclr-debug.a(trampolines-x86_64-dotnet-coreclr-debug.x86_64.o)) was built for newer macOS version (11.0) than being linked (10.15)
Return a non-zero exit code if tests fail on older macOS versions, but keep
running tests. This way the step shows up as orange if something fails (and
not green, which is confusing).