Browse Source

Make all libraries of CppSharp use .NET Standard

This makes them usable with .NET Framework, .NET Core and .NET 5.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
cppsharp-net-standard-nuget
Dimitar Dobrev 4 years ago
parent
commit
201d28e64d
  1. 4
      Directory.Build.props
  2. 1
      Directory.Packages.props
  3. 1
      src/AST/CppSharp.AST.csproj
  4. 12
      src/CLI/Generator.cs
  5. 1
      src/Core/CppSharp.csproj
  6. 8
      src/CppParser/Bindings/premake5.lua
  7. 8
      src/CppParser/Bootstrap/Bootstrap.cs
  8. 12
      src/CppParser/ParserGen/ParserGen.cs
  9. 13
      src/Generator.Tests/GeneratorTest.cs
  10. 4
      src/Generator/CppSharp.Generator.csproj
  11. 2
      src/Generator/Generators/NAPI/NAPISources.cs
  12. 14
      src/Generator/Library.cs
  13. 3
      src/Parser/CppSharp.Parser.csproj

4
Directory.Build.props

@ -47,6 +47,10 @@ @@ -47,6 +47,10 @@
<GeneratorFileExtension>exe</GeneratorFileExtension>
<DotNetCmd></DotNetCmd>
</PropertyGroup>
<PropertyGroup Condition="$(MSBuildProjectFile.StartsWith('CppSharp.')) AND !$(MSBuildProjectFile.StartsWith('CppSharp.Generator.Tests'))">
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<Target Name="prepack" DependsOnTargets="Build" Condition="'$(IsPackable)' == 'true' AND '$(Platform)' == 'x64'">
<Copy SourceFiles="$(TargetDir)ref\$(TargetFileName)" DestinationFolder="$(PackageDir)ref\$(GlobalTargetFramework)" Condition="'$(ProduceReferenceAssembly)' == 'true' AND '$(RID)' == 'win-x64'" />

1
Directory.Packages.props

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageVersion Include="NUnit" Version="3.11.0" />

1
src/AST/CppSharp.AST.csproj

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<IsPackable>true</IsPackable>

12
src/CLI/Generator.cs

@ -108,7 +108,7 @@ namespace CppSharp @@ -108,7 +108,7 @@ namespace CppSharp
return true;
}
public void Setup(Driver driver)
public override void Setup(Driver driver)
{
var parserOptions = driver.ParserOptions;
parserOptions.TargetTriple = triple;
@ -168,21 +168,17 @@ namespace CppSharp @@ -168,21 +168,17 @@ namespace CppSharp
parserOptions.AddDefines("_GLIBCXX_USE_CXX11_ABI=" + (options.Cpp11ABI ? "1" : "0"));
}
public void SetupPasses(Driver driver)
public override void SetupPasses(Driver driver)
{
driver.Context.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass());
driver.Context.TranslationUnitPasses.AddPass(new MarshalPrimitivePointersAsRefTypePass());
}
public void GenerateCode(Driver driver, List<GeneratorOutput> outputs)
public override void Preprocess(Driver driver, ASTContext ctx)
{
}
public void Preprocess(Driver driver, ASTContext ctx)
{
}
public void Postprocess(Driver driver, ASTContext ctx)
public override void Postprocess(Driver driver, ASTContext ctx)
{
}

1
src/Core/CppSharp.csproj

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<IsPackable>true</IsPackable>

8
src/CppParser/Bindings/premake5.lua

@ -1,7 +1 @@ @@ -1,7 +1 @@
include ("CSharp")
if EnabledCLIProjects() and not os.getenv("CI") then
include ("CLI")
end
include ("CSharp")

8
src/CppParser/Bootstrap/Bootstrap.cs

@ -46,7 +46,7 @@ namespace CppSharp @@ -46,7 +46,7 @@ namespace CppSharp
return Directory.EnumerateDirectories(llvmDir, $"*{llvmRevision}*").FirstOrDefault();
}
public void Setup(Driver driver)
public override void Setup(Driver driver)
{
driver.Options.GeneratorKind = GeneratorKind.CSharp;
driver.Options.DryRun = true;
@ -83,11 +83,11 @@ namespace CppSharp @@ -83,11 +83,11 @@ namespace CppSharp
module.LibraryDirs.Add(Path.Combine(llvmPath, "lib"));
}
public void SetupPasses(Driver driver)
public override void SetupPasses(Driver driver)
{
}
public void Preprocess(Driver driver, ASTContext ctx)
public override void Preprocess(Driver driver, ASTContext ctx)
{
new IgnoreMethodsWithParametersPass { Context = driver.Context }
.VisitASTContext(ctx);
@ -116,7 +116,7 @@ namespace CppSharp @@ -116,7 +116,7 @@ namespace CppSharp
GenerateExpr(driver.Context);
}
public void Postprocess(Driver driver, ASTContext ctx)
public override void Postprocess(Driver driver, ASTContext ctx)
{
}

12
src/CppParser/ParserGen/ParserGen.cs

@ -44,7 +44,7 @@ namespace CppSharp @@ -44,7 +44,7 @@ namespace CppSharp
throw new Exception("Could not find build directory: " + dir);
}
public void Setup(Driver driver)
public override void Setup(Driver driver)
{
var parserOptions = driver.ParserOptions;
parserOptions.TargetTriple = Triple;
@ -118,11 +118,11 @@ namespace CppSharp @@ -118,11 +118,11 @@ namespace CppSharp
options.AddArguments("-stdlib=libc++");
}
public void SetupPasses(Driver driver)
public override void SetupPasses(Driver driver)
{
}
public void Preprocess(Driver driver, ASTContext ctx)
public override void Preprocess(Driver driver, ASTContext ctx)
{
ctx.RenameNamespace("CppSharp::CppParser", "Parser");
@ -146,7 +146,7 @@ namespace CppSharp @@ -146,7 +146,7 @@ namespace CppSharp
}
}
public void Postprocess(Driver driver, ASTContext ctx)
public override void Postprocess(Driver driver, ASTContext ctx)
{
}
@ -192,5 +192,9 @@ namespace CppSharp @@ -192,5 +192,9 @@ namespace CppSharp
Console.WriteLine();
}
}
public void GenerateCode(Driver driver, List<GeneratorOutput> outputs)
{
}
}
}

13
src/Generator.Tests/GeneratorTest.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using CppSharp.AST;
@ -20,7 +21,7 @@ namespace CppSharp.Utils @@ -20,7 +21,7 @@ namespace CppSharp.Utils
this.kind = kind;
}
public virtual void Setup(Driver driver)
public override void Setup(Driver driver)
{
var options = driver.Options;
options.GeneratorKind = kind;
@ -47,15 +48,15 @@ namespace CppSharp.Utils @@ -47,15 +48,15 @@ namespace CppSharp.Utils
testModule.Headers.Add(Path.GetFileName(file));
}
public virtual void Preprocess(Driver driver, ASTContext ctx)
public override void Preprocess(Driver driver, ASTContext ctx)
{
}
public virtual void Postprocess(Driver driver, ASTContext ctx)
public override void Postprocess(Driver driver, ASTContext ctx)
{
}
public virtual void SetupPasses(Driver driver)
public override void SetupPasses(Driver driver)
{
}
@ -101,6 +102,10 @@ namespace CppSharp.Utils @@ -101,6 +102,10 @@ namespace CppSharp.Utils
throw new Exception("Could not find tests output directory");
}
public void GenerateCode(Driver driver, List<GeneratorOutput> outputs)
{
}
#endregion
}
}

4
src/Generator/CppSharp.Generator.csproj

@ -12,4 +12,8 @@ @@ -12,4 +12,8 @@
<ProjectReference Include="..\Parser\CppSharp.Parser.csproj" />
<ProjectReference Include="$(NativeProjectsDir)Std-symbols.vcxproj" ReferenceOutputAssembly="false" Condition="$(IsWindows)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>

2
src/Generator/Generators/NAPI/NAPISources.cs

@ -28,7 +28,7 @@ namespace CppSharp.Generators.Cpp @@ -28,7 +28,7 @@ namespace CppSharp.Generators.Cpp
{
var paths = unit.FileRelativePath.Split('/').ToList();
paths = paths.Select(p => Path.GetFileNameWithoutExtension(p.ToLowerInvariant())).ToList();
var name = string.Join('_', paths);
var name = string.Join("_", paths);
return name;
}

14
src/Generator/Library.cs

@ -1,12 +1,10 @@ @@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using CodingSeb.ExpressionEvaluator;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
using CppSharp.Passes;
namespace CppSharp
@ -14,33 +12,33 @@ namespace CppSharp @@ -14,33 +12,33 @@ namespace CppSharp
/// <summary>
/// Used to massage the library types into something more .NET friendly.
/// </summary>
public interface ILibrary
public abstract class ILibrary
{
/// <summary>
/// Do transformations that should happen before passes are processed.
/// </summary>
void Preprocess(Driver driver, ASTContext ctx);
public abstract void Preprocess(Driver driver, ASTContext ctx);
/// <summary>
/// Do transformations that should happen after passes are processed.
/// </summary>
void Postprocess(Driver driver, ASTContext ctx);
public abstract void Postprocess(Driver driver, ASTContext ctx);
/// <summary>
/// Setup the driver options here.
/// </summary>
void Setup(Driver driver);
public abstract void Setup(Driver driver);
/// <summary>
/// Setup your passes here.
/// </summary>
/// <param name="driver"></param>
void SetupPasses(Driver driver);
public abstract void SetupPasses(Driver driver);
/// <summary>
/// Generate custom code here.
/// </summary>
void GenerateCode(Driver driver, List<GeneratorOutput> outputs) { }
public virtual void GenerateCode(Driver driver, List<GeneratorOutput> outputs) { }
}
public static class LibraryHelpers

3
src/Parser/CppSharp.Parser.csproj

@ -18,8 +18,7 @@ @@ -18,8 +18,7 @@
<ProjectReference Include="..\Core\CppSharp.csproj" />
<ProjectReference Include="..\AST\CppSharp.AST.csproj" />
<ProjectReference Include="..\Runtime\CppSharp.Runtime.csproj" />
<ProjectReference Include="..\CppParser\Bindings\CSharp\CppSharp.Parser.CSharp.csproj" Condition="!$(IsWindows) OR $(CI)" />
<ProjectReference Include="$(NativeProjectsDir)\CppSharp.Parser.CLI.vcxproj" Condition="$(IsWindows) AND !$(CI)" />
<ProjectReference Include="..\CppParser\Bindings\CSharp\CppSharp.Parser.CSharp.csproj" />
</ItemGroup>
<Target Name="PackNativeHeaders" AfterTargets="prepack" Condition="'$(RID)' == 'win-x64'">

Loading…
Cancel
Save