-
Notifications
You must be signed in to change notification settings - Fork 518
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
[feature request] Support std::shared_ptr
(and complete Github Actions workflow example file with generating bindings of popular libraries)
#1860
Comments
I wrote down a primer of a minimalistic workflow file I meant above, looking to generate C API bindings to https://github.com/triton-inference-server/core/blob/main/include/triton/core/tritonserver.h Does CppSharp absolutely need to have access to CppSharp compiled How could name: tritonservercppsharp
on: workflow_dispatch
env:
PLATFORM: x64
jobs:
tritonservercppsharp:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Write down the bindings code
run: |
tee tritonservercppsharp.cs <<EOF
namespace CppSharpTransformer { class DllDemoGenerator : CppSharp.ILibrary {
public static void Main(string[] args) { CppSharp.ConsoleDriver.Run(new DllDemoGenerator()); }
public void SetupPasses(CppSharp.Driver driver) { }
public void Preprocess(CppSharp.Driver driver, ASTContext ctx) { }
public void Postprocess(CppSharp.Driver driver, ASTContext ctx) { }
void ILibrary.Setup(CppSharp.Driver driver) { }
void Setup(CppSharp.Driver driver) {
var options = driver.Options;
options.GeneratorKind = GeneratorKind.CSharp;
var module = options.AddModule("TritonServerCppSharp");
module.IncludeDirs.Add("core/include");
module.Headers.Add("triton/core/tritonserver.h");
//module.LibraryDirs.Add("/path/to/triton/which/containslibtritonserver.so/");
//module.Libraries.Add("libtritonserver.so");
}
} }
EOF
- name: Clone and build CppSharp
run: |
#wget https://dot.net/v1/dotnet-install.sh && bash dotnet-install.sh --channel 9.0
git clone --single-branch --depth 1 --branch v1.1 https://github.com/mono/CppSharp
cd CppSharp
bash build/build.sh generate -configuration Release -platform $PLATFORM
bash build/build.sh download_llvm -platform $PLATFORM
bash build/build.sh restore -platform $PLATFORM
bash build/build.sh -platform $PLATFORM -build_only
find bin
dotnet --version
- name: Generating bindings
run: |
git clone --single-branch --depth 1 --branch r23.03 https://github.com/triton-inference-server/core
#"$HOME/.dotnet"
DOTNET_ROOT=/usr/share/dotnet
DOTNETSDKVER=$(dotnet --version)
DOTNETFWKVER=$(dotnet --list-runtimes | grep Microsoft.NETCore.App | tail -n 1 | cut -d " " -f2)
DOTNETLIBDIR="$DOTNET_ROOT/shared/Microsoft.NETCore.App/$DOTNETFWKVER"
LD_LIBRARY_PATH=CppSharp/bin/Release_x64/ dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" -r:CppSharp/bin/Release_x64/CppSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.AST.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.dll $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') -target:library -out:tritonservercppsharp.exe tritonservercppsharp.cs
dotnet tritonservercppsharp.exe
# - uses: actions/upload-artifact@v4
# with:
# path: CppSharp/bin/Release_x64/ |
Sure, though this way will compile CppSharp from source (which I personally like, though takes a bit more time).
IIRC it does not need it, it's only used to find which symbols are provided by the compiled libraries. Especially for C libraries this is not a concern, because header-only inline symbols are usually not present. For C++, it might be a concern depending on the library. Also to note, for some applications, the CppSharp CLI might be useful since it does not need a custom C# code setup: https://github.com/mono/CppSharp/blob/main/src/CLI/CLI.cs Customization is harder in that case, but does not have to be the case. I would be very helpful to provide a declarative customization model for simple cases (YAML or even C# script based). |
Is there an example of using this tool anywhere? For simple things (and as a baseline), it should indeed be sufficient! I think it's worth advertising a complete example of using this option in the CppSharp's README directly (to have a complete example with
For this case, do I need to do Thanks! |
The test suite is using it, but I would check out the CLI tool directly, as it provides help and description for the parameters:
I think these are the main ones:
I am not the best person to ask about Nuget as I rarely use it in my workflows. But development versions are pushed to GitHub packages:
https://github.com/mono/CppSharp/pkgs/nuget/CppSharp The last version says it was published 4 months ago, so maybe publishing for ongoing development commits is not working correctly after all. |
For some reason I'm getting problems loading the generated
name: tritonservercppsharp
on: workflow_dispatch
env:
PLATFORM: x64
jobs:
tritonservercppsharp:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Write down the bindings code
run: |
tee tritonservercppsharp.cs <<EOF
namespace CppSharpTransformer { public class DllDemoGenerator : CppSharp.ILibrary {
public static void Main(string[] args) { CppSharp.ConsoleDriver.Run(new DllDemoGenerator()); }
public void SetupPasses(CppSharp.Driver driver) { }
public void Preprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Postprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Setup(CppSharp.Driver driver) {
var options = driver.Options;
options.GeneratorKind = CppSharp.Generators.GeneratorKind.CSharp;
var module = options.AddModule("TritonServerCppSharp");
module.IncludeDirs.Add("core/include");
module.Headers.Add("triton/core/tritonserver.h");
module.Headers.Add("triton/core/tritonbackend.h");
module.Headers.Add("triton/core/tritoncache.h");
module.Headers.Add("triton/core/tritonrepoagent.h");
//module.LibraryDirs.Add("/path/to/triton/server.so");
//module.Libraries.Add("tritonserver.so");
} } }
EOF
- name: Clone and build CppSharp
run: |
#wget https://dot.net/v1/dotnet-install.sh && bash dotnet-install.sh --channel 9.0
git clone --single-branch --depth 1 https://github.com/mono/CppSharp
cd CppSharp
bash build/build.sh generate -configuration Release -platform $PLATFORM
bash build/build.sh download_llvm -platform $PLATFORM
bash build/build.sh restore -platform $PLATFORM
bash build/build.sh -platform $PLATFORM -build_only
find bin
- name: Generating bindings
run: |
git clone --single-branch --depth 1 https://github.com/triton-inference-server/core
#"$HOME/.dotnet"
DOTNET_ROOT=/usr/share/dotnet
DOTNETSDKVER=$(dotnet --version)
DOTNETFWKVER=$(dotnet --list-runtimes | grep Microsoft.NETCore.App | tail -n 1 | cut -d " " -f2)
DOTNETLIBDIR="$DOTNET_ROOT/shared/Microsoft.NETCore.App/$DOTNETFWKVER"
dotnet --version
dotnet --list-runtimes
echo $DOTNETSDKVER $DOTNETFWKVER
# -r:CppSharp/bin/Release_x64/CppSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.AST.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.dll
#echo 'namespace ProgramNamespace { public static class Program { public static void Main(string[] args) { System.Console.WriteLine("Hello world!"); } } }' > footest.cs
#dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') -target:exe -out:footest.exe footest.cs
#echo '{"runtimeOptions":{"framework":{"name":"Microsoft.NETCore.App","version":"'$DOTNETFWKVER'"}}}' > footest.runtimeconfig.json
#dotnet footest.exe
find CppSharp/bin/Release_x64 -name 'CppSharp*.dll'
# -r:CppSharp/bin/Release_x64/CppSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.AST.dll -r:CppSharp/bin/Release_x64/CppSharp.Runtime.dll -r:CppSharp/bin/Release_x64/CppSharp.CLI.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.CSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.Bootstrap.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.Gen.dll
dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') $(find CppSharp/bin -name "*.dll" -printf '-r:"%p" ') -target:exe -out:tritonservercppsharp.exe tritonservercppsharp.cs
echo '{"runtimeOptions":{"framework":{"name":"Microsoft.NETCore.App","version":"'$DOTNETFWKVER'"}}}' > tritonservercppsharp.runtimeconfig.json
echo BEFORE
find CppSharp/bin -name "*.dll" -o -name "*.so" -exec cp {} . ';'
dotnet tritonservercppsharp.exe |
Have you tried this locally or are you running only on CI? |
Only on CI. It appears that dotnet does not like the
|
With the similar command: echo 'namespace ProgramNamespace { public static class Program { public static void Main(string[] args) { System.Console.WriteLine("Hello world!"); } } }' > footest.cs
dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') -target:exe -out:footest.exe footest.cs
echo '{"runtimeOptions":{"framework":{"name":"Microsoft.NETCore.App","version":"'$DOTNETFWKVER'"}}}' > footest.runtimeconfig.json
dotnet footest.exe this runs with success but maybe the problem is that the build command uses a different dotnet / runtime and hence incompat with the runtime I use for running the compiled app?
|
Seems likely, any reason you are installing a separate .NET version instead of using the system one? |
I am not installing any separate .NET. This line is commented out |
Ok, have you tried without this |
It appears in {
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
}, |
Because otherwise |
Ok, must be a new .NET feature, previously I don't remember that being necessary. Maybe this can help, you can pass |
I've tried that. This indeed makes name: tritonservercppsharp
on: workflow_dispatch
env:
PLATFORM: x64
FRAMEWORK: net80
DOTNET_ROOT: /usr/share/dotnet
DOTNETSDKVER: 8.0.303
DOTNETFWKVER: 8.0.7
jobs:
tritonservercppsharp:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Write down the bindings code
run: |
tee tritonservercppsharp.cs <<EOF
namespace CppSharpTransformer { public class DllDemoGenerator : CppSharp.ILibrary {
public static void Main(string[] args) { CppSharp.ConsoleDriver.Run(new DllDemoGenerator()); }
public void SetupPasses(CppSharp.Driver driver) { }
public void Preprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Postprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Setup(CppSharp.Driver driver) {
var options = driver.Options;
options.GeneratorKind = CppSharp.Generators.GeneratorKind.CSharp;
var module = options.AddModule("TritonServerCppSharp");
module.IncludeDirs.Add("core/include");
module.Headers.Add("triton/core/tritonserver.h");
module.Headers.Add("triton/core/tritonbackend.h");
module.Headers.Add("triton/core/tritoncache.h");
module.Headers.Add("triton/core/tritonrepoagent.h");
//module.LibraryDirs.Add("/path/to/triton/server.so");
//module.Libraries.Add("tritonserver.so");
} } }
EOF
- name: Clone and build CppSharp
run: |
git clone --single-branch --depth 1 https://github.com/mono/CppSharp
cd CppSharp
bash build/build.sh generate -configuration Release -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh download_llvm -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh restore -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh -platform $PLATFORM -build_only -target-framework $FRAMEWORK
find bin
- name: Generating bindings
run: |
git clone --single-branch --depth 1 https://github.com/triton-inference-server/core
dotnet --version
dotnet --list-runtimes
DOTNETLIBDIR="$DOTNET_ROOT/shared/Microsoft.NETCore.App/$DOTNETFWKVER"
#DOTNETSDKVER=$(dotnet --version)
#DOTNETFWKVER=$(dotnet --list-runtimes | grep Microsoft.NETCore.App | tail -n 1 | cut -d " " -f2)
echo 'namespace ProgramNamespace { public static class Program { public static void Main(string[] args) { System.Console.WriteLine("Hello world!"); } } }' > footest.cs
dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') -target:exe -out:footest.exe footest.cs
echo '{"runtimeOptions":{"framework":{"name":"Microsoft.NETCore.App","version":"'$DOTNETFWKVER'"}}}' > footest.runtimeconfig.json
dotnet footest.exe
# -r:CppSharp/bin/Release_x64/CppSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.AST.dll -r:CppSharp/bin/Release_x64/CppSharp.Runtime.dll -r:CppSharp/bin/Release_x64/CppSharp.CLI.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.CSharp.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.Bootstrap.dll -r:CppSharp/bin/Release_x64/CppSharp.Parser.Gen.dll
dotnet "$DOTNET_ROOT/sdk/$DOTNETSDKVER/Roslyn/bincore/csc.dll" $(find "$DOTNETLIBDIR" -name "*.dll" -printf '-r:"%p" ') $(find CppSharp/bin -name "*.dll" -printf '-r:"%p" ') -target:exe -out:tritonservercppsharp.exe tritonservercppsharp.cs
echo '{"runtimeOptions":{"framework":{"name":"Microsoft.NETCore.App","version":"'$DOTNETFWKVER'"}}}' > tritonservercppsharp.runtimeconfig.json
find CppSharp/bin -name "*.dll" -o -name "*.so" -exec cp {} . ';'
dotnet tritonservercppsharp.exe || true
- uses: actions/upload-artifact@v4
with:
path: |
CppSharp/bin/
tritonservercppsharp.cs
tritonservercppsharp.runtimeconfig.json
tritonservercppsharp.exe |
Ha-ha, it seems that running a csc-compiled file referencing assemblies obtained from |
I've tried also using cp ./CppSharp/bin/Release_x64/libCppSharp.CppParser.so ./CppSharp/bin/Release_x64/libStd-symbols.so .
mkdir output && ./CppSharp/bin/Release_x64/CSharp.Gen -I core/include/triton/core -o ./output/ More errors:
But I couldn't figure out where the symbols So somehow these are some test functions from CppSharp itself:
why is it searching for these symbols? Is it trying to run some tests? |
And the Driver path gives this error. How do I make this Clang resource file findable?
|
I think CSharp.Gen is just an artifact built for generating the tests bindings.
Sure, there should be a |
Okay, I managed to build two variants. Some notes:
I guess I'll try now to bind the C++ headers at https://github.com/triton-inference-server/developer_tools/tree/main/server/include/triton/developer_tools My overall impression: complete, fully self-contained examples are desperately needed (and especially of the name: tritonservercppsharp
on: workflow_dispatch
env:
PLATFORM: x64
FRAMEWORK: net80
FRAMEWORKDOT: net8.0
jobs:
tritonservercppsharp:
runs-on: ubuntu-22.04
steps:
- name: Clone tritonserver
run: |
git clone --single-branch --depth 1 --branch r24.08 https://github.com/triton-inference-server/core
git clone --single-branch --depth 1 --branch r24.08 https://github.com/triton-inference-server/developer_tools
- name: Clone and build CppSharp
run: |
git clone --single-branch --depth 1 https://github.com/mono/CppSharp
cd CppSharp
bash build/build.sh generate -configuration Release -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh download_llvm -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh restore -platform $PLATFORM -target-framework $FRAMEWORK
bash build/build.sh -platform $PLATFORM -build_only -target-framework $FRAMEWORK
- name: Variant 1
run: ./CppSharp/bin/Release_x64/CppSharp.CLI -m tritonserver -g csharp -p linux -a x64 -o ./variant1/ -I=core/include core/include/triton/core/tritonserver.h core/include/triton/core/tritonbackend.h core/include/triton/core/tritoncache.h core/include/triton/core/tritonrepoagent.h
- name: Variant 2
run: |
echo '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><EnableDefaultItems>false</EnableDefaultItems></PropertyGroup><ItemGroup><Compile Remove="**/*.cs"/><Compile Include="tritonservercppsharp.cs"/><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Runtime.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.AST.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Generator.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.CLI.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Parser.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Parser.CSharp.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Parser.Bootstrap.dll</HintPath></Reference><Reference Include="MyAssembly"><HintPath>./CppSharp/bin/Release_x64/CppSharp.Parser.Gen.dll</HintPath></Reference></ItemGroup></Project>' > tritonservercppsharp.csproj
tee tritonservercppsharp.cs <<EOF
namespace CppSharpTransformer { public class DllDemoGenerator : CppSharp.ILibrary {
public static void Main(string[] args) { CppSharp.ConsoleDriver.Run(new DllDemoGenerator()); }
public void SetupPasses(CppSharp.Driver driver) { }
public void Preprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Postprocess(CppSharp.Driver driver, CppSharp.AST.ASTContext ctx) { }
public void Setup(CppSharp.Driver driver) {
var options = driver.Options;
options.GeneratorKind = CppSharp.Generators.GeneratorKind.CSharp;
var module = options.AddModule("tritonserver");
options.OutputDir = "variant2";
module.IncludeDirs.Add(".");
module.IncludeDirs.Add("core/include");
module.Headers.Add("core/include/triton/core/tritonserver.h");
module.Headers.Add("core/include/triton/core/tritonbackend.h");
module.Headers.Add("core/include/triton/core/tritoncache.h");
module.Headers.Add("core/include/triton/core/tritonrepoagent.h");
//module.LibraryDirs.Add("/path/to/triton/server.so");
//module.Libraries.Add("tritonserver.so");
} } }
EOF
mkdir -p bin/x64/Release/$FRAMEWORKDOT && cp -r ./CppSharp/bin/Release_x64/lib bin/x64/Release/$FRAMEWORKDOT/lib
LD_PRELOAD=$PWD/CppSharp/bin/Release_x64/libCppSharp.CppParser.so:$PWD/CppSharp/bin/Release_x64/libStd-symbols.so dotnet run -c Release
- uses: actions/upload-artifact@v4
with:
path: |
variant1/
variant2/ |
Tried adding to wrap https://github.com/triton-inference-server/developer_tools/blob/main/server/include/triton/developer_tools/server_wrapper.h - getting an error ServerOptions(
const std::vector<std::string>& model_repository_paths,
const LoggingOptions& logging, const MetricsOptions& metrics,
const std::vector<BackendConfig>& be_config, const std::string& server_id,
const std::string& backend_dir, const std::string& repo_agent_dir,
const bool disable_auto_complete_config,
const ModelControlMode& model_control_mode,
const int32_t repository_poll_secs,
const std::set<std::string>& startup_models,
const std::vector<RateLimitResource>& rate_limit_resource,
const int64_t pinned_memory_pool_byte_size,
const std::vector<CUDAMemoryPoolByteSize>& cuda_memory_pool_byte_size,
const uint64_t response_cache_byte_size,
const double& min_cuda_compute_capability, const bool exit_on_error,
const int32_t exit_timeout_secs,
const int32_t buffer_manager_thread_count,
const uint32_t model_load_thread_count,
const std::vector<ModelLoadGPULimit>& model_load_gpu_limit,
const std::vector<HostPolicy>& host_policy, std::shared_ptr<Trace> trace);
InferOptions(
const std::string& model_name, const int64_t model_version,
const std::string& request_id, const uint64_t correlation_id,
const std::string& correlation_id_str, const bool sequence_start,
const bool sequence_end, const uint64_t priority,
const uint64_t request_timeout,
std::shared_ptr<Allocator> custom_allocator,
std::shared_ptr<Trace> trace);
|
std::shared_ptr
(and complete Github Actions workflow example file with generating bindings of popular libraries)
I was not able build package via scripts on windows so I made nuspec file which works to get some context... although I'm pretty sure it is dropping lib files at the moment. <?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>CppSharp</id>
<version>x.y.z</version>
<authors>CppSharp Devs</authors>
<owners>Mono</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>YOU!</description>
<dependencies>
<dependency id="Microsoft.Win32.Registry" version="5.0.0"/>
</dependencies>
<contentFiles>
<files include="any/any/**/*.h" buildAction="Content" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="bin\Release_x64\CppSharp.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.AST.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.Generator.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.Parser.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.CppParser.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.CppParser.lib" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.Parser.CLI.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\CppSharp.Parser.CLI.lib" target="lib\netstandard2.1" />
<file src="bin\Release_x64\Std-symbols.dll" target="lib\netstandard2.1" />
<file src="bin\Release_x64\Std-symbols.lib" target="lib\netstandard2.1" />
<file src="bin\Release_x64\Ijwhost.dll" target="lib\netstandard2.1" />
<!-- Clang headers which path changes depend upon what version of Clang is downloaded -->
<!-- Are needed see "Parser/ParserOptions.cs" -->
<file src="build\llvm\llvm-6eb36a-windows-vs2022-x64-RelWithDebInfo\lib\**\include\**\*.h" target="contentFiles\any\any\lib\" />
</files>
</package> |
What is CppSharp behavior for binding C++ classes destructors? Does it generate Regarding binding In modern C++, plenty of various pointer wrappers could now be used in APIs like Otherwise, in C# classes have reference/shared_ptr-like semantics anyway, so maybe no wrappers are needed... |
We do not support
Yes, see the
We could start by just allowing for manual reference count increase and decrease, which at least would already allow supporting those objects. But the main reason I did not spend too much time with standard library constructs is that it leads to non portable bindings, where you need generated C# bindings code for each ABI, which complicates packaging and distribution on the C# side. Hence I always recommend modifying the original C++ code, or creating a portable wrapper on top of it. You can check out the |
Thanks for explaining! Deleting
I think for bindings not distributed publicly but generated, compiled and consumed on the target platform, it is okay to support non-ABI-portable things like So overall, JavaCpp seems to support shared_ptr: bytedeco/javacpp#623 Maybe for CppSharp, the model of a single repo with GitHub Actions - i.e. JavaCpp presets repo: https://github.com/bytedeco/javacpp-presets, reproducbile bindings generation could also be very useful: https://github.com/bytedeco/javacpp-presets |
It will ignore any methods and fields that are not supported, so the binding can still be generated.
They support it by generating C++ code (with JNI) which is a lot more doable for C++ standard library constructs. With the regular CppSharp approach, it only generates C++ code for inline symbols for which there is absolute no other way. Its doable to do the same for other C++ std lib types, but overall its somewhat complicated and error prone.
No doubt, this would be great, was always on my mind, but its a lot of work to setup and maintain, so unless someone else is willing to do the dirty work, its not going to happen from my side. |
Maybe then an example/recipe in the docs for adding non-portable support for
Maybe if it's not to support a high-quality bar and just be a place where people contribute single-file, self-contained GitHub Actions workflow files as examples, then the maintenance bar would be lower and some reproducibility would be preserved. And also might be nice if https://github.com/dotnet org or https://dotnetfoundation.org/ sponsored/supported this effort...
But yeah, I see what you mean... |
UPD: the missing
std::shared_ptr<T>
support context is in the message #1860 (comment). Currently this support seems missing, andshared_ptr
/unique_ptr
are quite common types in modern C++ APIs to be processedJavaCpp seems to support binding
std::shared_ptr<T>
: bytedeco/javacpp#623Below is a very long thread where we ended up rolling a fully complete GitHub Actions Workflow file.
GitHub Actions allow for a reproducible environment, so pulling in-tree a collection of GitHub Actions workflow files for popular libraries from https://github.com/mono/CppSharp?tab=readme-ov-file#users (like ffmpeg or dearimgui) could be a great start for new users showcasing the install procedures.
And sometimes it would be possible to just copy the filly self-contained workflow-file and modify it to create a command for binding-generation for a new library. Then users could send PRs with such workflows/scripts, and they could be tested easily (and especially - tested against new versions of the libraries). Currently https://github.com/mono/CppSharp/tree/main/tests doesn't have many real-world library examples.
I found https://github.com/mono/CppSharp/blob/main/.github/workflows/main.yml. Could it be considered a base for such a workflow file producing a fully functioning llvm+CppSharp install?
The text was updated successfully, but these errors were encountered: