Skip to content

Commit

Permalink
尝试cppsharp
Browse files Browse the repository at this point in the history
  • Loading branch information
maikebing committed Aug 21, 2022
1 parent de76d7c commit 5613f1c
Show file tree
Hide file tree
Showing 12 changed files with 1,477 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,4 @@ ASALocalRun/
/src/Example/TDengine-client-2.0.1.1-Linux-x64.tar.gz
/src/Example/core
/src/Example/TDengine-client-2.0.3.1-Linux-x64.tar.gz
/src/ConsoleAppCppSharp/Driver
17 changes: 16 additions & 1 deletion EFCore.Taos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-co
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkCore.Taos.Tests", "src\EntityFrameworkCore.Taos.Tests\EntityFrameworkCore.Taos.Tests.csproj", "{7F5F12D6-CA82-4499-AF3E-6CA7E61579CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.ORM.Taos", "src\IoTSharp.ORM.Taos\IoTSharp.ORM.Taos.csproj", "{C7819FDC-BA05-42DD-88A6-97F2B0D9D783}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.ORM.Taos", "src\IoTSharp.ORM.Taos\IoTSharp.ORM.Taos.csproj", "{C7819FDC-BA05-42DD-88A6-97F2B0D9D783}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ORMExample", "src\ORMExample\ORMExample.csproj", "{9961CED3-F482-41E7-AB0D-17EC37FD637D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppCppSharp", "src\ConsoleAppCppSharp\ConsoleAppCppSharp.csproj", "{9474C715-BB6C-445B-B80A-387A95751E93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -138,6 +140,18 @@ Global
{9961CED3-F482-41E7-AB0D-17EC37FD637D}.Release|x64.Build.0 = Release|Any CPU
{9961CED3-F482-41E7-AB0D-17EC37FD637D}.Release|x86.ActiveCfg = Release|Any CPU
{9961CED3-F482-41E7-AB0D-17EC37FD637D}.Release|x86.Build.0 = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|x64.ActiveCfg = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|x64.Build.0 = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|x86.ActiveCfg = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Debug|x86.Build.0 = Debug|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|Any CPU.Build.0 = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|x64.ActiveCfg = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|x64.Build.0 = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|x86.ActiveCfg = Release|Any CPU
{9474C715-BB6C-445B-B80A-387A95751E93}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -149,6 +163,7 @@ Global
{61524D14-E365-4D00-A058-479AAE4D2B49} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{C7819FDC-BA05-42DD-88A6-97F2B0D9D783} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
{9961CED3-F482-41E7-AB0D-17EC37FD637D} = {B24685BC-E919-46BE-ADE8-52AC8697A1F1}
{9474C715-BB6C-445B-B80A-387A95751E93} = {CE6B50B2-34AE-44C9-940A-4E48C3E1B3BC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705}
Expand Down
30 changes: 30 additions & 0 deletions src/ConsoleAppCppSharp/ConsoleAppCppSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Driver\TDengine-client-3.0.0.0\**" />
<EmbeddedResource Remove="Driver\TDengine-client-3.0.0.0\**" />
<None Remove="Driver\TDengine-client-3.0.0.0\**" />
</ItemGroup>



<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CppSharp" Version="1.0.1" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>



<ItemGroup>
<Folder Include="Driver\" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions src/ConsoleAppCppSharp/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using CommandLine.Text;
using CommandLine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppCppSharp
{
public class Options
{


[Option(
Required = true,
HelpText = "输入解压路径.")]
public string Path { get; set; }

[Option(
Required = true,
HelpText = "涛思数据的版本")]
public string Version { get; set; }


}

}
47 changes: 47 additions & 0 deletions src/ConsoleAppCppSharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommandLine;
using CppSharp;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using System.Text;

namespace ConsoleAppCppSharp
{
internal class Program
{
static async Task Main(string[] args)
{
await Parser.Default.ParseArguments<Options>(args)
.WithParsedAsync(async o =>
{

var client = new HttpClient();
using var buffer = await client.GetStreamAsync($"https://www.taosdata.com/assets-download/3.0/TDengine-client-{o.Version}-Linux-x64.tar.gz");
if (!Directory.Exists(o.Path)) Directory.CreateDirectory(o.Path);
ExtractTarGz(buffer, o.Path);
ExtractTarGz(Path.Combine(o.Path, $"TDengine-client-{o.Version}", "taos.tar.gz"), Path.Combine(o.Path, "taos"));

ConsoleDriver.Run(new TaosLibrary(o.Path, o.Version));
});
}



public static bool ExtractTarGz(string path, string goalFolder)
{
using (var inStream = File.OpenRead(path))
{
return ExtractTarGz(inStream, goalFolder);
}
}
public static bool ExtractTarGz(Stream inStream, string goalFolder)
{
using (var gzipStream = new GZipInputStream(inStream))
{
var tarArchive = TarArchive.CreateInputTarArchive(gzipStream, Encoding.Default);
tarArchive.ExtractContents(goalFolder);
tarArchive.Close();
}
return true;
}
}
}
52 changes: 52 additions & 0 deletions src/ConsoleAppCppSharp/TaosLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppCppSharp
{
internal class TaosLibrary : ILibrary
{
private string path;
private readonly string version;

public TaosLibrary(string path,string version)
{
this.path = path;
this.version = version;
}


public void Setup(CppSharp.Driver driver)
{
var options = driver.Options;
options.GeneratorKind = GeneratorKind.CSharp;
var module = options.AddModule("taos");
module.IncludeDirs.Add(System.IO.Path.Combine(path, "taos","inc"));
module.Headers.Add("taos.h");

// module.LibraryDirs.Add(System.IO.Path.Combine(path, $"TDengine-client-{version}", "driver"));
//module.Libraries.Add($"libtaos.so.{version}");
options.OutputDir = path;
module.OutputNamespace = "taos";
}

public void Preprocess(Driver driver, ASTContext ctx)
{
}

public void Postprocess(Driver driver, ASTContext ctx)
{
}

public void SetupPasses(Driver driver)
{
driver.Generator.Context.ParserOptions.LanguageVersion =
CppSharp.Parser.LanguageVersion.C99;
}
}
}
2 changes: 1 addition & 1 deletion src/Example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
apt-get -y -q update && apt-get install -y -q apt-utils libgdiplus libc6-dev lsof net-tools wget curl iputils-ping inetutils-tools && \
apt-get autoremove -y && apt-get clean && apt-get autoclean && rm /var/cache/apt/* -rf && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN curl -o TDengine-client.tar.gz "https://www.taosdata.com/assets-download/TDengine-client-3.0.0.0-Linux-x64.tar.gz" && \
RUN curl -o TDengine-client.tar.gz "https://www.taosdata.com/assets-download/3.0/TDengine-client-3.0.0.0-Linux-x64.tar.gz" && \
tar -xvf TDengine-client.tar.gz && rm TDengine-client.tar.gz -f && cd $(ls TDengine-client* -d) && \
./install_client.sh && \
rm $(pwd) -rf
Expand Down
Loading

0 comments on commit 5613f1c

Please sign in to comment.