xlab / c-for-go

Automatic C-Go Bindings Generator for Go Programming Language
https://c.for-go.com
MIT License
1.47k stars 116 forks source link

Request: v8 #104

Open tmc opened 3 years ago

tmc commented 3 years ago

My naive attempt of generating bindings for v8.h via:

GENERATOR: 
  PackageName: v8
  PackageDescription: "Package v8 provides Go bindings for V8"
  # PkgConfigOpts: [v8]
  Includes: ["v8.h"]
  Options:
    SafeStrings: true
PARSER: 
  IncludePaths: [
    "/usr/include",
    "/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/usr/include/",
    "../../v8/v8/include",
  ]
  SourcesPaths: ["v8.h"]

results in:

  processing v8.yml ⠙[ERR] ../../v8/v8/include/cppgc/common.h:11:11: unexpected identifier cppgc, expected one of ['(', ')', ',', ':', ';', '=', '[', '{', _Bool, _Complex, _Noreturn, _Static_assert, asm, auto, char, const, double, enum, extern, float, inline, int, long, register, restrict, short, signed, static, struct, typedef, typedefname, typeof, union, unsigned, void, volatile] (and 7 more errors)

I gather it's the namespace..

xlab commented 3 years ago

Unfortunately, namespace is a C++ feature. And V8 is also written in C++. So no bindings directly, usually C++ needs to be wrapped additionally into C code, and that C code can be used in bindings. That's true for most C++ projects, due to lack of stable ABI for C++.

Look at this work for example https://github.com/augustoroman/v8/blob/master/v8_c_bridge.cc

Also this: https://github.com/lazytiger/go-v8/blob/master/v8_wrap.cc

So you can only generate bindings using the corresponding C headers.