Skip to content

Commit

Permalink
[dotnet] Integrate class handle rewriting into static registrar proce…
Browse files Browse the repository at this point in the history
…ss. (#18456)

Integrate class handle rewriting into static registrar.
  • Loading branch information
stephen-hawley authored and rolfbjarne committed Jun 26, 2023
1 parent 1bf687f commit e474a47
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 247 deletions.
134 changes: 0 additions & 134 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/ClassRedirectorTask.cs

This file was deleted.

6 changes: 0 additions & 6 deletions msbuild/Xamarin.MacDev.Tasks/Xamarin.MacDev.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
<Compile Include="..\..\tools\common\SdkVersions.cs">
<Link>external\SdkVersions.cs</Link>
</Compile>
<Compile Include="..\..\tools\common\CSToObjCMap.cs">
<Link>external\CSToObjCMap.cs</Link>
</Compile>
<Compile Include="..\..\tools\common\ObjCNameIndex.cs">
<Link>external\ObjCNameIndex.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ unsafe static void Initialize (InitializationOptions* options)
throw ErrorHelper.CreateError (8010, msg);
}

#if NET
if (options->RegistrationMap is not null && options->RegistrationMap->map is not null) {
ClassHandles.InitializeClassHandles (options->RegistrationMap->map);
}
#endif

IntPtrEqualityComparer = new IntPtrEqualityComparer ();
TypeEqualityComparer = new TypeEqualityComparer ();

Expand Down
12 changes: 7 additions & 5 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

using ObjCRuntime;

using ClassRedirector;

#if MONOTOUCH
using PlatformResolver = MonoTouch.Tuner.MonoTouchResolver;
#elif MMP
Expand Down Expand Up @@ -167,7 +169,6 @@ public bool IsDefaultMarshalManagedExceptionMode {
public bool EnableBitCode { get { return BitCodeMode != BitCodeMode.None; } }

public bool SkipMarkingNSObjectsInUserAssemblies { get; set; }
public string ClassMapPath = "";

// assembly_build_targets describes what kind of native code each assembly should be compiled into for mobile targets (iOS, tvOS, watchOS).
// An assembly can be compiled into: static object (.o), dynamic library (.dylib) or a framework (.framework).
Expand Down Expand Up @@ -1029,10 +1030,11 @@ public void RunRegistrar ()
}
#endif
var registrar = new Registrar.StaticRegistrar (this);
if (RootAssemblies.Count == 1)
registrar.GenerateSingleAssembly (resolver, resolvedAssemblies.Values, Path.ChangeExtension (registrar_m, "h"), registrar_m, Path.GetFileNameWithoutExtension (RootAssembly), out var _, ClassMapPath);
else
registrar.Generate (resolver, resolvedAssemblies.Values, Path.ChangeExtension (registrar_m, "h"), registrar_m, out var _, ClassMapPath);
if (RootAssemblies.Count == 1) {
registrar.GenerateSingleAssembly (resolver, resolvedAssemblies.Values, Path.ChangeExtension (registrar_m, "h"), registrar_m, Path.GetFileNameWithoutExtension (RootAssembly), out var _);
} else {
registrar.Generate (resolver, resolvedAssemblies.Values, Path.ChangeExtension (registrar_m, "h"), registrar_m, out var _);
}
}

public IEnumerable<Abi> Abis {
Expand Down
37 changes: 0 additions & 37 deletions tools/common/CSToObjCMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,9 @@

namespace ClassRedirector {
public class CSToObjCMap : Dictionary<string, ObjCNameIndex> {
const string objMapName = "CSToObjCMap";
const string elementName = "Element";
const string csNameName = "CSName";
public CSToObjCMap () : base ()
{
}

public static XElement ToXElement (CSToObjCMap map)
{
return new XElement (objMapName, Elements (map));
}

static IEnumerable<XElement> Elements (CSToObjCMap map)
{
return map.Select (kvp => new XElement (elementName, new XAttribute (csNameName, kvp.Key), ObjCNameIndex.ToXElement (kvp.Value)));
}

public static CSToObjCMap FromXElement (XElement xmap)
{
var map = new CSToObjCMap ();
var elements = from el in xmap.Descendants (elementName)
select new KeyValuePair<string?, ObjCNameIndex?> (el.Attribute (csNameName)?.Value,
ObjCNameIndex.FromXElement (el.Element (ObjCNameIndex.ObjNameIndexName)));
foreach (var elem in elements) {
if (elem.Key is not null && elem.Value is not null)
map.Add (elem.Key, elem.Value);
}
return map;
}

public static CSToObjCMap? FromXDocument (XDocument doc)
{
var el = doc.Descendants (objMapName).FirstOrDefault ();
return el is null ? null : FromXElement (el);
}

public static XDocument ToXDocument (CSToObjCMap map)
{
return new XDocument (ToXElement (map));
}
}
}

2 changes: 0 additions & 2 deletions tools/common/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ static bool ParseOptions (Application app, Mono.Options.OptionSet options, strin
options.Add ("skip-marking-nsobjects-in-user-assemblies:", "Don't mark NSObject (and any subclass of NSObject) in user assemblies in the linker. This may break your app, use at own risk.", v => {
app.SkipMarkingNSObjectsInUserAssemblies = ParseBool (v, "--skip-marking-nsobjects-in-user-assemblies");
});
options.Add ("class-map-path=", "Sets the path for an output path to generate a class map XML file used to optimize class handle access when the static registrar has been used.", v => { app.ClassMapPath = v; });


// Keep the ResponseFileSource option at the end.
options.Add (new Mono.Options.ResponseFileSource ());
Expand Down
21 changes: 0 additions & 21 deletions tools/common/ObjCNameIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,13 @@

namespace ClassRedirector {
public class ObjCNameIndex {
public const string ObjNameIndexName = "ObjNameIndex";
const string nameName = "Name";
const string indexName = "Index";
public ObjCNameIndex (string objCName, int mapIndex)
{
ObjCName = objCName;
MapIndex = mapIndex;
}
public string ObjCName { get; private set; }
public int MapIndex { get; private set; }

public static XElement ToXElement (ObjCNameIndex nameIndex)
{
return new XElement (ObjNameIndexName,
new XElement (nameName, nameIndex.ObjCName),
new XElement (indexName, nameIndex.MapIndex));
}

public static ObjCNameIndex? FromXElement (XElement? objNameIndex)
{
if (objNameIndex is null)
return null;
var name = (string?) objNameIndex.Element (nameName);
var index = (int?) objNameIndex.Element (indexName);
if (name is null || index is null)
return null;
return new ObjCNameIndex (name, index.Value);
}
}
}

Loading

0 comments on commit e474a47

Please sign in to comment.