RainwayApp / node-clangffi

Generate Typescript FFI bindings for C/C++ libraries using libclang and ffi-napi.
MIT License
7 stars 1 forks source link

feat: --clean-enum-constants flag #48

Closed lynn closed 2 years ago

lynn commented 2 years ago

Making a draft for this, because it's finished in theory but I can't test it 😅

I get a crash like so:

PS C:\code\node-clangffi> cat hi.h
enum MyEnum {
    MY_ENUM_FOO = 1,
    MY_ENUM_BAR = 2,
};

PS C:\code\node-clangffi> npm run clangffi --  --clean-enum-constants -i hi.h -o hi.ts

> node-clangffi-lerna-workspace@1.0.0 clangffi
> node packages/clangffi/dist/bin/clangffi.js "--clean-enum-constants" "-i" "hi.h" "-o" "hi.ts"

Invalid CXChildVisitResult!
UNREACHABLE executed at C:\src\llvm_package_1400-rc2\llvm-project\clang\tools\libclang\CIndex.cpp:236!

on every invocation of clangffi. Have you ever seen this @bengreenier?

bengreenier commented 2 years ago

hmm - what version of clang do you have? It could be a mismatch between libclang-bindings and your actual libclang.dll. Here's what I get when I run your test with this branch:

import ffi from "ffi-napi";
import ref, { Pointer as TypedPointer, UnderlyingType } from "ref-napi";
import refStructDi, { StructObject } from "ref-struct-di";
import refArrayDi, { TypedArray } from "ref-array-di";

const Struct = refStructDi(ref);
const Array = refArrayDi(ref);
const Pointer = ref.refType;
export enum MyEnum {
  MY_ENUM_FOO = 1,
  MY_ENUM_BAR = 2,
}
export const MyEnumDef = ref.types.int;
export function dlopen(libPath: string) {
  return ffi.Library(libPath, {});
}

I have:

λ clang --version
clang version 13.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
bengreenier commented 2 years ago

For even more context - If this ends up being due to clang versions - I'd like to add packages that wrap their releases (or get them on postInstall) - just haven't gotten around to it. But that would be a big win for a few reasons: