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

[build] Target net9.0 #1279

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>
<!-- Disables the transitive restore of packages like Microsoft.AspNetCore.App.Ref, Microsoft.WindowsDesktop.App.Ref -->
<DisableTransitiveFrameworkReferenceDownloads>true</DisableTransitiveFrameworkReferenceDownloads>
<DotNetTargetFrameworkVersion>8.0</DotNetTargetFrameworkVersion>
<DotNetTargetFrameworkVersion>9.0</DotNetTargetFrameworkVersion>
<DotNetTargetFramework>net$(DotNetTargetFrameworkVersion)</DotNetTargetFramework>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pr:
variables:
RunningOnCI: true
Build.Configuration: Release
DotNetCoreVersion: 8.0.303
DotNetTargetFramework: net8.0
DotNetCoreVersion: 9.0.200
DotNetTargetFramework: net9.0
NetCoreTargetFrameworkPathSuffix: -$(DotNetTargetFramework)
HostedPoolName: Azure Pipelines
HostedWinImage: windows-2022
Expand Down
5 changes: 5 additions & 0 deletions src/Java.Interop.Export/Java.Interop/MarshalMemberBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand All @@ -11,8 +12,12 @@

namespace Java.Interop {

[RequiresDynamicCode (ExpressionRequiresUnreferencedCode)]
[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public class MarshalMemberBuilder : JniRuntime.JniMarshalMemberBuilder
{
internal const string ExpressionRequiresUnreferencedCode = "System.Linq.Expression usage may trim away required code.";

public MarshalMemberBuilder ()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ public JniMarshalMemberBuilder MarshalMemberBuilder {

internal bool UseMarshalMemberBuilder => marshalMemberBuilder != null;

const string NotUsedInAndroid = "This code path is not used in Android projects.";

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[DynamicDependency (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, "Java.Interop.MarshalMemberBuilder", "Java.Interop.Export")]
[UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = NotUsedInAndroid)]
[UnconditionalSuppressMessage ("Trimming", "IL2035", Justification = "Java.Interop.Export.dll is not always present.")]
[UnconditionalSuppressMessage ("Trimming", "IL3050", Justification = NotUsedInAndroid)]
partial void SetMarshalMemberBuilder (CreationOptions options)
{
if (!options.UseMarshalMemberBuilder) {
Expand Down
15 changes: 6 additions & 9 deletions src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,16 @@ protected virtual IEnumerable<string> GetSimpleReferences (Type type)
static readonly Type[] EmptyTypeArray = Array.Empty<Type> ();
const string NotUsedInAndroid = "This code path is not used in Android projects.";

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL3050", Justification = NotUsedInAndroid)]
static Type MakeArrayType (Type type) =>
// FIXME: https://github.com/dotnet/java-interop/issues/1192
#pragma warning disable IL3050
type.MakeArrayType ();
#pragma warning restore IL3050

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = NotUsedInAndroid)]
[UnconditionalSuppressMessage ("Trimming", "IL3050", Justification = NotUsedInAndroid)]
static Type MakeGenericType (Type type, Type arrayType) =>
// FIXME: https://github.com/dotnet/java-interop/issues/1192
#pragma warning disable IL3050
type.MakeGenericType (arrayType);
#pragma warning restore IL3050

[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "Types returned here should be preserved via other means.")]
[return: DynamicallyAccessedMembers (MethodsConstructors)]
Expand Down Expand Up @@ -400,16 +398,15 @@ IEnumerable<Type> CreateGetTypesForSimpleReferenceEnumerator (string jniSimpleRe
// https://github.com/xamarin/xamarin-android/blob/5472eec991cc075e4b0c09cd98a2331fb93aa0f3/src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs#L176-L186
const string makeGenericTypeMessage = "Generic 'Invoker' types are preserved by the MarkJavaObjects trimmer step.";

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = makeGenericTypeMessage)]
[UnconditionalSuppressMessage ("Trimming", "IL3050", Justification = makeGenericTypeMessage)]
[return: DynamicallyAccessedMembers (Constructors)]
static Type MakeGenericType (
[DynamicallyAccessedMembers (Constructors)]
Type type,
Type [] arguments) =>
// FIXME: https://github.com/dotnet/java-interop/issues/1192
#pragma warning disable IL3050
type.MakeGenericType (arguments);
#pragma warning restore IL3050

var signature = type.GetCustomAttribute<JniTypeSignatureAttribute> ();
if (signature == null || signature.InvokerType == null) {
Expand Down
5 changes: 2 additions & 3 deletions src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,11 @@ static JniValueMarshaler GetObjectArrayMarshaler (Type elementType)
{
const string makeGenericMethodMessage = "This code path is not used in Android projects.";

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2060", Justification = makeGenericMethodMessage)]
[UnconditionalSuppressMessage ("Trimming", "IL3050", Justification = makeGenericMethodMessage)]
static MethodInfo MakeGenericMethod (MethodInfo method, Type type) =>
// FIXME: https://github.com/dotnet/java-interop/issues/1192
#pragma warning disable IL3050
method.MakeGenericMethod (type);
#pragma warning restore IL3050

Func<JniValueMarshaler> indirect = GetObjectArrayMarshalerHelper<object>;
var reifiedMethodInfo = MakeGenericMethod (
Expand Down
1 change: 1 addition & 0 deletions src/Java.Interop/Java.Interop/JniValueMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Expression CreateSelf (JniValueMarshalerContext context, ParameterExpression sou
return self;
}

[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = ExpressionRequiresUnreferencedCode)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type _GetType () => GetType ();

Expand Down
17 changes: 15 additions & 2 deletions src/Java.Runtime.Environment/Java.Interop/JreTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -17,7 +18,13 @@ namespace Java.Interop {

public class JreTypeManager : JniRuntime.JniTypeManager {

public override void RegisterNativeMembers (JniType nativeClass, Type type, ReadOnlySpan<char> methods)
const string NotUsedInAndroid = "This code path is not used in Android projects.";

public override void RegisterNativeMembers (
JniType nativeClass,
[DynamicallyAccessedMembers (MethodsAndPrivateNested)]
Type type,
ReadOnlySpan<char> methods)
{
if (base.TryRegisterNativeMembers (nativeClass, type, methods)) {
return;
Expand Down Expand Up @@ -63,6 +70,10 @@ public override void RegisterNativeMembers (JniType nativeClass, Type type, Read
nativeClass.RegisterNativeMethods (registrations.ToArray ());
}

// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2062", Justification = NotUsedInAndroid)]
[UnconditionalSuppressMessage ("Trimming", "IL2070", Justification = NotUsedInAndroid)]
[UnconditionalSuppressMessage ("Trimming", "IL2078", Justification = NotUsedInAndroid)]
static void AddInterfaceMethods (JniMethodMap toRegister, Type type)
{
foreach (var iface in type.GetInterfaces ()) {
Expand All @@ -86,7 +97,9 @@ static void AddJniMethod (JniMethodMap toRegister, MethodInfo declaringMethod, M
toRegister [("n_" + signature.MemberName, signature.MemberSignature)] = targetMethod ?? declaringMethod;
}

static void AddClassMethods (JniMethodMap toRegister, Type type)
// FIXME: https://github.com/dotnet/java-interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2070", Justification = NotUsedInAndroid)]
static void AddClassMethods (JniMethodMap toRegister, [DynamicallyAccessedMembers (Methods)] Type type)
{
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
foreach (var method in type.GetMethods (Flags)) {
Expand Down
12 changes: 9 additions & 3 deletions src/Java.Runtime.Environment/Java.Interop/ManagedValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -231,12 +232,17 @@ void ActivateViaReflection (JniObjectReference reference, ConstructorInfo cinfo,
{
var declType = cinfo.DeclaringType ?? throw new NotSupportedException ("Do not know the type to create!");

#pragma warning disable IL2072
var self = (IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (declType);
#pragma warning restore IL2072
var self = GetUninitializedObject (declType);
self.SetPeerReference (reference);

cinfo.Invoke (self, argumentValues);

// FIXME: https://github.com/dotnet/java-interop/issues/1192
const string getUninitializedObject = "This code path is not used in Android projects.";
[UnconditionalSuppressMessage ("Trimming", "IL2067", Justification = getUninitializedObject)]
[UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = getUninitializedObject)]
static IJavaPeerable GetUninitializedObject (Type type) =>
(IJavaPeerable) System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject (type);
}

public override List<JniSurfacedPeerInfo> GetSurfacedPeers ()
Expand Down

This file was deleted.