wahern / cqueues

Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.
http://25thandclement.com/~william/projects/cqueues.html
MIT License
244 stars 37 forks source link

Android NDK Compilation #177

Closed Whitecl4ws closed 5 years ago

Whitecl4ws commented 7 years ago

Hello, I've been trying to compile this library with the Android NDK, but I hit a wall, It compiles fine on linux bu with the NDK, t it uses the default bits/mathinline.h file because that file doesn't exist in it's headers, is there a workaround to not use that file or perhaps disable it for arm infrastructures?

61215/src/cqueues.c:36:
/tmp/luarocks_cqueues-20161215.51-0-Xv9Uj5/cqueues-rel-20161215/src/cqueues.c: In function 'dbg_f2ms':
/usr/include/bits/mathinline.h:769:3: error: inconsistent operand constraints in an 'asm'
   __asm __volatile ("fnstcw %3\n\t"           \
   ^
/usr/include/bits/mathinline.h:503:5: note: in definition of macro '__inline_mathcodeNP_'
     code;              \
     ^
/usr/include/bits/mathinline.h:764:1: note: in expansion of macro '__inline_mathcodeNP'
 __inline_mathcodeNP (ceil, __x, \
 ^
/tmp/luarocks_cqueues-20161215.51-0-Xv9Uj5/cqueues-rel-20161215/src/GNUmakefile:75: recipe for target '/tmp/luarocks_cqueues-20161215.51-0-Xv9Uj5/cqueues-rel-20161215/src/5.1/cqueues.o' failed
make: *** [/tmp/luarocks_cqueues-20161215.51-0-Xv9Uj5/cqueues-rel-20161215/src/5.1/cqueues.o] Error 1

Error: Build error: Failed building.

Thank you very much... Also, the reason it's crashing is of course the difference in infrastructure

Whitecl4ws commented 7 years ago

I downloaded the cqueues rock and made it local, I changed every mention of 5.3 to 5.1 in the rockspec

dependencies = {
    "lua == 5.1";
}
external_dependencies = {
    OPENSSL = {
        header = "openssl/ssl.h";
        library = "ssl";
    };
    CRYPTO = {
        header = "openssl/crypto.h";
        library = "crypto";
    };
}
build = {
    type = "make";
    makefile = "GNUmakefile";

    build_target = "all5.1";
    build_variables = {
        CPPFLAGS= '-I/usr/include/lua5.1 -I"$(OPENSSL_INCDIR)" -I"$(CRYPTO_INCDIR)"';
        CFLAGS = '-I/usr/include/lua5.1 $(CFLAGS)';
        LDFLAGS = '$(LIBFLAG) -L"$(OPENSSL_LIBDIR)" -L"$(CRYPTO_LIBDIR)"';
        bindir = "$(LUA_BINDIR)";
        includedir = "$(LUA_INCDIR)";
        libdir = "$(LUA_LIBDIR)";
    };

    install_target = "install5.1";
    install_variables = {
        prefix = "$(PREFIX)";
        lua51cpath = "$(LIBDIR)";
        lua51path = "$(LUADIR)";
        bindir = "$(BINDIR)";
    };
}

And finally i changed math.h to platforms/my/android/lib/usr/include/math.h, and it skips the math error but now I'm left with a lua related error, it seems I'm doing something wrong ... I'm getting a LOT Of errors like these

/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1267:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 static cqs_error_t cqueue_tryalert(struct cqueue *Q) {
                                                      ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1275:29: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setvfstring(lua_State *L, struct callinfo *I, const char *fmt, va_list ap) {
                             ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1280:28: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setfstring(lua_State *L, struct callinfo *I, const char *fmt, ...) {
                            ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1288:25: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setcode(lua_State *L, struct callinfo *I, int code) {
                         ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1295:27: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setthread(lua_State *L, struct callinfo *I, struct thread *T) {
                           ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1301:27: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setobject(lua_State *L, struct callinfo *I, cqs_index_t index) {
                           ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1306:23: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setfd(lua_State *L NOTUSED, struct callinfo *I, int fd) {
                       ^
/home/malek/Desktop/AndroidLibs/LuaRocks/bin/src/cqueues.c:1310:25: error: expected declaration specifiers or '...' before 'lua_State'
 static void err_setinfo(lua_State *L, struct callinfo *I, int code, struct thread *T, int object, const char *fmt, ...) {
daurnimator commented 7 years ago

How are you trying to compile (apparently with my luarocks rockspec?) How have you configured luarocks to compile using the NDK?

Instead of using luarocks you might be better off just using the makefile directly

I downloaded the cqueues rock and made it local, I changed every mention of 5.3 to 5.1 in the rockspec

There is already a different rockspec available for each lua version e.g. for 5.1: https://luarocks.org/manifests/daurnimator/cqueues-20161215.51-0.rockspec

bits/mathinline.h

cqueues doesn't include this file directly. You've got wrong include paths or something.

Whitecl4ws commented 7 years ago

daurnimator, I actually am, but apparently android-gcc checks the default include paths before checking the android libs which is odd but can be avoided by just using the full path in the include ... I tried by including every path separately and disabling standard include paths but it gives me plenty of errors ... I'll try using lua 5.1 rockspec ... Edit: This issue can be avoided using llvm but unfortunately I started using gcc so I'll atleast end it with gcc Edit2: I used the same source and rockspec than you and unfortunately it gives the same mistakes as before, I'll try compiling with a makefile

Whitecl4ws commented 7 years ago

Edit: I managed to compile the library using this buildenv.sh file and just the default make command ( . ./buildenv.sh && make LUA_APIS="5.1")

export CC="/opt/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CFLAGS="-L/opt/android-ndk-r13b/platforms/android-21/arch-arm/usr/lib -I/opt/android-ndk-r13b/platforms/android-21/arch-arm/usr/include --sysroot=/opt/android-ndk-r13b/platforms/android-21/arch-arm/"
export LDFLAGS="-L/opt/android-ndk-r13b/platforms/android-21/arch-arm/usr/lib"

The only thing I encountered was that in_port_t was not defined in the Android NDK library headers so I just added: typedef uint16_t in_port_t; I'm in the process of linking the library so my buildenv.sh is not finished yet, I'll upgrade accordingly

daurnimator commented 7 years ago

in_port_t was not defined in the Android NDK library headers

https://github.com/android-ndk/ndk/issues/123

Whitecl4ws commented 7 years ago

So I removed -lrt and -lpthread because they are already functionally included in the Android API and symlinked crtbegin_so.o and crtend_so.o and it finally linked. Closing the issue. Edit: If I knew how to heh

daurnimator commented 7 years ago

@Whitecl4ws so what modifications did you end up needing in the end? Are there things we can/should add upstream?

Whitecl4ws commented 7 years ago

I did compile it using the Android NDK, but it still gave me some binary issues so I just scrapped it

On 18 February 2017 at 03:46, daurnimator notifications@github.com wrote:

@Whitecl4ws https://github.com/Whitecl4ws so what modifications did you end up needing in the end? Are there things we can/should add upstream?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wahern/cqueues/issues/177#issuecomment-280831978, or mute the thread https://github.com/notifications/unsubscribe-auth/AIm9UApG6susHjOL6UeiYndaCkx9Jy-uks5rdq_bgaJpZM4Lk1xm .

daurnimator commented 5 years ago

I'm going to assume this was fixed with https://github.com/android-ndk/ndk/issues/123