Skip to content

Commit

Permalink
Support .Net Standard (#176)
Browse files Browse the repository at this point in the history
* Support .Net Standard

* Update DynamicLanguageRuntime.nuspec

* Fix NuSpec

* Update make.ps1

* Update ILGen.cs
  • Loading branch information
YairHalberstadt authored and slozier committed Feb 20, 2019
1 parent c29f32c commit 487da7c
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 27 deletions.
49 changes: 49 additions & 0 deletions Build/netstandard2.0.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IsFullFramework>false</IsFullFramework>
</PropertyGroup>

<PropertyGroup>
<Features>$(Features);FEATURE_APARTMENTSTATE</Features>
<Features>$(Features);FEATURE_APPLICATIONEXCEPTION</Features>
<Features>$(Features);FEATURE_ASSEMBLY_CODEBASE</Features>
<Features>$(Features);FEATURE_ASSEMBLY_LOCATION</Features>
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
<Features>$(Features);FEATURE_CODEDOM</Features>
<Features>$(Features);FEATURE_CONFIGURATION</Features>
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
<Features>$(Features);FEATURE_DBNULL</Features>
<Features>$(Features);FEATURE_DRIVENOTFOUNDEXCEPTION</Features>
<Features>$(Features);FEATURE_DYNAMIC_EXPRESSION_VISITOR</Features>
<Features>$(Features);FEATURE_ENCODING</Features>
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
<Features>$(Features);FEATURE_FILESYSTEM</Features>
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
<Features>$(Features);FEATURE_FULL_NET</Features>
<Features>$(Features);FEATURE_ICLONEABLE</Features>
<Features>$(Features);FEATURE_LCG</Features>
<Features>$(Features);FEATURE_LOADWITHPARTIALNAME</Features>
<Features>$(Features);FEATURE_METADATA_READER</Features>
<Features>$(Features);FEATURE_MMAP</Features>
<Features>$(Features);FEATURE_OS_SERVICEPACK</Features>
<Features>$(Features);FEATURE_PIPES</Features>
<Features>$(Features);FEATURE_PROCESS</Features>
<Features>$(Features);FEATURE_REFEMIT</Features>
<Features>$(Features);FEATURE_REGISTRY</Features>
<Features>$(Features);FEATURE_SECURITY_RULES</Features>
<Features>$(Features);FEATURE_SERIALIZATION</Features>
<Features>$(Features);FEATURE_SORTKEY</Features>
<Features>$(Features);FEATURE_STACK_TRACE</Features>
<Features>$(Features);FEATURE_SYNC_SOCKETS</Features>
<Features>$(Features);FEATURE_THREAD</Features>
<Features>$(Features);FEATURE_TYPE_EQUIVALENCE</Features>
<Features>$(Features);FEATURE_TYPECONVERTER</Features>
<Features>$(Features);FEATURE_WARNING_EXCEPTION</Features>
<Features>$(Features);FEATURE_WIN32EXCEPTION</Features>
<Features>$(Features);FEATURE_XMLDOC</Features>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions Dlr.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{60056F49
Build\net45.props = Build\net45.props
Build\netcoreapp2.0.props = Build\netcoreapp2.0.props
Build\netcoreapp2.1.props = Build\netcoreapp2.1.props
Build\netstandard2.0.props = Build\netstandard2.0.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Package", "Package", "{006DB050-2A71-4F36-BBE1-4AF6AF310C13}"
Expand Down
6 changes: 6 additions & 0 deletions Package/nuget/DynamicLanguageRuntime.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<dependency id="System.CodeDom" version="4.5.0" />
<dependency id="System.Configuration.ConfigurationManager" version="4.5.0" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="System.CodeDom" version="4.5.0" />
<dependency id="System.Configuration.ConfigurationManager" version="4.5.0" />
<dependency id="System.Reflection.Emit" version="4.6.0-preview.19073.11" />
<dependency id="System.Reflection.Emit.Lightweight" version="4.6.0-preview.19073.11" />
</group>
</dependencies>
</metadata>
<files>
Expand Down
4 changes: 2 additions & 2 deletions Src/Microsoft.Dynamic/Debugging/DelegateHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static Type MakeNewCustomDelegateType(Type[] types) {
TypeBuilder builder = DefineDelegateType("Delegate_" + Guid.NewGuid().ToString());
builder.DefineConstructor(CtorAttributes, CallingConventions.Standard, _DelegateCtorSignature).SetImplementationFlags(ImplAttributes);
builder.DefineMethod("Invoke", InvokeAttributes, returnType, parameters).SetImplementationFlags(ImplAttributes);
return builder.CreateType();
return builder.CreateTypeInfo();
}

private static TypeBuilder DefineDelegateType(string name) {
Expand All @@ -49,4 +49,4 @@ private static ModuleBuilder GetModule() {
}
}
}
#endif
#endif
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Generation/AssemblyGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public Type MakeDelegateType(string name, Type[] parameters, Type returnType) {
TypeBuilder builder = DefineType(name, typeof(MulticastDelegate), DelegateAttributes, false);
builder.DefineConstructor(CtorAttributes, CallingConventions.Standard, _DelegateCtorSignature).SetImplementationFlags(ImplAttributes);
builder.DefineMethod("Invoke", InvokeAttributes, returnType, parameters).SetImplementationFlags(ImplAttributes);
return builder.CreateType();
return builder.CreateTypeInfo();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Generation/CompilerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public static T LightCompile<T>(this Expression<T> lambda, int compilationThresh
return (T)(object)LightCompile((LambdaExpression)lambda, compilationThreshold);
}

#if FEATURE_REFEMIT && !NETCOREAPP2_0 && !NETCOREAPP2_1
#if FEATURE_REFEMIT && !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NETSTANDARD2_0
/// <summary>
/// Compiles the lambda into a method definition.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Src/Microsoft.Dynamic/Generation/DynamicILGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override T CreateDelegate<T>(out MethodInfo mi) {
}

private MethodInfo CreateMethod() {
Type t = _tb.CreateType();
Type t = _tb.CreateTypeInfo();
return t.GetMethod(_mb.Name);
}

Expand All @@ -71,4 +71,4 @@ public override MethodInfo Finish() {
}
#endif
}
#endif
#endif
6 changes: 3 additions & 3 deletions Src/Microsoft.Dynamic/Generation/FieldBuilderExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.Scripting.Generation {
public class FieldBuilderExpression : Expression {
private readonly FieldBuilder _builder;

#if NETCOREAPP2_0 || NETCOREAPP2_1
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETSTANDARD2_0
private readonly StrongBox<Type> _finishedType;

// Get something which can be updated w/ the final type.
Expand Down Expand Up @@ -60,7 +60,7 @@ public override Expression Reduce() {

private FieldInfo GetFieldInfo() {
// turn the field builder back into a FieldInfo
#if NETCOREAPP2_0 || NETCOREAPP2_1
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETSTANDARD2_0
return _finishedType.Value.GetDeclaredField(_builder.Name);
#else
return _builder.DeclaringType.Module.ResolveField(
Expand All @@ -75,4 +75,4 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) {
}
}

#endif
#endif
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Generation/ILGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] option
_ilg.EmitCall(opcode, methodInfo, optionalParameterTypes);
}

#if !NETCOREAPP2_0 || NETCOREAPP2_1
#if !NETCOREAPP2_0 && !NETSTANDARD2_0
/// <summary>
/// Emits an unmanaged indirect call instruction.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Generation/Snippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Type DefineDelegate(string name, Type returnType, params Type[] argTypes)
MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
CallingConventions.Standard, _DelegateCtorSignature).SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
tb.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual, returnType, argTypes).SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
return tb.CreateType();
return tb.CreateTypeInfo();

}

Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Generation/ToDiskRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private bool ShouldRewriteDelegate(Type delegateType) {
// SaveAssemblies mode prevents us from detecting the module as
// transient. If that option is turned on, always replace delegates
// that live in another AssemblyBuilder
#if NETCOREAPP2_0 || NETCOREAPP2_1
#if NETCOREAPP2_0 || NETCOREAPP2_1 || NETSTANDARD2_0
return true; // TODO:
#else
var module = delegateType.Module as ModuleBuilder;
Expand Down
4 changes: 2 additions & 2 deletions Src/Microsoft.Dynamic/Generation/TypeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override string ToString() {

public Type FinishType() {
_initGen?.Emit(OpCodes.Ret);
Type ret = TypeBuilder.CreateType();
Type ret = TypeBuilder.CreateTypeInfo();
return ret;
}

Expand Down Expand Up @@ -84,4 +84,4 @@ public ILGen DefineMethodOverride(MethodInfo baseMethod) {
}
}
}
#endif
#endif
11 changes: 8 additions & 3 deletions Src/Microsoft.Dynamic/Microsoft.Dynamic.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1;netstandard2.0;</TargetFrameworks>
<RootNamespace>Microsoft.Scripting</RootNamespace>
<BaseAddress>859832320</BaseAddress>
<CodeAnalysisRuleSet>..\..\DLR.ruleset</CodeAnalysisRuleSet>
Expand All @@ -14,15 +14,20 @@
</ItemGroup>

<ItemGroup>
<Reference Include="System.Configuration" Condition=" $(Features.Contains('FEATURE_CONFIGURATION')) " />
<Reference Include="System.Configuration" Condition=" '$(TargetFramework)' == 'net45' AND $(Features.Contains('FEATURE_CONFIGURATION')) " />
<Reference Include="System.Runtime.Remoting" Condition=" $(Features.Contains('FEATURE_REMOTING')) " />
<Reference Include="System.Xaml" Condition=" $(Features.Contains('FEATURE_WPF')) " />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants.Replace(';FEATURE_FILESYSTEM', ''))</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Reflection.Emit" Version="4.6.0-preview.19073.11" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.6.0-preview.19073.11" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public static StringBuilder FormatSignature(StringBuilder result, MethodBase met
result.Append(' ');
}

#if FEATURE_REFEMIT && !NETCOREAPP2_0 && !NETCOREAPP2_1
#if FEATURE_REFEMIT && !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NETSTANDARD2_0
MethodBuilder builder = method as MethodBuilder;
if (builder != null) {
result.Append(builder.Signature);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1;netstandard2.0;</TargetFrameworks>
<BaseAddress>859832320</BaseAddress>
<CodeAnalysisRuleSet>..\..\DLR.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
Expand Down
11 changes: 8 additions & 3 deletions Src/Microsoft.Scripting/Microsoft.Scripting.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net45;netcoreapp2.0;netcoreapp2.1;netstandard2.0</TargetFrameworks>
<BaseAddress>857735168</BaseAddress>
<CodeAnalysisRuleSet>..\..\DLR.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Reference Include="System.Configuration" Condition=" $(Features.Contains('FEATURE_CONFIGURATION')) " />
<Reference Include="System.Configuration" Condition=" '$(TargetFramework)' == 'net45' AND $(Features.Contains('FEATURE_CONFIGURATION')) " />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netcoreapp2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.CodeDom" Version="4.5.0" />
</ItemGroup>


<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Reflection.Emit" Version="4.6.0-preview.19073.11" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions Src/Microsoft.Scripting/Utils/DelegateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ internal static Type EmitCallSiteDelegateType(int paramCount) {
MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Public,
CallingConventions.Standard, _DelegateCtorSignature).SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
tb.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual, typeof(object), paramTypes).SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);
return tb.CreateType();
return tb.CreateTypeInfo();
}
}
}
#endif
#endif
4 changes: 2 additions & 2 deletions Src/Microsoft.Scripting/Utils/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if FEATURE_NATIVE || NETCOREAPP2_0 || NETCOREAPP2_1
#if FEATURE_NATIVE || NETCOREAPP2_0 || NETCOREAPP2_1 || NETSTANDARD2_0

using System;
using System.Runtime.InteropServices;
Expand All @@ -15,4 +15,4 @@ internal static class NativeMethods {
}
}

#endif
#endif
2 changes: 1 addition & 1 deletion Tests/Microsoft.Dynamic.Test/TestReflectionServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void TestExtensionMethods1() {
"DefaultIfEmpty", "ElementAt", "ElementAtOrDefault"
}).ToList();

#if !NETCOREAPP2_0 && !NETCOREAPP2_1
#if !NETCOREAPP2_0 && !NETCOREAPP2_1 && !NETSTANDARD2_0
names.AddRange(
new string[] {
"AsQueryable", "AsQueryable", "AsParallel", "AsParallel", "AsParallel", "AsOrdered",
Expand Down

0 comments on commit 487da7c

Please sign in to comment.