Link the BCL
Enable the Link option for BCL assemblies. Mscorlib is excluded because the CSLA library wasn't working when it gets linked. Fixes #89
This commit is contained in:
parent
0877dfb7df
commit
3c6c1ecf66
|
@ -41,7 +41,7 @@ namespace Ooui.Wasm.Build.Tasks
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Console.WriteLine (ex);
|
//Console.WriteLine (ex);
|
||||||
Log.LogErrorFromException (ex);
|
Log.LogErrorFromException (ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -227,11 +227,14 @@ namespace Ooui.Wasm.Build.Tasks
|
||||||
|
|
||||||
Pipeline GetLinkerPipeline ()
|
Pipeline GetLinkerPipeline ()
|
||||||
{
|
{
|
||||||
|
IEnumerable<string> bclNames = bclAssemblies.Values.Select (Path.GetFileNameWithoutExtension);
|
||||||
|
|
||||||
var p = new Pipeline ();
|
var p = new Pipeline ();
|
||||||
p.AppendStep (new DontLinkExeStep ());
|
p.AppendStep (new DontLinkExeStep ());
|
||||||
p.AppendStep (new LoadReferencesStep ());
|
p.AppendStep (new LoadReferencesStep ());
|
||||||
p.AppendStep (new PreserveUsingAttributesStep (bclAssemblies.Values.Select (Path.GetFileNameWithoutExtension)));
|
p.AppendStep (new PreserveUsingAttributesStep (bclNames));
|
||||||
p.AppendStep (new BlacklistStep ());
|
p.AppendStep (new BlacklistStep ());
|
||||||
|
p.AppendStep (new LinkBclStep (bclNames));
|
||||||
p.AppendStep (new TypeMapStep ());
|
p.AppendStep (new TypeMapStep ());
|
||||||
p.AppendStep (new MarkStepWithUnresolvedLogging (this));
|
p.AppendStep (new MarkStepWithUnresolvedLogging (this));
|
||||||
p.AppendStep (new SweepStep ());
|
p.AppendStep (new SweepStep ());
|
||||||
|
@ -251,6 +254,48 @@ namespace Ooui.Wasm.Build.Tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LinkBclStep : BaseStep
|
||||||
|
{
|
||||||
|
HashSet<string> bclNames;
|
||||||
|
List<Tuple<string, string>> preserveTypeNames;
|
||||||
|
|
||||||
|
public LinkBclStep (IEnumerable<string> bclNames)
|
||||||
|
{
|
||||||
|
// CSLA cannot tolerate mscorlib being linked (uses reflection over types it doesn't reference)
|
||||||
|
this.bclNames = new HashSet<string> (bclNames.Where(x => x != "mscorlib"));
|
||||||
|
preserveTypeNames = new List<Tuple<string, string>> {
|
||||||
|
Tuple.Create ("System", "System.ComponentModel.IEditableObject"),
|
||||||
|
Tuple.Create ("System", "System.ComponentModel.IDataErrorInfo"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Process ()
|
||||||
|
{
|
||||||
|
var asms = Context.GetAssemblies ();
|
||||||
|
|
||||||
|
foreach (var a in asms) {
|
||||||
|
if (bclNames.Contains (a.Name.Name)) {
|
||||||
|
Annotations.SetAction (a, AssemblyAction.Link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var p in preserveTypeNames) {
|
||||||
|
var asm = asms.FirstOrDefault (x => x.Name.Name == p.Item1);
|
||||||
|
if (asm == null)
|
||||||
|
throw new Exception ($"Could not find assembly {p.Item1}");
|
||||||
|
var t = asm.MainModule.GetType (p.Item2);
|
||||||
|
if (t == null)
|
||||||
|
throw new Exception ($"Could not find type {p.Item2} in {p.Item1}");
|
||||||
|
Annotations.SetPreserve (t, TypePreserve.All);
|
||||||
|
}
|
||||||
|
|
||||||
|
//foreach (var a in asms) {
|
||||||
|
// var act = Annotations.GetAction (a);
|
||||||
|
// Console.WriteLine ($"{act} {a.Name.Name}");
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MarkStepWithUnresolvedLogging : MarkStep
|
class MarkStepWithUnresolvedLogging : MarkStep
|
||||||
{
|
{
|
||||||
BuildDistTask task;
|
BuildDistTask task;
|
||||||
|
@ -376,8 +421,6 @@ namespace Ooui.Wasm.Build.Tasks
|
||||||
|
|
||||||
class LinkerMetadataResolver : MetadataResolver
|
class LinkerMetadataResolver : MetadataResolver
|
||||||
{
|
{
|
||||||
LinkerAssemblyResolver resolver;
|
|
||||||
|
|
||||||
readonly AssemblyNameReference mscorlibScope = new AssemblyNameReference ("mscorlib", new Version (1, 0));
|
readonly AssemblyNameReference mscorlibScope = new AssemblyNameReference ("mscorlib", new Version (1, 0));
|
||||||
|
|
||||||
public LinkerMetadataResolver (LinkerAssemblyResolver asmResolver)
|
public LinkerMetadataResolver (LinkerAssemblyResolver asmResolver)
|
||||||
|
|
Loading…
Reference in New Issue