btzy / nativefiledialog-extended

Cross platform (Windows, Mac, Linux) native file dialog library with C and C++ bindings, based on mlabbe/nativefiledialog.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Universal Bindings

ds5678 opened this issue · comments

We are running into some issues while generating cross platform bindings for .NET. It mostly arises from the use of macros to define the utf8 functions on Mac and Linux. On Windows, both native and utf8 functions get exported, but on Mac and Linux, only native functions get exported.

I see two potential solutions:

  • On Mac and Linux, change the utf8 macros to function definitions, so that all 3 platforms have both sets of function exports.
  • On Mac and Linux, change utf8 to be the default and native to be the macro.

Macros seem to be, on hindsight, a bad idea.

On Mac and Linux, change the utf8 macros to function definitions, so that all 3 platforms have both sets of function exports.

I think this is the better thing to do - get rid of the macros, and have all 3 platforms export both sets of functions. It should probably be possible in the Mac and Linux implementations to have some __attribute__((alias("stuff"))) stuff to map both exports to the same function definition, so we don't need extra function wrappers (and the header file shouldn't need to know about this aliasing stuff). Will this work with the binding generators? If they only consume the header file, then I think it should work. This should be fully ABI compatible, and essentially API compatible unless someone uses complicated macro or template magic over the macros in the library.

On Mac and Linux, change utf8 to be the default and native to be the macro.

We can't do this without breaking ABI. NFDe is a package at least on Fedora, which uses it as a dynamic library, so changing the names of exported functions will result in a loader error on the end user's machine. Also, those who build NFDe statically will get link errors. In any case, I don't think continuing to use macros are a good idea, just to save a few bytes in the compiled library.

I'm running into issues on Mac because of signature differences:

NFD_API void NFD_FreePathN(nfdnchar_t* filePath);
NFD_API void NFD_PathSet_FreePathN(const nfdnchar_t* filePath);

//I used real function definitions on Mac and Windows because alias seems unsupported.
void NFD_PathSet_FreePathN(const nfdnchar_t* filePath) {
    NFD_FreePathN(const_cast<nfdnchar_t*>(filePath)); //const_cast doesn't seem to be supported on Mac.
}

https://github.com/AssetRipper/nativefiledialog-extended/actions/runs/7171753252
https://github.com/AssetRipper/nativefiledialog-extended/tree/replace-macros-with-alias

I figured it out. :)