Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# automatic binding #202

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "examples/rust/orderbook.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# bindings = ["ligen", "ligen-macro", "ligen-csharp"]
bindings = ["ligen", "ligen-macro", "ligen-cargo", "ligen-rust", "ligen-csharp"]
default = ["rust_gmp"]
rust_gmp = ["openlimits-nash/rust_gmp"]
num_bigint = ["openlimits-nash/num_bigint"]
Expand All @@ -25,16 +25,20 @@ openlimits-binance = "0.3.0"
openlimits-exchange = "0.3.0"
openlimits-coinbase = "0.3.0"
openlimits-nash = "0.3.0"
# ligen-macro = { path = "../../sensorial/systems/ligen/ligen/macro", optional = true }
# ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
# lazy_static = "1.4.0"
ligen-macro = { path = "../../sensorial/systems/ligen/ligen/macro", optional = true }
ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
lazy_static = "1.4.0"
rust_decimal = "1.17.0"
tokio = { version = "1.0", features = ["full"] }

[dev-dependencies]
rust_decimal = "1.14.3"
tokio = { version = "1.0", features = ["full"] }
futures = "0.3"
dotenv = "0.15.0"

[build-dependencies]
# ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
# ligen-csharp = { path = "../../sensorial/systems/ligen/generators/ligen-csharp", optional = true }
ligen = { path = "../../sensorial/systems/ligen/ligen", optional = true }
ligen-cargo = { path = "../../sensorial/systems/ligen/generators/ligen-cargo", optional = true }
ligen-rust = { path = "../../sensorial/systems/ligen/generators/ligen-rust", optional = true }
ligen-csharp = { path = "../../sensorial/systems/ligen/generators/ligen-csharp", optional = true }
serde_json = "1.0.73"
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix hardcoded values in CargoBuilde
17 changes: 13 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@

fn main() {
#[cfg(feature = "bindings")]
{
use ligen::prelude::*;
use ligen::traits::build::{BuildSystem, BuildProfile};
use ligen_csharp::CSharpGenerator;
use ligen_cargo::{CargoProject, CargoGenerator, CargoBuilder};
use ligen_rust::RustGenerator;

match Project::current() {
match CargoProject::current().and_then(Project::try_from) {
Ok(project) => {
println!("Generating C# bindings...");
let rust_generator = RustGenerator::default();
let csharp_generator = CSharpGenerator::default();
csharp_generator.generate(&project).expect("Failed to generate C# bindings.");
let cargo_generator = CargoGenerator::default();
let cargo_builder = CargoBuilder;
cargo_generator.generate(&project).expect("Failed to generate Cargo interface.");
rust_generator.generate(&project).expect("Failed to generate Rust interface.");
csharp_generator.generate(&project).expect("Failed to generate C# interface.");
cargo_builder.build(&project, BuildProfile::Release).expect("Failed to build Cargo project.");
},
Err(e) => println!("e: {:#?}", e)
Err(_) => ()
}
}
}
Expand Down
29 changes: 13 additions & 16 deletions examples/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@ class Program
{
static public void Main(string[] args)
{
var ffi_string = Client.FFIGetName();
Console.WriteLine(ffi_string);
// var ptr = FFIString.FFIGetPointer(ffi_string);
// Console.WriteLine(ptr);
return;
CoinbaseParameters parameters = new CoinbaseParameters(Environment.Production, "a", "b", "c");
string key = parameters.apiKey;
Client client = Client.Coinbase(parameters);
Console.WriteLine("String: " + Client.GetName());
Console.WriteLine("Appended string: " + Client.AppendString("estringue"));
Console.WriteLine("Appended strings in structure: " + Client.AppendParameters(parameters));
// Client client = Client.Coinbase(parameters);
// Console.WriteLine(Decimal.Parse(askBid.qty));
// Console.WriteLine(Decimal.Parse(askBid.qty));
// Console.WriteLine(askBid.price);
var list = new List<ulong>();
list.Add(1);
list.Add(2);
list.Add(3);
Console.WriteLine(client.Sum(list));
var result = client.Mul(list, 2);
foreach (var value in result) {
Console.WriteLine(value);
}
// var list = new List<ulong>();
// list.Add(1);
// list.Add(2);
// list.Add(3);
// Console.WriteLine(client.Sum(list));
// var result = client.Mul(list, 2);
// foreach (var value in result) {
// Console.WriteLine(value);
// }

// Test.Display(person);
// NashClientConfig config = NashClientConfig.Unauthenticated(0, NashEnvironment.Production, 1000);
Expand Down
4 changes: 2 additions & 2 deletions examples/csharp/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# cargo build --manifest-path ../../Cargo.toml
cp ../../target/ligen/openlimits/lib/openlimits.dll ./bin/Debug/netcoreapp5.0/openlimits_csharp.dll
# cp ../../target/ligen/openlimits/lib/libopenlimits.so ./bin/Debug/netcoreapp5.0/libopenlimits_csharp.so
cp ../../target/ligen/ffi/openlimits/target/release/ffi_openlimits.dll ./bin/Debug/netcoreapp5.0/ffi_openlimits.dll
#cp ../../target/ligen/ffi/openlimits/target/release/libffi_openlimits.so ./bin/Debug/netcoreapp5.0/libffi_openlimits.so
dotnet run

29 changes: 29 additions & 0 deletions examples/test/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace test {
class Account {
public decimal quantity { get; set; }
}

class Person {
public string name { get; set; }
public int age { get; set; }
public Account account { get; set; }
}

class Program {
static void Main(string[] args) {
var person = new Person();
person.name = "Danilo";
person.age = 33;
person.account = new Account();
person.account.quantity = 12314;
string json = JsonSerializer.Serialize(person);
Console.WriteLine(json);
Person fromJson = JsonSerializer.Deserialize<Person>(json);
Console.WriteLine(fromJson.account.quantity);
}
}
}
Binary file added examples/test/bin/Debug/net5.0/ref/test.dll
Binary file not shown.
23 changes: 23 additions & 0 deletions examples/test/bin/Debug/net5.0/test.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v5.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v5.0": {
"test/1.0.0": {
"runtime": {
"test.dll": {}
}
}
}
},
"libraries": {
"test/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
Binary file added examples/test/bin/Debug/net5.0/test.dll
Binary file not shown.
Binary file added examples/test/bin/Debug/net5.0/test.exe
Binary file not shown.
Binary file added examples/test/bin/Debug/net5.0/test.pdb
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/test/bin/Debug/net5.0/test.runtimeconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\dangu\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\dangu\\.nuget\\packages"
]
}
}
9 changes: 9 additions & 0 deletions examples/test/bin/Debug/net5.0/test.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]
Binary file added examples/test/obj/Debug/net5.0/apphost.exe
Binary file not shown.
Binary file added examples/test/obj/Debug/net5.0/ref/test.dll
Binary file not shown.
22 changes: 22 additions & 0 deletions examples/test/obj/Debug/net5.0/test.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("test")]
[assembly: System.Reflection.AssemblyTitleAttribute("test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a987eb0675210088860249537ec979b0010c987d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
is_global = true
build_property.TargetFramework = net5.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.PublishSingleFile =
build_property.IncludeAllContentForSelfExtract =
build_property._SupportedPlatformList = Android,iOS,Linux,macOS,Windows
Binary file added examples/test/obj/Debug/net5.0/test.assets.cache
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d9bf6df19d9e130c226f3887e01298d8b37e12eb
16 changes: 16 additions & 0 deletions examples/test/obj/Debug/net5.0/test.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.exe
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.deps.json
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.runtimeconfig.json
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.runtimeconfig.dev.json
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.dll
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\ref\test.dll
C:\Users\dangu\dev\nash-io\openlimits\examples\test\bin\Debug\net5.0\test.pdb
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.csproj.AssemblyReference.cache
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.AssemblyInfoInputs.cache
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.AssemblyInfo.cs
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.csproj.CoreCompileInputs.cache
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.dll
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\ref\test.dll
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.pdb
C:\Users\dangu\dev\nash-io\openlimits\examples\test\obj\Debug\net5.0\test.genruntimeconfig.cache
Binary file added examples/test/obj/Debug/net5.0/test.dll
Binary file not shown.
1 change: 1 addition & 0 deletions examples/test/obj/Debug/net5.0/test.genruntimeconfig.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9431f34b09501de181957879814907a9286e0a25
Binary file added examples/test/obj/Debug/net5.0/test.pdb
Binary file not shown.
67 changes: 67 additions & 0 deletions examples/test/obj/project.assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"version": 3,
"targets": {
"net5.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net5.0": []
},
"packageFolders": {
"C:\\Users\\dangu\\.nuget\\packages\\": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj",
"projectName": "test",
"projectPath": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj",
"packagesPath": "C:\\Users\\dangu\\.nuget\\packages\\",
"outputPath": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\dangu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net5.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.301\\RuntimeIdentifierGraph.json"
}
}
}
}
8 changes: 8 additions & 0 deletions examples/test/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "gO3WnxcOMFsZZjjB0297LhcfU7a6K3Cpyd7dVt/BeQ1EpiBmJVghuNWMVBzZQNpjOGnrCFc+PBrgreLx9o04VQ==",
"success": true,
"projectFilePath": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj",
"expectedPackageFiles": [],
"logs": []
}
62 changes: 62 additions & 0 deletions examples/test/obj/test.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"format": 1,
"restore": {
"C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj": {}
},
"projects": {
"C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj",
"projectName": "test",
"projectPath": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\test.csproj",
"packagesPath": "C:\\Users\\dangu\\.nuget\\packages\\",
"outputPath": "C:\\Users\\dangu\\dev\\nash-io\\openlimits\\examples\\test\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\dangu\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net5.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net5.0": {
"targetAlias": "net5.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.301\\RuntimeIdentifierGraph.json"
}
}
}
}
}
Loading