Skip to content

Commit

Permalink
Basic support for the netcore-based projects. /#90
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Oct 28, 2019
1 parent c6f76c9 commit 2b89a04
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Specific

/MetadataCore/DllExport.xml
/Configurator/ConfVersion.cs

## Ignore Visual Studio temporary files, build results, and
Expand Down
36 changes: 25 additions & 11 deletions .vssbe

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions DllExport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGiesecke.DllExport", "RGiesecke.DllExport\RGiesecke.DllExport.csproj", "{AC6947C6-0637-429A-A5F1-54447A494E6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metadata", "Metadata\Metadata.csproj", "{D620BC4A-50CD-48DF-8C6E-B79555260EA0}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetadataFx", "MetadataFx\MetadataFx.csproj", "{D620BC4A-50CD-48DF-8C6E-B79555260EA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGiesecke.DllExport.MSBuild", "RGiesecke.DllExport.MSBuild\RGiesecke.DllExport.MSBuild.csproj", "{9C75E9C4-5D81-4704-ADD1-F4B42B6267C8}"
EndProject
Expand Down Expand Up @@ -73,9 +73,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wizard", "Wizard\Wizard.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PeViewer", "PeViewer\PeViewer.csproj", "{BE8C8005-A6C6-41D0-9DB0-6B4B7BD1077F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvsSln", "MvsSln\MvsSln\MvsSln.csproj", "{F905DFB2-2E67-4FF7-9001-924F6F2D645D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvsSln", "MvsSln\MvsSln\MvsSln.csproj", "{F905DFB2-2E67-4FF7-9001-924F6F2D645D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvsSlnTest", "MvsSln\MvsSlnTest\MvsSlnTest.csproj", "{EC0CA220-39EC-41E5-B9D6-88D8F860F979}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvsSlnTest", "MvsSln\MvsSlnTest\MvsSlnTest.csproj", "{EC0CA220-39EC-41E5-B9D6-88D8F860F979}"
ProjectSection(ProjectDependencies) = postProject
{F905DFB2-2E67-4FF7-9001-924F6F2D645D} = {F905DFB2-2E67-4FF7-9001-924F6F2D645D}
EndProjectSection
Expand Down Expand Up @@ -122,6 +122,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "batch", "batch", "{603C7C21
Manager\batch\tests.targets = Manager\batch\tests.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetadataCore", "MetadataCore\MetadataCore.csproj", "{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -183,6 +185,12 @@ Global
{EC0CA220-39EC-41E5-B9D6-88D8F860F979}.PublicRelease|Any CPU.Build.0 = Release|Any CPU
{EC0CA220-39EC-41E5-B9D6-88D8F860F979}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC0CA220-39EC-41E5-B9D6-88D8F860F979}.Release|Any CPU.Build.0 = Release|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.PublicRelease|Any CPU.ActiveCfg = Release|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.PublicRelease|Any CPU.Build.0 = Release|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F0E1861-4EC7-4125-B16A-EE95FA80FA0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Manager/batch/.compressor
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
var vdict = gencomb(cdict, 2, (int i) => { return char.IsLetter(cdict[i]) || cdict[i] == '_'; });
// to skip processing for:
var exvar = new[] { "__p_call", "wMgrArgs", "wSlnDir", "wPkgPath", "wMetaLib", "wDxpTarget", "wAction", "wSlnFile", "wRootPath", "ngserver" };
var exvar = new[] { "__p_call", "wMgrArgs", "wSlnDir", "wPkgPath", "wMetaLib", "wMetaCor", "wDxpTarget", "wAction", "wSlnFile", "wRootPath", "ngserver" };
const string VNAME = "[a-z_][a-z_0-9]+";
const string VERS = "[Minified version]";
Expand Down
9 changes: 8 additions & 1 deletion Manager/batch/Manager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ echo * Upgrade - Aggregates an Update action with additions for upgradin
echo.
echo -sln-dir {path} - Path to directory with .sln files to be processed.
echo -sln-file {path} - Optional predefined .sln file to be processed.
echo -metalib {path} - Relative path from PkgPath to DllExport meta library.
echo -metalib {path} - Relative path to meta library.
echo -metacor {path} - Relative path to meta core library.
echo -dxp-target {path} - Relative path to entrypoint wrapper of the main core.
echo -dxp-version {num} - Specific version of DllExport. Where {num}:
echo * Versions: 1.6.0 ...
Expand Down Expand Up @@ -236,6 +237,11 @@ set key=!arg[%idx%]!

set wMetaLib=!v!

goto continue
) else if [!key!]==[-metacor] ( set /a "idx+=1" & call :eval arg[!idx!] v

set wMetaCor=!v!

goto continue
) else if [!key!]==[-dxp-target] ( set /a "idx+=1" & call :eval arg[!idx!] v

Expand Down Expand Up @@ -354,6 +360,7 @@ call :dbgprint "dxpVersion = " dxpVersion
call :dbgprint "-sln-dir = " wSlnDir
call :dbgprint "-sln-file = " wSlnFile
call :dbgprint "-metalib = " wMetaLib
call :dbgprint "-metacor = " wMetaCor
call :dbgprint "-dxp-target = " wDxpTarget
call :dbgprint "-wz-target = " tWizard

Expand Down
3 changes: 3 additions & 0 deletions Manager/batch/tests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<Error Text="wMetaLib: $(wMetaLib) == $(DataSpecSymbols)" Condition="'$(wMetaLib)' != '$(DataSpecSymbols)'" />
<Message Text="wMetaLib: $(wMetaLib) == $(DataSpecSymbols)" Importance="High" />

<Error Text="wMetaCor: $(wMetaCor) == $(DataSpecSymbols)" Condition="'$(wMetaCor)' != '$(DataSpecSymbols)'" />
<Message Text="wMetaCor: $(wMetaCor) == $(DataSpecSymbols)" Importance="High" />

<Error Text="wDxpTarget: $(wDxpTarget) == $(DataSpecSymbols)" Condition="'$(wDxpTarget)' != '$(DataSpecSymbols)'" />
<Message Text="wDxpTarget: $(wDxpTarget) == $(DataSpecSymbols)" Importance="High" />

Expand Down
32 changes: 32 additions & 0 deletions MetadataCore/MetadataCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.6.5</Version>
<MetadataFxPath>..\MetadataFx\</MetadataFxPath>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>net.r_eg.DllExport</RootNamespace>
<AssemblyName>DllExport</AssemblyName>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MetadataFxPath)key.snk</AssemblyOriginatorKeyFile>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/3F/DllExport</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Authors>github.com/3F/DllExport</Authors>
<Copyright>github.com/3F/DllExport</Copyright>
<Configurations>Debug;Release;PublicRelease</Configurations>
<!-- <NoWarn>1701;1702;CS1591</NoWarn> -->
<!-- <LangVersion>latest</LangVersion> -->
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MetadataFxPath)DllExportAttribute.cs" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions RGiesecke.DllExport/Parsing/ILAsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ private int Run(string outputFile, string ilSuffix, CpuPlatform cpu)
while(File.Exists(str1));
File.Move(this.InputValues.InputFileName, str1);
}
try
{

// https://github.com/3F/coreclr/blob/05afa4f81fdf671429b54467c64d65cde6b5fadc/src/debug/ildbsymlib/symwrite.cpp#L308
// Due to possible incorrect ISymUnmanagedWriter when exists initial pdb data for non-modified asm.
// \- Part of https://github.com/3F/DllExport/issues/90
File.Delete(Path.ChangeExtension(InputValues.InputFileName, ".pdb"));

try {
return this.RunCore(cpu, outputFile, ressourceParam, ilSuffix);
}
finally
Expand Down
50 changes: 49 additions & 1 deletion RGiesecke.DllExport/Parsing/IlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ public IEnumerable<string> GetLines(CpuPlatform cpu)
}
}
}

EmitMSCorlib(stringList2, state);

stopwatch1.Stop();
this.GetNotifier().Notify(-2, "EXPPERF02", Resources.Parsing_0_lines_of_IL_took_1_ms_, (object)stringList1.Count, (object)stopwatch1.ElapsedMilliseconds);
if(this.ProfileActions)
Expand All @@ -246,7 +249,8 @@ public IEnumerable<string> GetLines(CpuPlatform cpu)
this.GetNotifier().Notify(-1, "EXPPERF03", Resources.Parsing_action_0_took_1_ms, (object)keyValuePair.Key, (object)keyValuePair.Value.Milliseconds);
}
}
return (IEnumerable<string>)stringList2;

return stringList2;
}
}

Expand All @@ -255,6 +259,50 @@ internal IDllExportNotifier GetNotifier()
return this.ServiceProvider.GetService<IDllExportNotifier>();
}

/// <summary>
/// Read my note in https://github.com/3F/DllExport/issues/90
///
/// .assembly extern 'netstandard'
/// ... ^^^^^^^^^^^
///
/// .class public auto ansi beforefieldinit ...
/// extends[mscorlib] System.Object
/// ^^^^^^^^
/// ...
/// call instance void [mscorlib]System.Object::.ctor()
/// ^^^^^^^^
/// </summary>
/// <param name="il"></param>
/// <param name="state"></param>
/// <returns></returns>
private bool EmitMSCorlib(List<string> il, ParserStateValues state)
{
if(state.ExternalAssemlyDeclarations.Count < 1) {
return false;
}

const string _EASM = "mscorlib";

if(state.ExternalAssemlyDeclarations.Any(x => x.AssemblyName == _EASM)) {
return false;
}

il.InsertRange
(
state.ExternalAssemlyDeclarations[0].InputLineIndex,
new []
{
$".assembly extern '{_EASM}'",
"{",
" .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) ",
" .ver 4:0:0:0",
"}"
}
);

return true;
}

private HashSet<string> GetMethodAttributes()
{
string str = (this.InputValues.MethodAttributes ?? "").Trim();
Expand Down
14 changes: 13 additions & 1 deletion Wizard/DllExportCfgTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public string PkgPath
private string _pkgPath;

/// <summary>
/// Relative path from PkgPath to DllExport meta library.
/// Relative path to meta library.
/// </summary>
[Required]
public string MetaLib
Expand All @@ -92,6 +92,17 @@ public string MetaLib
}
private string _metaLib;

/// <summary>
/// Relative path to meta core library.
/// </summary>
[Required]
public string MetaCor
{
get => _metacor;
set => _metacor = value.FilePathFormat();
}
private string _metacor;

/// <summary>
/// Path to .targets file of the DllExport.
/// </summary>
Expand Down Expand Up @@ -286,6 +297,7 @@ private void PrintKeys(Message.Level level)
LSender.Send(this, $"SlnFile: '{SlnFile}'", level);
LSender.Send(this, $"PkgPath: '{PkgPath}'", level);
LSender.Send(this, $"MetaLib: '{MetaLib}'", level);
LSender.Send(this, $"MetaCor: '{MetaCor}'", level);
LSender.Send(this, $"MgrArgs: '{MgrArgs}'", level);
LSender.Send(this, $"DxpTarget: '{DxpTarget}'", level);
LSender.Send(this, $"RootPath: '{RootPath}'", level);
Expand Down
3 changes: 2 additions & 1 deletion Wizard/IProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public interface IProject
/// Returns fullpath to meta library for current project.
/// </summary>
/// <param name="evaluate">Will return unevaluated value if false.</param>
/// <param name="corlib">netfx-based or netcore-based meta lib.</param>
/// <returns></returns>
string MetaLib(bool evaluate);
string MetaLib(bool evaluate, bool corlib = false);

/// <summary>
/// To recover references with project file.
Expand Down
7 changes: 6 additions & 1 deletion Wizard/IWizardConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public interface IWizardConfig
string PkgPath { get; }

/// <summary>
/// Relative path from PkgPath to DllExport meta library.
/// Relative path to meta library.
/// </summary>
string MetaLib { get; }

/// <summary>
/// Relative path to meta core library.
/// </summary>
string MetaCor { get; }

/// <summary>
/// Path to .targets file of the DllExport.
/// </summary>
Expand Down
33 changes: 27 additions & 6 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,26 @@ protected ISender Log
/// Returns fullpath to meta library for current project.
/// </summary>
/// <param name="evaluate">Will return unevaluated value if false.</param>
/// <param name="corlib">netfx-based or netcore-based meta lib.</param>
/// <returns></returns>
public virtual string MetaLib(bool evaluate)
public virtual string MetaLib(bool evaluate, bool corlib = false)
{
string mdll = GetMetaDll(corlib);

return Path.GetFullPath
(
Path.Combine
(
Config.Wizard.PkgPath,
"gcache",
"metalib",
evaluate ? corlib ? "metacor" : "metalib"
: "$(DllExportMetaXBase)",

(evaluate && Config?.Namespace != null) ?
Config.Namespace : "$(DllExportNamespace)",

(evaluate && Config?.Wizard?.MetaLib != null) ?
Path.GetFileName(Config.Wizard.MetaLib) : "$(DllExportMetaLibName)"
(evaluate && mdll != null) ?
Path.GetFileName(mdll) : "$(DllExportMetaLibName)"
)
);
}
Expand Down Expand Up @@ -372,11 +377,17 @@ protected void Save()
}

protected void CfgDDNS()
{
CfgDDNS(false);
CfgDDNS(true);
}

protected void CfgDDNS(bool corlib)
{
Config.DDNS.setNamespace(
CopyLib(
Path.Combine(Config.Wizard.PkgPath, Config.Wizard.MetaLib),
MetaLib(true)
Path.Combine(Config.Wizard.PkgPath, GetMetaDll(corlib)),
MetaLib(true, corlib)
),
Config.Namespace,
Config.UseCecil,
Expand Down Expand Up @@ -740,5 +751,15 @@ private string CopyLib(string src, string dest)

return dest;
}

private string GetMetaDll(bool corlib)
{
IWizardConfig cfg = Config?.Wizard;
if(cfg == null) {
return null;
}

return corlib ? cfg.MetaCor : cfg.MetaLib;
}
}
}
1 change: 1 addition & 0 deletions Wizard/Wizard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<ProjectReference Include="..\MvsSln\MvsSln\MvsSln.csproj">
<Project>{f905dfb2-2e67-4ff7-9001-924f6f2d645d}</Project>
<Name>MvsSln</Name>
<AdditionalProperties>TargetFramework=net40</AdditionalProperties>
</ProjectReference>
<ProjectReference Include="..\NSBin\NSBin.csproj">
<Project>{311706a5-5ed2-4006-b794-055009d8a256}</Project>
Expand Down
4 changes: 3 additions & 1 deletion Wizard/net.r_eg.DllExport.Wizard.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<wSlnDir Condition="'$(wSlnDir)' == ''">.\</wSlnDir>
<wPkgPath Condition="'$(wPkgPath)' == ''">packages\DllExport</wPkgPath>
<wMetaLib Condition="'$(wMetaLib)' == ''">tools\raw\lib\net20\DllExport.dll</wMetaLib>
<wMetaCor Condition="'$(wMetaCor)' == ''">tools\raw\lib\netstd\DllExport.dll</wMetaCor>
<wDxpTarget Condition="'$(wDxpTarget)' == ''">tools\net.r_eg.DllExport.targets</wDxpTarget>
<wAction Condition="'$(wAction)' == ''">Restore</wAction> <!-- Action by default. enum `ActionType`. -->
</PropertyGroup>
Expand Down Expand Up @@ -41,7 +42,8 @@
SlnDir="$(wSlnDir)"
SlnFile="$(wSlnFile)"
PkgPath="$(wPkgPath)"
MetaLib="$(wMetaLib)"
MetaLib="$(wMetaLib)"
MetaCor="$(wMetaCor)"
MgrArgs="$(wMgrArgs)"
DxpTarget="$(wDxpTarget)"
StoragePath="$(wStoragePath)"
Expand Down
Loading

0 comments on commit 2b89a04

Please sign in to comment.