mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.15k stars 518 forks source link

Add support for Haiku #1840

Open nexus6-haiku opened 8 months ago

nexus6-haiku commented 8 months ago

I'm working on porting CppSharp to Haiku where we have a .NET SDK. It's not officially supported yet but it works pretty well. I've made all the necessary changes to support the new OS (x64 only) including providing a pre-built LLVM package (LLVM17 it's the latest we have, atm). I have a question on how to generate the bindings in src/CppParser/Bindings/CSharp. Currently I'm using a copy from Linux or MacOS but clearly it's not going to work as I get tons of errors like:

Generating bindings for Encodings (CSharp)
  Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named '?' in shared library 'Std-symbols'.
     at Std.BasicStringExtensions.__Internal.Data(IntPtr __instance)
     at Std.BasicStringExtensions.Data(BasicString`3 this) in /boot/home/workspace/CppSharp/src/CppParser/Bindings/CSharp/x86_64-unknown-haiku/Std.cs:line 540
     at CppSharp.Parser.CppParserOptions.get_ClangVersion() in /boot/home/workspace/CppSharp/src/CppParser/Bindings/CSharp/x86_64-unknown-haiku/CppSharp.CppParser.cs:line 41009
     at CppSharp.Parser.ParserOptions.get_BuiltinsDirBasePath() in /boot/home/workspace/CppSharp/src/Parser/ParserOptions.cs:line 408
     at CppSharp.Parser.ParserOptions.get_BuiltinsDir() in /boot/home/workspace/CppSharp/src/Parser/ParserOptions.cs:line 421
     at CppSharp.Parser.ParserOptions.SetupIncludes(TargetPlatform targetPlatform) in /boot/home/workspace/CppSharp/src/Parser/ParserOptions.cs:line 428
     at CppSharp.Parser.ParserOptions.Setup(TargetPlatform targetPlatform) in /boot/home/workspace/CppSharp/src/Parser/ParserOptions.cs:line 316
     at CppSharp.Driver.Setup() in /boot/home/workspace/CppSharp/src/Generator/Driver.cs:line 57
     at CppSharp.ConsoleDriver.Run(ILibrary library) in /boot/home/workspace/CppSharp/src/Generator/Driver.cs:line 399
     at CppSharp.Tests.EncodingsTestsGenerator.Main(String[] args) in /boot/home/workspace/CppSharp/tests/dotnet/Encodings/Encodings.Gen.cs:line 27

I'm a bit confused on how the process is supposed to be. Could these bindings be generated on Haiku itself or do I need to do it from another platform? I've gone through #1708 and #1825 but have not fully grasped how to create the bindings. Is there a step-by-step guide or could anyone provide some guidance?

nexus6-haiku commented 8 months ago

I've just built CppSharp on MacOS 14.4 (Intel) and I get the exact same error. I have net8.0 installed so I forced the target framework with

./build.sh -configuration Release -platform x64 -target-framework net8.0

On Haiku I just add -os haiku.

My main concern on generating the bindings remains but I'm wondering if there's another issue here.

tritao commented 7 months ago

Hello,

Missed this post, those bindings are generated by the ParserGen tool: https://github.com/mono/CppSharp/blob/main/src/CppParser/ParserGen/ParserGen.cs

You first will need to bootstrap the Haiku project from Linux, you will need to copy all the necessary system include header files to Linux and go from there.

nexus6-haiku commented 7 months ago

Hello @tritao, I've managed to compile the project from Haiku itself using the Linux bindings and all tests passed except 4, which was a good result. I've also managed to re-generate them from Haiku. Then I had to (re)apply a patch to LLVM that is not available yet in the version required by CppSharp to enable TLS (it has been merged upstream after that). Now I get two type of errors in different points:

  1. /boot/home/workspace/dotnet/CppSharp/build/gen/Encodings/Std.cs(229,43): error CS1001: Identifier expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/Encodings/Encodings.CSharp.csproj] /boot/home/workspace/dotnet/CppSharp/build/gen/Encodings/Std.cs(299,29): error CS1031: Type expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/Encodings/Encodings.CSharp.csproj] /boot/home/workspace/dotnet/CppSharp/build/gen/Encodings/Std.cs(308,88): error CS1031: Type expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/Encodings/Encodings.CSharp.csproj]

and

/boot/home/workspace/dotnet/CppSharp/build/gen/VTables/Std.cs(233,43): error CS1001: Identifier expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/VTables/VTables.CSharp.csproj] /boot/home/workspace/dotnet/CppSharp/build/gen/VTables/Std.cs(303,29): error CS1031: Type expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/VTables/VTables.CSharp.csproj] /boot/home/workspace/dotnet/CppSharp/build/gen/VTables/Std.cs(312,88): error CS1031: Type expected [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/VTables/VTables.CSharp.csproj]

These are mainly due to the lack of a type parameter, for example:

public unsafe partial class Allocator<> : IDisposable

2.

Generating bindings for NamespacesDerived (CSharp) Linking library libNamespacesBase-symbols.so... Linking success. CppSharp.Generator.Tests -> /boot/home/workspace/dotnet/CppSharp/bin/Release_x64/CppSharp.Generator.Tests.dll Linking library libNamespacesDerived-symbols.so... Linking success. Linking library libStd-symbols.so... Linking success. Linking library libCSharp-symbols.so... Linking success. Symbol not found: _ZN48SpecializationOfClassWithNonTypeTemplateArgumentD2Ev Symbol not found: _ZN48SpecializationOfClassWithNonTypeTemplateArgumentC2Ev Symbol not found: HasPureVirtualWithDefaultArg_HasPureVirtualWithDefaultArg Symbol not found: ProtectedConstructorDestructor_ProtectedConstructorDestructor Compilation succeeded: /boot/home/workspace/dotnet/CppSharp/build/gen/NamespacesDerived/Std.dll. CppSharp.Parser.Gen -> /boot/home/workspace/dotnet/CppSharp/bin/Release_x64/CppSharp.Parser.Gen.dll CppSharp.CLI -> /boot/home/workspace/dotnet/CppSharp/bin/Release_x64/CppSharp.CLI.dll /boot/home/workspace/dotnet/CppSharp/build/gen/CSharp/CSharp.cs(18241,40): warning CS8500: This takes the address of, gets the size of, or declares a pointer to a managed type ('T') [/boot/home/workspace/dotnet/CppSharp/tests/dotnet/CSharp/CSharp.CSharp.csproj] CSharp.CSharp -> /boot/home/workspace/dotnet/CppSharp/build/gen/CSharp/CSharp.CSharp.dll CSharp.Tests.CSharp -> /boot/home/workspace/dotnet/CppSharp/build/gen/CSharp/CSharp.Tests.CSharp.dll Compilation succeeded: /boot/home/workspace/dotnet/CppSharp/build/gen/NamespacesDerived/NamespacesBase.dll. Compilation succeeded: /boot/home/workspace/dotnet/CppSharp/build/gen/NamespacesDerived/NamespacesDerived.dll. Common.Gen -> /boot/home/workspace/dotnet/CppSharp/bin/Release_x64/Common.Gen.dll

Just as an example there is a symbol _ZN48SpecializationOfClassWithNonTypeTemplateArgumentaSEOS_ that unmangled is SpecializationOfClassWithNonTypeTemplateArgument::operator=(SpecializationOfClassWithNonTypeTemplateArgument&&)

Do you have any idea where to look at? Thank you!