aurel300 / ammer Goto Github PK
View Code? Open in Web Editor NEWUnified FFI for Haxe native extensions
Home Page: https://aurel300.github.io/ammer/
License: MIT License
Unified FFI for Haxe native extensions
Home Page: https://aurel300.github.io/ammer/
License: MIT License
The workaround is to store a reference to the pointer globally in C so it can be used statically, and move the Haxe method from the Pointer type to the Library type as a static function.
I'd like to see a linux section in the README, and a Makefile.linux. I'm not super familiar with native workflows, but I'm guessing the Makefile.linux would be something like:
all: libadder.so adder.o
libadder.so: adder.o
gcc -shared -fPIC -o libadder.so adder.o -lc
adder.o: adder.c
gcc -c -fPIC -o adder.o adder.c
.PHONY: all
I'd be happy to test the workflow. Let me know if you have input on the above.
Haxe side:
Void
enum
s though)Native side:
int32
float
(rather than double
)struct
s - Haxe won't do struct passing in general but we can construct a struct
at the callsite from the object; may not be very performantVector<Float>
in HaxeRecent replacement of types like int
with int32_t
breaks compilation if user’s header file doesn’t include <stdint.h>
. Maybe all such includes should be at StubHl.hx
?
ammer/git/src/ammer/internal/Ammer.hx:34: characters 41-59 : Type not found : ammer.core.Builder
I've included the amber-core project, but it can't seem to find it.
os:ubuntu 18
haxe :nightly build
ammer:git versin
step:
cd samples/poc/native
make -f Makefiles.linux
cd ../
haxe build-common.hxml
/root/haxe/haxelib/ammer/git/src/ammer/Ammer.hx:403: characters 16-17 : Unknown identifier : C
/root/haxe/haxelib/ammer/git/src/ammer/Ammer.hx:403: characters 16-17 : ... For function argument 'map'
Adder.hx:5: character 1 : Build failure
Adder.hx:5: character 1 : ... For function argument 'v'
Main.hx:1: lines 1-8 : ... Defined in this class
Main.hx:4: characters 32-46 : Class<Adder> has no field concat_strings
Main.hx:5: characters 40-49 : Class<Adder> has no field load_file
Main.hx:6: characters 45-58 : Class<Adder> has no field reverse_bytes
I tried to build my project with haxe 4.2.3
I got this error
ammer/FFITools.hx:115: characters 9-59 : invalid FFI type for return
Verbose
Calling macro ammer.Pointer.initType (?:1)
Exiting macro ammer.Pointer.initType
Calling macro ammer.Ammer.buildType (/Volumes/Vibranium/Users/damilare/haxe/haxe_libraries/ammer/0.0.1/github/9fe359b15fcdec1685c2bbe879f5e9c56c0ebcdc/src/ammer/FFITools.hx:111)
Calling macro ammer.Pointer.initType (?:1)
Exiting macro ammer.Pointer.initType
Calling macro ammer.Ammer.buildType (/Volumes/Vibranium/Users/damilare/haxe/haxe_libraries/ammer/0.0.1/github/9fe359b15fcdec1685c2bbe879f5e9c56c0ebcdc/src/ammer/FFITools.hx:111)
Exiting macro ammer.Ammer.buildType
Parsed /Volumes/Vibranium/Users/damilare/haxe/haxe_libraries/ammer/0.0.1/github/9fe359b15fcdec1685c2bbe879f5e9c56c0ebcdc/src/ammer/conv/ArrayWrapper.hx
/Volumes/Vibranium/Users/damilare/haxe/haxe_libraries/ammer/0.0.1/github/9fe359b15fcdec1685c2bbe879f5e9c56c0ebcdc/src/ammer/FFITools.hx:115: characters 9-59 : invalid FFI type for return
I am working on a project that involves audio decoding. Unlike video frames, audio data packets are represented as float **
, how do I carry this forward to Haxe by using ammer? How do I represent and use this type in Haxe?
Is this appropriate? ammer.ffi.ArrayDynamic<ammer.Pointer<"float">>
It would be nice to have tools which could detect which methods and variables should be declared in the ammer library definition. Possible methods:
LUA_API
in lua)All of this can go horribly wrong and will need manual work for nearly any library, but tools could still make the process less tedious.
I noticed this library is not uploaded to lib.haxe.org, is that intentional?
Mention some common problems that can happen during the build.
vcvars32
or developer promptHow do I make Ammer find headers installed on the system?? I am using a Mac.
decoder.h:29:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
Ideally APIs should be mapped one-to-one, but it might be good to provide an option to inject C code directly into the glue code. All of ammer targets need to compile some C or C++ after all.
I have a C++ code
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#define LIB_EXPORT __declspec(dllexport)
#else
#define LIB_EXPORT
#endif
#include <stdlib.h>
#ifdef HXCPP
#include <hxcpp.h>
#endif
class leb128 {
public:
template<typename int_t = uint64_t>
LIB_EXPORT size_t encodeVarint(int_t value, Array<unsigned char> output) {
size_t outputSize = 0;
//While more than 7 bits of data are left, occupy the last output byte
// and set the next byte flag
while (value > 127) {
//|128: Set the next byte flag
output[outputSize] = ((uint8_t)(value & 127)) | 128;
//Remove the seven bits we just wrote
value >>= 7;
outputSize++;
}
output[outputSize++] = ((uint8_t)value) & 127;
return outputSize;
}
template<typename int_t = uint64_t>
LIB_EXPORT int_t decodeVarint(unsigned char *input, size_t inputSize) {
int_t ret = 0;
for (size_t i = 0; i < inputSize; i++) {
ret |= (input[i] & 127) << (7 * i);
//If the next-byte flag is set
if(!(input[i] & 128)) {
break;
}
}
return ret;
}
};
#ifdef __cplusplus
}
#endif
I can call decodeVarint like this decodeVarint<uint32_t>(input, size);
How do I do this with Haxe & ammer ?
It loooks like Ammer is building in the wrong order; I'm not 100% sure what the build process is for Ammer, but I assume it generally is supposed to "build out" the Library<T>
type (in its entirety) first before attempting to build the Library's derived Pointer
types.
However, with this code:
import ammer.*;
import ammer.ffi.*;
import haxe.io.Bytes;
// @:ammer.nativePrefix("odbc_")
class Odbc extends Library<"odbc"> {
public static function odbc_connect(cnxStr:String):OdbcCtx;
// public static function test_sql():Int;
}
// @:ammer.nativePrefix("odbc_")
class OdbcCtx extends Pointer<"odbc_ctx_t", Odbc> {
public function odbc_execute(_:ammer.ffi.This, query:String):OdbcStmtCtx;
public function odbc_disconnect(_:ammer.ffi.This):Bool;
public function odbc_get_ctx_errors(_:ammer.ffi.This):String;
}
// @:ammer.nativePrefix("odbc_")
class OdbcStmtCtx extends Pointer<"odbc_stmt_t", Odbc> {
public function odbc_get_stmt_errors(_:ammer.ffi.This):String;
public function odbc_get_column_name(_:ammer.ffi.This, i:Int):String;
public function odbc_get_column_datatype(_:ammer.ffi.This, i:Int):Int;
public function odbc_get_column_size(_:ammer.ffi.This, i:Int):UInt;
public function odbc_get_column_decimal_digits(_:ammer.ffi.This, i:Int):Int;
public function odbc_get_column_nullable(_:ammer.ffi.This, i:Int):Int;
}
OdbcStmtCtx
doesn't build because for some reason the compiler is trying to find its fields in the Odbc
Library class, see the error:
Odbc.hx:17: characters 5-67 : Class<Odbc> has no field odbc_get_stmt_errors (Suggestion: odbc_get_ctx_errors)
Odbc.hx:18: characters 5-74 : Class<Odbc> has no field odbc_get_column_name
Odbc.hx:19: characters 5-75 : Class<Odbc> has no field odbc_get_column_datatype
Odbc.hx:20: characters 5-72 : Class<Odbc> has no field odbc_get_column_size
Odbc.hx:21: characters 5-81 : Class<Odbc> has no field odbc_get_column_decimal_digits
Odbc.hx:22: characters 5-75 : Class<Odbc> has no field odbc_get_column_nullable
I assume what happens is static methods get created on the library method which are then called in the Pointer
instance methods, for whatever reason, the Library
static methods for OdbcStmtCtx
aren't being built before Ammer attempts to build OdbcStmtCtx
's Pointer
type.
When I forcefully inject the methods into the Library
type like so:
class Odbc extends Library<"odbc"> {
public static function odbc_connect(cnxStr:String):OdbcCtx;
public static function odbc_get_stmt_errors(ptr:OdbcStmtCtx):String;
public static function odbc_get_column_name(ptr:OdbcStmtCtx, i:Int):String;
public static function odbc_get_column_datatype(ptr:OdbcStmtCtx, i:Int):Int;
public static function odbc_get_column_size(ptr:OdbcStmtCtx, i:Int):UInt;
public static function odbc_get_column_decimal_digits(ptr:OdbcStmtCtx, i:Int):Int;
public function odbc_get_column_nullable(ptr:OdbcStmtCtx, i:Int):Int;
// public static function test_sql():Int;
}
It builds (or at least gets further in the build process) and then errors out:
Odbc.hx:23: characters 5-67 : Duplicate class field declaration : Odbc.odbc_get_stmt_errors
Odbc.hx:5: lines 5-14 : Defined in this class
Odbc.hx:24: characters 5-74 : Duplicate class field declaration : Odbc.odbc_get_column_name
Odbc.hx:5: lines 5-14 : Defined in this class
Odbc.hx:25: characters 5-75 : Duplicate class field declaration : Odbc.odbc_get_column_datatype
Odbc.hx:5: lines 5-14 : Defined in this class
Odbc.hx:26: characters 5-72 : Duplicate class field declaration : Odbc.odbc_get_column_size
Odbc.hx:5: lines 5-14 : Defined in this class
Odbc.hx:27: characters 5-81 : Duplicate class field declaration : Odbc.odbc_get_column_decimal_digits
Odbc.hx:5: lines 5-14 : Defined in this class
Odbc.hx:28: characters 5-75 : Same field name can't be used for both static and instance : odbc_get_column_nullable
Odbc.hx:5: lines 5-14 : Defined in this class
Which to me seems to indicate that the static library fields do indeed get added, just not soon enough in the build process.
I'm having problems with hl.h
on Linux...
> haxe -D ammer.hl.hlInclude=/home/jward/dev/hashlink/src -D ammer.hl.hlLibrary=/home/jward/dev/hashlink/ build-hl.hxml
make: Entering directory '/home/jward/dev/ammer/samples/poc/bin/hl'
cc -fPIC -o ammer_adder.hl.o -c ammer_adder.hl.c -I /home/jward/dev/ammer/samples/poc/native
ammer_adder.hl.c:2:10: fatal error: hl.h: No such file or directory
#include <hl.h>
^~~~~~
compilation terminated.
Makefile.hl.ammer:8: recipe for target 'ammer_adder.hl.o' failed
make: *** [ammer_adder.hl.o] Error 1
make: Leaving directory '/home/jward/dev/ammer/samples/poc/bin/hl'
It appears that the Makefile.hl.ammer
does not include my reference to the hl include directory:
> cat bin/hl/Makefile.hl.ammer
all: ammer_adder.hdll
@:
ammer_adder.hdll: ammer_adder.hl.o
$(CC) $(CFLAGS) -I /home/jward/dev/ammer/samples/poc/native -D LIBHL_EXPORTS -m64 -shared -o ammer_adder.hdll ammer_adder.hl.o -L/home/jward/dev/hashlink/ -lhl -L/home/jward/dev/ammer/samples/poc/native -ladder
ammer_adder.hl.o: ammer_adder.hl.c
$(CC) $(CFLAGS) -fPIC -o ammer_adder.hl.o -c ammer_adder.hl.c -I /home/jward/dev/ammer/samples/poc/native
.PHONY: all
I have tried the ammer sample project here in this lib.
I have build the windows dll with success.
I can compile to hxcpp and the exe is working as attended.
But I can't compile to hl, here is my error:
C:\HaxeToolkit\haxe\lib\ammer\git\samples\poc>haxe build-hl.hxml
Uncaught exception Null Access
C:\HaxeToolkit\haxe\lib\ammer/git/src/ammer/build/BuildTools.hx:76: characters 29-70 : Called from here
C:\HaxeToolkit\haxe\lib\ammer/git/src/ammer/LineBuf.hx:25: characters 5-8 : Called from here
C:\HaxeToolkit\haxe\lib\ammer/git/src/ammer/build/BuildTools.hx:41: lines 41-101 : Called from here
C:\HaxeToolkit\haxe\lib\ammer/git/src/ammer/build/BuildHl.hx:10: lines 10-34 : Called from here
C:\HaxeToolkit\haxe\lib\ammer/git/src/ammer/Ammer.hx:439: characters 9-53 : Called from here
Is there a specific haxe version to use?
Mine is : 4.1.2
I've got a native function that passes through int argc, char* argv[]
. Is it possible to call this function from within ammer? I didn't see anything that looked immediately relevant on https://aurel300.github.io/ammer/definition-ffi.html but I'm also not super familiar with Haxe to know how this might map over.
Unbuntu 22.10
Haxe 4.3.0
ammer-core-rewrite
HEAD
I don't understand why the linker can't find string
for one thing, but why is it looking in ammer_libtypes
for lib.neko.o
when it wrote it to ammer_aria2
?
It seems the call that should generate lib.neko.so
in ammer_aria2
isn't working
-main Main
-cp src/main/haxe
-D ammer.buildPath=tmp
-D ammer.outputPath=.local/bertha/i/pkg/aria2/lib/gnu
--no-output
-L stx
-L ammer
-neko test.n
src/main/eu/ohmrun/ammer/include
package eu.ohmrun.aria2.include;
@:ammer.lib.includePath("../../../../../../../vendor/aria2/src/includes/aria2/")
@:ammer.lib.headers.include("aria2.h")
class Aria2 extends ammer.def.Library<"aria2"> {
public static function libraryInit():Int;
}
Error
mkdir /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes
mkdir /mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu
write /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.c (121221 characters)
compile object /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.c -> /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.o
run cc [-fPIC,-o,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.o,-c,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.c]
link library /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.o -> /mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu/ammer_libtypes.ndll
run cc [-m64,-o,/mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu/ammer_libtypes.ndll,-shared,-fPIC,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_libtypes/lib.neko.o,-lneko]
mkdir /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2
mkdir /mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu
write /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.c (4665 characters)
compile object /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.c -> /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.o
run cc [-fPIC,-o,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.o,-c,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.c,-I,/mnt/dat/i/prj/haxe/dev/aria2/vendor/aria2/src/includes/aria2]
link library /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.o -> /mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu/ammer_aria2.ndll
run cc [-m64,-o,/mnt/dat/i/prj/haxe/dev/aria2/.local/bertha/i/pkg/aria2/lib/gnu/ammer_aria2.ndll,-shared,-fPIC,/mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.o,-lneko,-laria2]
In file included from /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.c:116:
/mnt/dat/i/prj/haxe/dev/aria2/vendor/aria2/src/includes/aria2/aria2.h:38:10: fatal error: string: No such file or directory
38 | #include <string>
| ^~~~~~~~
compilation terminated.
/usr/bin/ld: cannot find /mnt/dat/i/prj/haxe/dev/aria2/tmp/ammer_aria2/lib.neko.o: No such file or directory
/usr/bin/ld: cannot find -laria2: No such file or directory
collect2: error: ld returned 1 exit status
/mnt/dat/i/prj/haxe/published/stx_release/src/main/haxe/eu/ohmrun/pml/Module.hx:16: characters 33-64 : Warning : (WDeprecated) Usage of this field is deprecated
/mnt/dat/u/lib/haxe/tink_state/git/src/tink/state/Promised.hx:16: characters 21-34 : Warning : (WDeprecated) Use Promise.never() instea
This list is only for documenting which interfaces exist.
(what can help is to autogenerate swig files? http://www.swig.org/)
Target | Interface | Implemented | Planned |
---|---|---|---|
Javascript | Emscript | false | false |
NodeJs | N-API | false | true |
HashLink | hdll | true | false |
Eval | cmxs/cmo | false | true |
JVM | JNI | false | false |
PHP7 | Extension | false | false |
C++ | CFFI or extern | true | false |
Lua | C API | true | false |
C# | P/Invoke | false | false |
Python | ctypes | false | false |
Java | JNI | false | false |
Flash | NO! | false | false |
Neko | ndll | false | false |
I just learn snowkit's linc
and there are lot's of lib wrap c or c++ libs.
https://github.com/snowkit/linc_enet
and what I want to ask ,
is ammer better than snowkit or can compatible with snowkit's linc?
Seems like it is not supported by ammer right now
Example:
https://github.com/facebook/yoga/blob/633cdc908857a580e73bc209864cc227e25f78b4/yoga/YGNode.h#L184
The stubs/FFI for OCaml are relatively similar to those of HashLink. Assuming the user has a working OCaml compiler setup, we can simply create a Makefile
, generate a cmx
/cmo
file, and load it with eval.vm.Context.loadPlugin
.
On commits, the CI should:
OS:
Platform:
I'm trying to test whether I could get a small sample program working across the Ammer targets I would need. I've been able to compile and run the code on Neko and Hashlink, but building the same Ammer library fails on C++ with the error message:
Link: Main
/usr/bin/ld: obj/linux64/9e7162b5_CoreExtern_ammer_adder.o: in function `ammer::externs::__CoreExtern_ammer_adder_obj_hx__ammer_core__62DBCB88_ammer_adder_3D5DF277(Dynamic const&, Dynamic const&)':
CoreExtern_ammer_adder.cpp:(.text+0x3b0): undefined reference to `add_numbers'
/usr/bin/ld: obj/linux64/9e7162b5_CoreExtern_ammer_adder.o: in function `_ammer_core__62DBCB88_ammer_adder_3D5DF277(int, int)':
CoreExtern_ammer_adder.cpp:(.text+0x5b5): undefined reference to `add_numbers'
/usr/bin/ld: obj/linux64/9e7162b5_CoreExtern_ammer_adder.o: in function `ammer::externs::CoreExtern_ammer_adder_obj::_hx__ammer_core__62DBCB88_ammer_adder_3D5DF277(int, int)':
CoreExtern_ammer_adder.cpp:(.text+0x6e5): undefined reference to `add_numbers'
collect2: error: ld returned 1 exit status
Error: Build failed
Please find attached the zip file AmmerAdderExample.zip with the minimal example I'm trying to compile. It is based on the old Adder POC sample, but it's possible that I have not updated everything correctly. Compiling the program follows the instructions of the original POC sample.
I'm using the master version of ammer (commit c5ce5b3) and the dev version of ammer-core (commit Aurel300/ammer-core@59ddd7b), as the current ammer-core master version did not work with ammer.
Various other program versions I'm using which might be relevant:
Hello, i don't want to install vsbuild tools because it's an imense bloat, can i use gcc?
Use the Lua ffi
module.
I have some problems to run the sample project ( Haxe 4.1.1):
1) Downloading Ammer from instruction give a error:
haxelib git ammer [email protected]:Aurel300/ammer.git
Installing ammer from [email protected]:Aurel300/ammer.git
Error: Could not clone Git repository.
The following command works :
haxelib git ammer https://github.com/Aurel300/ammer.git
Installing ammer from https://github.com/Aurel300/ammer.git
Library ammer current version is now git
2) Compile to cpp give the error
Error: In file included from ./src/ammer/externs/AmmerExtern_adder_0.cpp:9:
include/../ammer/ammer_adder.cpp.c: In function ‘unsigned char* w_load_file(const char*, size_t*)’:
include/../ammer/ammer_adder.cpp.c:14:39: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
return (unsigned char * )load_file(arg_0, arg_1);
^~~~~
In file included from include/../ammer/ammer_adder.cpp.c:1,
from include/ammer/externs/AmmerExtern_adder_0.h:11,
from ./src/ammer/externs/AmmerExtern_adder_0.cpp:5:
/home/ronnis/ammer/native/tmp.adder.h:14:43: note: initializing argument 1 of ‘unsigned char* load_file(char*, size_t*)’
LIB_EXPORT unsigned char *load_file(char *filename, size_t *loaded);
~~~~~~^~~~~~~~
Error: Build failed
3) Compile to eval give
haxe build-eval.hxml
Adder.hx:5: character 1 : required define: ammer.eval.haxeDir
On Windows I typically use scoop to install all my tools. For C/C++ compiler I use gcc (it is mingw) usually, mostly because I don't want to install a bunch of Microsoft tools just to get a compiler and can just do a quick scoop install gcc and start coding.
I've been reading a lot about using native libraries with Haxe and ammer keeps popping up and seems great but I have yet to actually get it to work. When I tried the sample I can build the dll just fine. But when I try to run the build hxml I always just end up getting this error:
'U:\Projects\ammer\samples\poc\nmake' is not recognized as an internal or external command,
operable program or batch file.
Which, I thought, was because I did not have msvc installed. In Config.hx the useMSVC boolean is not actually determining if msvc is present but instead is just checking if it is on Windows. So obviously ammer is not accounting for other possible compilers on Windows.
However. I used scoop to install msvc after this (it is scoop install visualc if anyone is interested.)
Checked that nmake was on my path. Then tried to build the sample again and got the same nmake is not recognized error. Even though in the same terminal afterward I could type nmake and get nmake.
So, obviously my first request would just be to let ammer work with gcc on Windows. But I'm also curious if anyone else is getting this nmake problem on Windows with msvc/nmake installed and working otherwise or if it is just me (perhaps because scoop isn't installing something?)
I hope I've described my issue well enough. I wish I could just figure it out myself but for the life of me cannot wrap my head around using native libraries with haxe, with or without ammer... so any help either way would be awesome! Thanks!
Hi Aurel,
I've tried Ammer before and it worked, but today the build of the poc sample fails on mac.
The issue is when I try to build the CPP sample I have the following errors:
/usr/local/lib/haxe/lib/ammer/git/src/ammer/stub/StubBaseC.hx:25: characters 12-17 : Identifier 'Deref' is not part of ammer.FFIType
/usr/local/lib/haxe/lib/ammer/git/src/ammer/stub/StubBaseC.hx:25: characters 12-20 : Unrecognized pattern: Deref(t)
/usr/local/lib/haxe/lib/ammer/git/src/ammer/stub/StubHl.hx:27: characters 12-17 : Identifier 'Deref' is not part of ammer.FFIType
/usr/local/lib/haxe/lib/ammer/git/src/ammer/stub/StubHl.hx:27: characters 12-20 : Unrecognized pattern: Deref(t)
/usr/local/lib/haxe/lib/ammer/git/src/ammer/patch/PatchHl.hx:122: characters 12-17 : Identifier 'Deref' is not part of ammer.FFIType
/usr/local/lib/haxe/lib/ammer/git/src/ammer/patch/PatchHl.hx:122: characters 12-20 : Unrecognized pattern: Deref(t)
Adder.hx:5: character 1 : Build failure
Adder.hx:5: character 1 : For function argument 'v'
Main.hx:1: lines 1-8 : Defined in this class
Main.hx:4: characters 32-46 : Class<Adder> has no field concat_strings
Main.hx:5: characters 40-49 : Class<Adder> has no field load_file
Main.hx:6: characters 45-58 : Class<Adder> has no field reverse_bytes
What could cause Ammer.ctx
to be null?
Line 258 in f6c50d9
When building the sample, I ended up ultimately modifying build-hl.hxml
like so:
build-common.hxml
-D ammer.hl.hlInclude=C:\Users\user\Desktop\hl-1.10.0-win/include
-D ammer.hl.hlLibrary=C:\Users\user\Desktop\hl-1.10.0-win
-D ammer.hl.build=bin/hl
-D ammer.hl.output=bin/hl
--hl bin/hl/sample.hl
I then ran nmake from the Visual Studio 2019 Developer Prompt on Makefile.win
in the native folder, which worked. I have the library files.
Now, when I run haxe build-hl.hxml
I get this error:
'"C:\Users\user\Desktop\New folder\ammer\ammer\samples\poc\nmake"' is not recognized as an internal or external command,
Which I expected, as nmake
is only accessible from the VS 2019 Developer Command Prompt for me. So, when I open the prompt and run nmake
on Makefile.hl.ammer
, I get this output:
C:\Users\user\Desktop\New folder\ammer\ammer\samples\poc\bin\hl>nmake /F
Makefile.hl.ammer
Microsoft (R) Program Maintenance Utility Version 14.24.28316.0
Copyright (C) Microsoft Corporation. All rights reserved.
C:/Users/user/Desktop/New folder/ammer/ammer/samples/poc/cl /c ammer_adder.hl.c /I C:/Users/user/Desktop/New folder/ammer/ammer/samples/poc/native /I C:\Users\user\Desktop\hl-1.10.0-win/include
C:/Users/user/Desktop/New folder/ammer/ammer/samples/poc/cl /LD ammer_adder.hl.obj /DLIBHL_EXPORTS /link /OUT:ammer_adder.hdll /LIBPATH:C:\Users\user\Desktop\hl-1.10.0-win libhl.lib /LIBPATH:C:/Users/user/Desktop/New folder/ammer/ammer/samples/poc/native adder.lib
Which, I guess should mean it is successful? I'm not sure, I don't usually play with Makefiles. But I don't get any output at all from this (at leas that I know of), judging by the Makefile, it looks like it should be generating an hdll file no?
And of course, when I run the hl file (Which was built despite the nmake
error) it complains about the missing hdll.
Am I missing some steps?
There are various type not found errors due to StubHL
vs StubHl
(notice HL
vs Hl
capitalization). Also PatchHL
classes.
/home/jward/dev/ammer/src/ammer/Ammer.hx:280: characters 16-21 : Type not found : ammer.stub.StubHl
/home/jward/dev/ammer/src/ammer/Ammer.hx:292: characters 20-39 : Type not found : ammer.patch.PatchHl
[wish librarys]Please consider bring a complete example use ammer
current Hashlink has Libuv socket framework, but there is no WebSocket framework.
Maybe consider importing uWebSockets or Libwebsockets to showcase what ammer can do.
Since Haxe was switched to Dune builds, the compiler plugin system is broken, and hence ammer's eval target too. ping @RealyUniqueName :)
Perhaps as an alternative/replacement for ammer.ffi.SizeOf
, ammer.ffi.SizeOfReturn
, etc:
public static function foobar():Bytes {
var size = 0;
var ptr = nativeCall(/* passed by reference? */ size);
return ammer.Native.bytes(ptr, size);
}
how to config and add path hl.h?
"hl.h" no such file or directory.
I've been trying to follow along with amlib-qoi and make a wrapper for Raylib.
It appears to work, but it freezes after loading the raylib libraries. I think it may have something to do with GLFW, but I'm not entirely sure.
Any ideas on how I can debug this?
Haxe version:
4.3.0 rc1 built from https://github.com/HaxeFoundation/haxe/tree/10301c8b90fb390ab3d1523510cd86e0bcab31e8
Architecture:
Aarch64 M1 Macos
Ammer:
ammer ammer-core-rewrite branch
ammer-core dev branch
Raylib:
Version 4.5 from tag 4.5.0 (not sure why the output shows 4.6.0-dev)
Java arm64:
openjdk 19.0.2 2023-01-17
OpenJDK Runtime Environment Zulu19.32+13-CA (build 19.0.2+7)
OpenJDK 64-Bit Server VM Zulu19.32+13-CA (build 19.0.2+7, mixed mode, sharing)
Wrapper code src/amlib/raylib/Raylib.hx:
package amlib.raylib;
import ammer.ffi.*;
// @:ammer.lib.includePath("../../../native/raylib/raylib/include")
@:ammer.lib.includePath"../../../../../../../../../opt/homebrew/include/")
@:ammer.lib.headers.includeLocal("raylib.h")
@:ammer.lib.frameworks(["Cocoa", "IOKit", "OpenGL", "CoreVideo", "GLUT"])
@:ammer.lib.libraryPaths([
// "../../../native/raylib/raylib/"
"../../../../../../../../../opt/homebrew/lib/"
])
class Raylib extends ammer.def.Library<"raylib"> {
public static function InitWindow(width :Int32, height :Int32, title :String) :Void;
public static function BeginDrawing() :Void;
public static function EndDrawing() :Void;
public static function WindowShouldClose() :Bool;
public static function CloseWindow() :Void;
}
src/Main.hx:
package;
import amlib.raylib.*;
function main() {
Raylib.InitWindow(800, 450, "What");
while (!Raylib.WindowShouldClose()) // Detect window close button or ESC key
{
// Draw
//----------------------------------------------------------------------------------
Raylib.BeginDrawing();
Raylib.EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
Raylib.CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}
build.hxml:
-cp src/
--library ammer
-D ammer.buildPath=build
-D ammer.outputPath=bin
--main Main
--jvm bin/Main.jar
Output:
INFO: Initializing raylib 4.6-dev
INFO: Supported raylib modules:
INFO: > rcore:..... loaded (mandatory)
INFO: > rlgl:...... loaded (mandatory)
INFO: > rshapes:... loaded (optional)
INFO: > rtextures:. loaded (optional)
INFO: > rtext:..... loaded (optional)
INFO: > rmodels:... loaded (optional)
INFO: > raudio:.... loaded (optional)
Expected Output:
INFO: Initializing raylib 4.5
INFO: Supported raylib modules:
INFO: > rcore:..... loaded (mandatory)
INFO: > rlgl:...... loaded (mandatory)
INFO: > rshapes:... loaded (optional)
INFO: > rtextures:. loaded (optional)
INFO: > rtext:..... loaded (optional)
INFO: > rmodels:... loaded (optional)
INFO: > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO: > Display size: 1800 x 1169
INFO: > Screen size: 800 x 640
INFO: > Render size: 800 x 640
INFO: > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 43
INFO: GL: OpenGL device information:
INFO: > Vendor: Apple
INFO: > Renderer: Apple M1 Max
INFO: > Version: 4.1 Metal - 83
INFO: > GLSL: 4.10
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
I'm really not sure what domain this problem falls within or if any (maybe something I can fix on my own), but I have a native library,
take these two Makefiles:
Makefile.win:
all: odbc.dll
@:
odbc.dll: odbc.obj
gcc -shared -mwindows -o odbc.dll odbc.obj -lodbc32
odbc.obj: odbc.c
gcc -c -mwindows odbc.c -o odbc.obj -lodbc32
.PHONY: all
and Makefile.msvc:
all: odbc.dll
@:
odbc.dll: odbc.obj
cl /LD odbc.obj /link /OUT:odbc.dll /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x86" odbc32.lib
odbc.obj: odbc.c
cl /c odbc.c
.PHONY: all
Both of them work, they both produce "odbc.dll"; Makefile.msvc also produces exp
and lib
files.
For the GCC approach, I used dumpfile /EXPORTS odbc.dll > odbc.exports
and created a DEF file to then create a LIB/EXP file from using the Microsoft lib
tool.
This works for GCC, so end result after building I end up with the same files:
The problem is, odbc.dll cannot be loaded by ammer_odbc.hdll (presumably that's where this failure happens). I get this error: src\module.c(321) : FATAL ERROR : Failed to load library ammer_odbc.hdll
Does anyone have experience using GCC built DLLs with Ammer in Windows? I know other platforms require GCC, so I imagine it has to be possible on windows as well.
Line 2 in c76316a
Is it typo?
(heavily inspired by libuv/asys work of course)
It should be possible to easily declare constants which would normally be accessible in C by including the headers of the library. A specialisation for "flags" fields, i.e. integer constants meant to combined with bitwise-OR would be useful.
Something like:
class Foobar extends ammer.Library<"foobar"> {
@:ammer.native("FOOBAR_EXAMPLE") public static var example:Int;
@:ammer.native("FOOBAR_ELPMAXE") public static var elpmaxe:Int;
}
Should create a glue method in the C stubs that will be called during static initialisation. The method will simply return an array of the required values.
int *glue_foobar_ints(void) {
return {
FOOBAR_EXAMPLE,
FOOBAR_ELPMAXE
};
}
And then:
class Foobar_Impl {
static function __init__():Void {
var ints = glue_foobar_ints();
Foobar.example = ints[0];
Foobar.elpmaxe = ints[1];
}
}
Status:
In the past I've had strange issues putting private ammer types in the same file as the public API I desire to expose.
Subsequently, the FFIs in hxdbc and hxsynchapi are public.
Again, a minor concern.
EDIT: will add more details when I get a moment to try it again
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.