Re: How to cross-compile a Nim executable for Android

2018-05-16 Thread yglukhov
  1. No idea, but maybe a more complete example that compiles and runs and 
shows the problem would help. Bonus points for reproducing with localhost JVM, 
and not android 
  2. Yeah, that's how asyncdispatch works. You have to run the loop to make 
async things happen. In your case you run it by `waitFor`, or `runForever`, etc 
(see `asyncdispatch` docs)... Note that currently running Nim `asyncdispatch` 
loop in android main thread is a terribly bad idea, android will likely kill 
your app for that. If you're not afraid of `epoll`, `ALooper`, and NDK, you can 
do it the right way, like I've done it for macos/ios: 
[https://github.com/nim-lang/Nim/pull/7571](https://github.com/nim-lang/Nim/pull/7571)




Re: How to cross-compile a Nim executable for Android

2018-05-16 Thread alexsad
@yglukhov, thanks, it was helpful. For most cases the functionality of java 
interface implementation works.

But in some cases I get error at runtime:

java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called 
with pending exception java.lang.NullPointerException: Expected to unbox a 
'boolean' primitive type but was returned null

java_vm_ext.cc:504] at boolean java.lang.Object.equals(java.lang.Object) 
((null):-1)
java_vm_ext.cc:504] at int 
java.util.concurrent.CopyOnWriteArrayList.indexOf(java.lang.Object, 
java.lang.Object[], int, int) (CopyOnWriteArrayList.java:196) 
java_vm_ext.cc:504] at boolean 
java.util.concurrent.CopyOnWriteArrayList.contains(java.lang.Object) 
(CopyOnWriteArrayList.java:232)...


let prGstr = makeProxy(SomeListenerInterface, mr, MyObj_dispatcher)
mGstr.addOnSomeListener(prGstr, 10,  true.jboolean) #<-here runtime 
exception


and I have another question: I tried to implement this:


import asyncdispatch

proc callAsync() {.async.} =
await sleepAsync(1)
android_log_write(4, "TEST", "async wait")
discard callAsync()
waitFor callAsync()


this works as expected I get two "async wait" in the log. But if I set comment 
for waitFor callAsync() like this: 


import asyncdispatch

proc callAsync() {.async.} =
await sleepAsync(1)
android_log_write(4, "TEST", "async wait")
discard callAsync()
#waitFor callAsync()


or if run the discard callAsync() in callback of events then nothing is coming 
to the log. But I think it is nothing to do with JNI on android?

thanks 


Re: How to cross-compile a Nim executable for Android

2018-03-22 Thread yglukhov
@alexsad, take a look at 
[https://github.com/yglukhov/android](https://github.com/yglukhov/android)


Re: How to cross-compile a Nim executable for Android

2018-03-22 Thread alexsad
thanks a lot mashingan! It is working!

Now I am going to implement JNI to call java classes(some SDK has been already 
developed in Java) for manage android application.


Re: How to cross-compile a Nim executable for Android

2018-03-21 Thread mashingan
you forgot to link libm, add option `-lm` at very end.


Re: How to cross-compile a Nim executable for Android

2018-03-21 Thread alexsad
Hi

finelly is works!

I tried the way suggested Tetralux via make_standalone_toolchain.py and then 
clang.

Simple echo works, but I tried simple pow from math and clang doesn't compile 
it:


import math

var a = pow(5.09, 2.33)



clang -I ../sysroot/usr/include -I C:/Nim/lib -fPIE -pie -o 
C:/Users/uname/Documents/nimapps/jnijava/hello.bin 
C:/Users/uname/Documents/nimapps/jnijava/nimcache/*.c

...and get error:


\nimcache\hello.c:function NimMainModule: error: undefined reference to 
'pow'
clang50.exe: error: linker command failed with exit code 1 (use -v to see 
invocation)


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread mashingan
Hmm, I'm not sure, all I can say is the cross compiler cannot find the sysroot

This the exact command line I did and it success


\nimcache>arm-linux-androideabi-gcc -I d:/installer/nim/lib hello_android.c 
stdlib_system.c -o hello 
--sysroot=e:/installer/android/ndk/platforms/android-19/arch-arm


Before I did failed like what you had but because I wrote the sysroot wrong, 
before I wrote it `--sysroot=e:/installer/ndk/platforms/android-19/arch-arm` , 
but after recompiled with correct path, it compiled successfully.

My Nim version is still 0.17.2, 64 bit (haven't had a chance to try 0.18.0)

My arm-linux-androideabi-gcc version and its path dependency


arm-linux-androideabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-androideabi-gcc

COLLECT_LTO_WRAPPER=e:/installer/android/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper.exe
Target: arm-linux-androideabi
Configured with: 
/usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure
 --prefix=/tmp/54f254f8bb7b48dd787052921220a87d --target=arm-linux-androideabi 
--host=x86_64-pc-mingw32msvc --build=x86_64-linux-gnu --with-gnu-as 
--with-gnu-ld --enable-languages=c,c++ 
--with-gmp=/buildbot/tmp/build/toolchain/temp-install 
--with-mpfr=/buildbot/tmp/build/toolchain/temp-install 
--with-mpc=/buildbot/tmp/build/toolchain/temp-install 
--with-cloog=/buildbot/tmp/build/toolchain/temp-install 
--with-isl=/buildbot/tmp/build/toolchain/temp-install 
--with-ppl=/buildbot/tmp/build/toolchain/temp-install 
--disable-ppl-version-check --disable-cloog-version-check 
--disable-isl-version-check --enable-cloog-backend=isl 
--with-host-libstdcxx='-static-libgcc -static-libstdc++ -lstdc++ -lm -static' 
--disable-libssp --enable-threads --disable-nls --disable-libmudflap 
--disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions 
--disable-shared --disable-tls --disable-libitm --with-float=soft 
--with-fpu=vfp --with-arch=armv5te --enable-target-optspace 
--enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array 
--disable-nls --prefix=/tmp/54f254f8bb7b48dd787052921220a87d 
--with-sysroot=/tmp/54f254f8bb7b48dd787052921220a87d/sysroot 
--with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 
--with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none 
--with-gxx-include-dir=/tmp/54f254f8bb7b48dd787052921220a87d/include/c++/4.9.x 
--with-bugurl=http://source.android.com/source/report-bugs.html 
--enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp 
--enable-gnu-indirect-function --disable-libsanitizer --enable-gold 
--enable-eh-frame-hdr-for-static --enable-graphite=yes 
--with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te 
--program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default
Thread model: posix
gcc version 4.9.x 20150123 (prerelease) (GCC)


My system is Windows 10 64 bit


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad
Hi mashingan,

I tried cross-compile the same hello.nim from linux and **got the same errors 
exactly like in windows**.

what I did:

  1. Cloned nim-lang branch master from github and compled it.
  2. Downloaded android ndk
  3. Defined all needed paths in PATH
  4. Compile hello.nim: nim c --cpu:arm --os:android --compileOnly hello.nim
  5. Compile with arm-linux-androideabi-gcc.exe




Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad

> cd C:\Users\uname\Documents\nimapps\jnijava\
> set 
PATH=%PATH%;C:\Users\uname\Documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\bin
> nim c --cpu:arm --os:android --compileOnly hello.nim
> cd nimcache
> arm-linux-androideabi-gcc.exe -I "C:/Nim/lib" hello.c stdlib_system.c -o 
hello 
--sysroot="C:/Users/uname/Documents/apps/android-ndk-r16b/platforms/android-19/arch-arm"


Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread mashingan
Could you give the command-line you typed?

For example, what I did was like this


arm-linux-androideabi-gcc.exe -I "C:/Nim/lib" hello.c stdlib_system.c -o 
hello 
--sysroot="C:/Users/uname/Documents/apps/android-ndk-r16b/platforms/android-19/arch-arm"



Re: How to cross-compile a Nim executable for Android

2018-03-20 Thread alexsad
Hi mashingan,

thank you for suggestion and I tried all this /," and // possibilities but 
errors are the same.

any other suggestions? maybe I have not prepared some things... 


Re: How to cross-compile a Nim executable for Android

2018-03-19 Thread mashingan
Have you tried `/` in path string instead of `\` as path separator ?

Also you can try adding `"`.

Very likely because you were using `\` so gcc couldn't find the correct path. 
See my example above all using `/`.


Re: How to cross-compile a Nim executable for Android

2018-03-19 Thread alexsad
Hi, 

I tried last example. Unfortunately doesn't work for me.



C:\Users\uname\Documents\nimapps\jnijava\nimcache>arm-linux-androideabi-gcc.exe 
-I C:\Nim\lib hello.c stdlib_system.c -o hello 
--sysroot=C:\Users\uname\Documents\apps\android-ndk-r16b\platforms\android-19\arch-arm
In file included from 
c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\syslimits.h:7:0,
   from 
c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\limits.h:34,
   from C:\Nim\lib/nimbase.h:255,
   from hello.c:7:

c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\limits.h:168:61:
 error: no include path in which to search for limits.h
 #include_next   /* recurse down to the real one */
   ^
In file included from 
c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\syslimits.h:7:0,
   from 
c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\limits.h:34,
   from C:\Nim\lib/nimbase.h:255,
   from stdlib_system.c:7:

c:\users\uname\documents\apps\android-ndk-r16b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\lib\gcc\arm-linux-androideabi\4.9.x\include-fixed\limits.h:168:61:
 error: no include path in which to search for limits.h
 #include_next   /* recurse down to the real one */
   ^
stdlib_system.c:8:20: fatal error: setjmp.h: No such file or directory
 #include 
  ^
compilation terminated.

What I do wrong? Could you please help...


Re: How to cross-compile a Nim executable for Android

2018-03-09 Thread mashingan
Thank you, I did different approach. I followed from this stackoverflow thread 
about cross compiling 
[https://stackoverflow.com/questions/16795583/android-error-cannot-open-crtbegin-dynamic-o-no-such-file-or-directory](https://stackoverflow.com/questions/16795583/android-error-cannot-open-crtbegin-dynamic-o-no-such-file-or-directory)

I was stuck because I added `sysroot` option to the compiler when compiling C 
and after I looked your example, I realized I need to add `--compileOnly` to 
Nim compiler and do compiling as usual

* * *

For completeness, this is what I did


> set 
PATH=%PATH%;/my-installed-ndk/toolchains/arm-linux-android-eabi-4.9/prebuilt/windows-x86_64/bin
> nim --cpu:arm --os:android --compileOnly hello.nim
> cd nimcache
> arm-linux-androideabi-gcc.exe -I my-installed-nim-folder/lib hello.c 
stdlib_system.c -o hello 
--sysroot=my-installed-ndk/platforms/android-19/arch-arm
> adb root # starting adb server, make sure adb.exe in PATH
> adb push hello /data/local/tmp
> adb shell
$ su
# cd /data/local/tmp
# chmod 755 hello
# ./hello
cross compiled hello


I cross-compiled from Windows 10 64 bit too and targeting android-19 (4.4)