Description
Introductory Information:
Hashlink is basically the successor Neko in terms of Haxe VM targets, with the added advantage of having both a compiled-C and a bytecode target.
HXCPP is the traditional workhorse of Haxe native C++ targets.
Hashlink promises some advantages to workflow -- particularly faster compilation speed during development, but it's still relatively new and most of the C/C++ bindings for existing libraries for Haxe native targets are still written for HXCPP, and HXCPP is a solid well-maintained target that will surely see continued use alongside HashLink. This puts native extension library maintainers in a dilemma, do we support HXCPP or Hashlink, or both? Right now supporting both means maintaining two parallel sets of bindings, which is not only double the work, but also fertile ground for subtle duplication/oops-I-forgot-to-update-the-other-one errors.
This bounty is for developing a common format for writing native extensions to C API's for Haxe, that is compatible with both HXCPP and HashLink.
This is a separate issue from automatically generating native extensions with minimal effort from, say, raw C files. It's okay for the sake of this bounty if the accepted solution requires a bit of manual labor in writing the bindings themselves, so long as each binding doesn't have to be written twice, once for HXCPP and once for HashLink.
The Project
- Produce a method that bridges a C API to Haxe
- The solution should produce both HL bindings and HXCPP bindings
- The programmer should only have to write an "exposure" for a given C API function once, and get both bindings out of it
- Provide a working proof of concept example of limited scope
- Open source the whole shebang under MIT license or equivalent
- The exposed Haxe interface should match the C interface as closely as possible
- Absolute minimum dependencies
- Account for and note any "leaky abstractions" / incompatibilities between HXCPP & HL
- Minimize use of operations that generate expensive side-effects (such as hidden Dynamics on HXCPP target) -- libraries that rely on this solution should be suitable for high-performance things like physics and rendering.
- Exact approach (e.g. using CFFI, CFFI Prime, C externs, untyped C blocks, etc) is entirely up to you, just provide a reasoning for why your solution is the best one you could think of compared to the alternatives.
The sample should:
- Demonstrate passing two numbers from Haxe, adding them together on the C side, and returning them to Haxe
- Demonstrate passing a file name from Haxe, loading the file and resolving it as raw bytes on the C side, and returning the bytes to Haxe
- Demonstrate passing two (ASCII) strings from Haxe, concatenate them together on the C side, and return them to Haxe
- Demonstrate all the above, with the functions implemented in loose .c and/or .h files
- Demonstrate all the above, with the functions implemented in a .dll file
- Be able to be compiled and run against hxcpp target and hl target with a simple .hxml script
Out of scope
None of these things are part of the project:
- C++ API support (we only care about supporting plain C API's for now, save this for later)
- Exhaustive documentation (just a simple example and a quick description is fine)
- Unicode string support in the sample (just ASCII is fine for now)
- Pass a structured object from Haxe, mutate some of its values on the C side, and return it to Haxe
- Properly handle a C api that asks for a C data structure as input (important to solve eventually but let's not worry about it just yet)
- Automatic generation of bindings from a minimal description (such as c header files alone or whatever)
Prerequisites
- Knowledge of HXCPP
- Knowledge of Hashlink
- Knowledge of Macros
- Knowledge of C
What's been done so far
Nothing specifically on this project, but here's some prior work to learn form:
- Linc -- solely focused on HXCPP
- Everything I know about CFFI / CFFI Prime
- Haxe externs
- Hashlink links:
- Updates from comments:
How Much can Lars help?
- I'm available to talk to and ask/answer questions but you'll be doing the majority if not all the work here. I recognize I'm out of my depth.
What remains to be done
- The whole thing!
Budget/Timeline:
- No specific timeline. 1 month would be great? I'd like to see it done before November.
Budget is $100 USD. $200 USD $250 USD