0
Metasepi team meeting #8': 
#8':
Haskell apps on Android NDK
Kiwamu Okabe
Who am I?
☆ http://www.masterq.net/
☆ Twitter: @master_q
☆ Organizer of Metasepi Project
☆ A developer of Ajhc Haskell com...
Agenda
☆ [1] Demo
☆ [2] What is Ajhc?
☆ [3] What is Metasepi?
☆ [4] What is compiler to build OS
☆ [5] How to use Ajhc
☆ [...
[1] Demo
☆ A touchable cube demo.
☆ Haskell App runs on Android NDK.
☆ GC is breaked by ndk-gdb debugger.
☆ The App is ava...
Demo hardware
Nexus 7 (2012) / NVIDIA Tegra 3
Demo software
github.com/ajhc/demo-android-ndk
[2] What is Ajhc?
http://ajhc.metasepi.org/
☆ Ajhc := A fork of jhc
☆ jhc := John's Haskell Compiler
☆ http://repetae.net/...
Who is John?
☆ John Meacham
☆ http://repetae.net/
Why need Ajhc?
☆ GHC is de facto standard on Haskell.
☆ GHC := Glasgow Haskell Compiler
☆ http://www.haskell.org/ghc/
☆ Wh...
[3] What is Metasepi?
http://metasepi.org/
☆ Unix-like OS designed by strong type.
☆ Using ML or more strong type lang.
Ha...
Why need Metasepi?
☆ We have already Linux or Windows.
☆ But the developers are suffering.
☆ If use the kernel changed by ...
Doesn't OSS have good quality?
☆ "The Cathedral and the Bazaar"
☆ "Given enough eyeballs, all bugs are
shallow."
http://cr...
Low quality out of OSS umbrella
Type safety
☆ Less runtime errors.
☆ "数理科学的バグ撲滅方法論のすすめ"
http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/
Kernel wants type desperately
☆ Kernels are developed with C lang.
☆ Error on user space => SEGV
☆ Error on kernel space =...
[4] What is compiler to build OS
☆ Need strong type.
☆ Need flexibility such as C language.
☆ Create it if there are not!
...
Want POSIX free compiler
Programs to print "hoge" on terminal.

The lesser depends on POSIX, the
smaller values.
Jhc output has only 20 undef
$ nm hs.out | grep
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U
U

"U "
_IO_putc@@GLIBC_2.2.5
__libc...
Jhc is translator to C language
Easy to cross build
Survive burning out
Let's develop with dogfooding style.
(The method is called "Snatch".)
[5] How to use Ajhc
Case of Ubuntu 12.04 amd64.
$ sudo apt-get install haskell-platform libncurses5-dev gcc m4
$ cabal upd...
Detail of usage
☆ Please read "Ajhc User's Manual".
ajhc.metasepi.org/manual.html
☆ Also you can read in Japanese.
ajhc.me...
[6] Haskell on Android NDK
github.com/ajhc/demo-android-ndk
☆ First, build the demo apps.
☆ Then, see more detail of the c...
Setup Android SDK/NDK
☆ Download Android SDK/NDK
* Android SDK (adt-bundle-linux-x86_64-20130917.zip)
http://developer.and...
Start with sample C application
Sample application "native-activity".
developer.android.com/tools/sdk/ndk/
Build sample C application
☆ Build
$ cd $HOME/android-ndk/samples/native-activity
$ android update project -p ./ -n native...
Build Haskell applications
☆ Checkout the source code.
$ git clone https://github.com/ajhc/demo-android-ndk.git
$ cd demo-...
Source code tree
demo-android-ndk
|-- lib
|
`-- android-ndk
|
|-- AndroidNdk
|
|
|-- EGL.hs
|
|
|-- OpenGLES.hs
|
|
`-- St...
Build process on Makefile
[7] Status report of framework
Let's see "native-activity" demo internal.
But, the framework has no stability yet.
Architecture: Using C language
Architecture: Using Haskell
Code #1: Imports
Code #2: Some magic
Code #3: Main entry
Code #4: Handle inputs
Code #5: Handle cmds
Code #6: Draw frame
Code #7: Init display
PR: Call For Articles
☆ http://www.paraiso-lang.org/ikmsm/
☆ Fanzine of functional programming.
☆ About Haskell or OCaml o...
Upcoming SlideShare
Loading in...5
×

Metasepi team meeting #8': Haskell apps on Android NDK

5,208

Published on

Metasepi team meeting #8': Haskell apps on Android NDK

Published in: Technology, Education
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,208
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
17
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Metasepi team meeting #8': Haskell apps on Android NDK"

  1. 1. Metasepi team meeting #8':  #8': Haskell apps on Android NDK Kiwamu Okabe
  2. 2. Who am I? ☆ http://www.masterq.net/ ☆ Twitter: @master_q ☆ Organizer of Metasepi Project ☆ A developer of Ajhc Haskell compiler ☆ A Debian Maintainer ☆ 10 years' experience in developing OS using NetBSD.
  3. 3. Agenda ☆ [1] Demo ☆ [2] What is Ajhc? ☆ [3] What is Metasepi? ☆ [4] What is compiler to build OS ☆ [5] How to use Ajhc ☆ [6] Haskell on Android NDK ☆ [7] Status report of framework
  4. 4. [1] Demo ☆ A touchable cube demo. ☆ Haskell App runs on Android NDK. ☆ GC is breaked by ndk-gdb debugger. ☆ The App is available at Google Play. http://bit.ly/cubeplay ☆ You can watch the movie following. http://bit.ly/jhcdroid
  5. 5. Demo hardware Nexus 7 (2012) / NVIDIA Tegra 3
  6. 6. Demo software github.com/ajhc/demo-android-ndk
  7. 7. [2] What is Ajhc? http://ajhc.metasepi.org/ ☆ Ajhc := A fork of jhc ☆ jhc := John's Haskell Compiler ☆ http://repetae.net/computer/jhc/ ☆ Jhc outputs binary that has lowmemory-footprint and runs fast. ☆ Good for embedded software.
  8. 8. Who is John? ☆ John Meacham ☆ http://repetae.net/
  9. 9. Why need Ajhc? ☆ GHC is de facto standard on Haskell. ☆ GHC := Glasgow Haskell Compiler ☆ http://www.haskell.org/ghc/ ☆ Why need another Haskell compiler? ☆ To develop kernel named "Metasepi".
  10. 10. [3] What is Metasepi? http://metasepi.org/ ☆ Unix-like OS designed by strong type. ☆ Using ML or more strong type lang. Haskell http://www.haskell.org/ OCaml http://caml.inria.fr/ MLton http://mlton.org/ . . . and suchlike.
  11. 11. Why need Metasepi? ☆ We have already Linux or Windows. ☆ But the developers are suffering. ☆ If use the kernel changed by you, ☆ you will get many runtime error. ☆ Difficult even to reproduce it.
  12. 12. Doesn't OSS have good quality? ☆ "The Cathedral and the Bazaar" ☆ "Given enough eyeballs, all bugs are shallow." http://cruel.org/freeware/cathedral.html ☆ But if you develop your own product reusing OSS...
  13. 13. Low quality out of OSS umbrella
  14. 14. Type safety ☆ Less runtime errors. ☆ "数理科学的バグ撲滅方法論のすすめ" http://itpro.nikkeibp.co.jp/article/COLUMN/20060915/248230/
  15. 15. Kernel wants type desperately ☆ Kernels are developed with C lang. ☆ Error on user space => SEGV ☆ Error on kernel space => Halt! ☆ Should design kernel with the greatest care. ☆ C language is safe?
  16. 16. [4] What is compiler to build OS ☆ Need strong type. ☆ Need flexibility such as C language. ☆ Create it if there are not! ☆ From scratch? No thank you... ☆ Look for our compiler base.
  17. 17. Want POSIX free compiler Programs to print "hoge" on terminal. The lesser depends on POSIX, the smaller values.
  18. 18. Jhc output has only 20 undef $ nm hs.out | grep U U U U U U U U U U U U U U U U U U U U "U " _IO_putc@@GLIBC_2.2.5 __libc_start_main@@GLIBC_2.2.5 _setjmp@@GLIBC_2.2.5 abort@@GLIBC_2.2.5 ctime@@GLIBC_2.2.5 exit@@GLIBC_2.2.5 fflush@@GLIBC_2.2.5 fprintf@@GLIBC_2.2.5 fputc@@GLIBC_2.2.5 fputs@@GLIBC_2.2.5 free@@GLIBC_2.2.5 fwrite@@GLIBC_2.2.5 getenv@@GLIBC_2.2.5 malloc@@GLIBC_2.2.5 memset@@GLIBC_2.2.5 posix_memalign@@GLIBC_2.2.5 realloc@@GLIBC_2.2.5 setlocale@@GLIBC_2.2.5 sysconf@@GLIBC_2.2.5 times@@GLIBC_2.2.5
  19. 19. Jhc is translator to C language
  20. 20. Easy to cross build
  21. 21. Survive burning out Let's develop with dogfooding style. (The method is called "Snatch".)
  22. 22. [5] How to use Ajhc Case of Ubuntu 12.04 amd64. $ sudo apt-get install haskell-platform libncurses5-dev gcc m4 $ cabal update $ export PATH=$HOME/.cabal/bin/:$PATH $ cabal install ajhc $ which ajhc /home/USER/.cabal/bin/ajhc $ echo 'main = print "hoge"' > Hoge.hs $ ajhc Hoge.hs $ ./hs.out "hoge" You can use on Windows or Mac OS X.
  23. 23. Detail of usage ☆ Please read "Ajhc User's Manual". ajhc.metasepi.org/manual.html ☆ Also you can read in Japanese. ajhc.metasepi.org/manual_ja.html
  24. 24. [6] Haskell on Android NDK github.com/ajhc/demo-android-ndk ☆ First, build the demo apps. ☆ Then, see more detail of the code.
  25. 25. Setup Android SDK/NDK ☆ Download Android SDK/NDK * Android SDK (adt-bundle-linux-x86_64-20130917.zip) http://developer.android.com/sdk/index.html * Android NDK (android-ndk-r9-linux-x86_64.tar.bz2) http://developer.android.com/tools/sdk/ndk/index.html ☆ Install Android SDK/NDK $ cd $HOME $ unzip -x adt-bundle-linux-x86_64-20130917.zip $ mv adt-bundle-linux-x86_64-20130917/sdk $HOME/android-sdk $ rm -f adt-bundle-linux-x86_64-20130917 $ export PATH=$PATH:$HOME/android-sdk/tools:$HOME/android-sdk/ platform-tools $ tar xf android-ndk-r9-linux-x86_64.tar.bz2 $ mv android-ndk-r9 android-ndk $ export PATH=$PATH:$HOME/android-ndk $ sudo apt-get install openjdk-7-jdk ant lib32z1-dev lib32stdc++6 $ android update sdk --no-ui --force
  26. 26. Start with sample C application Sample application "native-activity". developer.android.com/tools/sdk/ndk/
  27. 27. Build sample C application ☆ Build $ cd $HOME/android-ndk/samples/native-activity $ android update project -p ./ -n native-activity -t android-10 $ ndk-build NDK_DEBUG=1 $ ant debug $ file bin/native-activity-debug.apk bin/native-activity-debug.apk: Java Jar file data (zip) ☆ Flash to your Android device $ sudo adb devices * daemon not running. starting it now on port 5037 * * daemon started successfully * List of devices attached 015d4906053c1605 device $ sudo adb install -r bin/native-activity-debug.apk 1221 KB/s (156823 bytes in 0.125s) pkg: /data/local/tmp/native-activity-debug.apk Success
  28. 28. Build Haskell applications ☆ Checkout the source code. $ git clone https://github.com/ajhc/demo-android-ndk.git $ cd demo-android-ndk ☆ Build $ make $ find . -name "*.hl" ./lib/android-ndk-0.1.hl $ find . -name "*debug.apk" ./cube/bin/cube-debug.apk ./native-activity/bin/native-activity-debug.apk ☆ "hl" suffix file: Ajhc library ☆ "apk" suffix file: Android application
  29. 29. Source code tree demo-android-ndk |-- lib | `-- android-ndk | |-- AndroidNdk | | |-- EGL.hs | | |-- OpenGLES.hs | | `-- Storable.hs | |-- AndroidNdk.hs | `-- android-ndk.yaml |-- cube ... `-- native-activity |-- AndroidManifest.xml |-- hs_src | `-- Main.hs |-- jni | |-- Android.mk | |-- Application.mk | |-- c_extern.h | |-- dummy4jhc.c | `-- main.c `-- res `-- values `-- strings.xml # Framework library # # Application Application # Haskell code on application side # # Stub code for Ajhc C language code to runtime kick Haskell code
  30. 30. Build process on Makefile
  31. 31. [7] Status report of framework Let's see "native-activity" demo internal. But, the framework has no stability yet.
  32. 32. Architecture: Using C language
  33. 33. Architecture: Using Haskell
  34. 34. Code #1: Imports
  35. 35. Code #2: Some magic
  36. 36. Code #3: Main entry
  37. 37. Code #4: Handle inputs
  38. 38. Code #5: Handle cmds
  39. 39. Code #6: Draw frame
  40. 40. Code #7: Init display
  41. 41. PR: Call For Articles ☆ http://www.paraiso-lang.org/ikmsm/ ☆ Fanzine of functional programming. ☆ About Haskell or OCaml or . . . ☆ Article about Ajhc in C84 book. ☆ Call me if you read it! http://www.paraiso-lang.org/ikmsm/books/c85.html
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×