Start investigating swigless csharp

This commit is contained in:
Ramana Kumar 2022-10-04 19:45:12 +01:00
parent 9512abbcfc
commit f5e95c497c
No known key found for this signature in database
GPG Key ID: ED471C788B900433
4 changed files with 23 additions and 10 deletions

1
.gitignore vendored
View File

@ -22,4 +22,5 @@ inc/blst_aux.h*
*bindings/python/*_wrap.c *bindings/python/*_wrap.c
*bindings/C#/*_wrap.c *bindings/C#/*_wrap.c
*bindings/C#/*.exe *bindings/C#/*.exe
*bindings/C#/*.dll
__pycache__ __pycache__

View File

@ -1,11 +1,8 @@
INCLUDE_DIRS = .. ../../min-src ../../inc INCLUDE_DIRS = .. ../../min-src ../../inc
test: tests.cs libckzg.so ckzg_swig.cs test: tests.cs ckzg.dll
mcs -langversion:5 -optimize+ tests.cs ckzg_swig.cs -r:System.Numerics.dll mcs tests.cs
mono tests.exe ./tests.exe
libckzg.so: c_kzg_4844_wrap.c ../../min-src/c_kzg_4844.o ../../lib/libblst.a ckzg.dll: ckzg.c ../../min-src/c_kzg_4844.o ../../lib/libblst.a
clang -O -Wall -shared -fPIC -Wl,-Bsymbolic -I${INCLUDE_PY} ${addprefix -I,${INCLUDE_DIRS}} -o $@ $^ clang -O -Wall -shared ${addprefix -I,${INCLUDE_DIRS}} -o $@ $^
c_kzg_4844_wrap.c ckzg_swig.cs: ../c_kzg_4844.swg
swig -DSWIGWORDSIZE64 -O -Wall -csharp -outcurrentdir -namespace ckzg -outfile ckzg_swig.cs $<

8
min-bindings/C#/ckzg.c Normal file
View File

@ -0,0 +1,8 @@
#include <inttypes.h>
#include <stdio.h>
#include "c_kzg_4844.h"
uint64_t hello(uint64_t a) {
printf("Hello World! %lu\n", a);
return 42;
}

View File

@ -1,10 +1,17 @@
using System; using System;
using System.Text; using System.Text;
using ckzg;
class PoC { class ckzg {
[global::System.Runtime.InteropServices.DllImport("ckzg.dll", EntryPoint="hello")]
public static extern uint hello(uint a);
[global::System.Runtime.InteropServices.DllImport("ckzg.dll", EntryPoint="bytes_to_bls_field_wrap")]
public static extern void bytes_to_bls_field(byte[] b);
}
class tests {
private static void Main(string[] args) private static void Main(string[] args)
{ {
Console.WriteLine("OK"); Console.WriteLine("OK");
Console.WriteLine(ckzg.hello(32));
} }
} }