COMMUNITY

Ammer and Anvil: Haxe Native Extension Toolkit

In case anyone else has had their attention drawn to @Aurel300’s ammer library, I’ve put together a class you can call from an initialization macro that works quite well for Windows.

I haven’t tested for other platforms, but presumably, if the build process works on your platform, it will work for others on the same platform (see #30).

If you’re a library author, and you want to distribute native extensions built with ammer, you should try anvil.

Both projects are both at version 0.0.1, hopefully that answers any questions about production readiness :slight_smile:

But, it works quite well, and I’ve gotten it to work on two different rigs of very different calibers so I’m optimistic.

ammer will build your stub code provided some preconditions are met (the native library the stub code relies on has been built and is in a place that is accessible to the user’s output directory).

anvil essentially takes care of those preconditions by asking 3 questions:

  • What’s your native library called (what does ammer know it as)
  • Where’s your native library located (relative to the project root directory)
  • What build command will you run (usually you will include a Makefile or a CMakeLists.txt and use something like nmake or cmake)

What anvil does not do:

  • Create Makefiles or CMakeLists.txt (or in any way reason about how to build the c files, it simply runs a command, that command should produce binaries, whatever restrictions that may come with for the user, in my case, you have to be using Windows and you need the MSVC toolchain)
  • Facilitate any cross-platform usage of an ammer library: If the native extension isn’t cross-platform, anvil won’t change that.
3 Likes

So… what does anvil do?

Oops. I wrote a whole reply and had to delete it because I didn’t actually reply, I commented.

Can’t repost it either. Maybe adding this disclaimer at the beginning will fool the repost guard :wink:

Basically, it just allows you to hoist the files Ammer needs to use ammer projects.

For example, a user of an ammer lib needs to build the native code and copy it to their project (or somewhere they can access) then set -D ammer.lib.<lib>.library=path/where/they/built/native

Anvil is meant to be run from an initialization macro, it will basically build your native code for users, copy the dynamic libs to their project and set the Ammer macros via haxe.macro.Compiler.define

You’d put an initialization macro calling anvil.Anvil.run() in your haxelibs extraParams.hxml and Anvil will build the native library for users of your library based in the .anvilrc config at the haxelibs root.

I’m still actively working on improving it.

One thing I’m working in is HxMake, which takes hxml-like “Makefiles” and allows users of your project to specify the toolchain, and it will run the appropriate compiler (cl, gcc, clang, etc…)

That sort of works, and I’m now working towards allowing Anvils buildCmd config to be replaced with hxMakefile which would point to that hxml like file and build it for users using their specified tool chain (users would specify this via a macro in their hxml referencing the native extension library, something like -D hxmake-compiler=gcc)

The tests may be currently broken because I’m still in that hxmake transition. It worked fine with buildCmd but was tied to, well, a single buildCmd which still leaves much of putting together the build process up to the library author.

Anvil does support multiple platforms and native libraries, so for instance if you have a unique build chain or require different libraries per platform (likely, like named pipes and Unix sockets) you’d probably have an hxMakefile for each platform.

1 Like

Note that that name is already being used by another project: https://github.com/eliasku/hxmake :slight_smile:

Dang, I should’ve replied sooner.

Now there’s two I guess until I come up with a new name.

HxMake is here; hxml like syntax to build your C sources (HxMake is included in the latest anvil, so if you’re already using anvil, you can just use HxMakefiles and anvilshould run them; this has only been tested with lix, not sure how well its running with just haxelib yet)

An example HxMakefile:

-lib odbc32
-src odbc.c
-o odbc.dll
-win-api

(-win-api becomes -mwindows on gcc; ignored on cl, clang and clang-cl behavior is inherited from GCC and CL, so it will pass -mwindows to clang as well, but not clang-cl)

You can see an example of HxMake/HxMakefiles in use in the hxdbc project (look in odbc_native and look at the .anvilrc at the root)

ETA: I originally considered HxCC (simple; Haxe C Compiler) since it’s not really a Makefile (though it does execute two separate commands, like most Makefiles), I might rename it to that

So, why don’t you use CMake?