Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created August 11, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/d9353c6a91f10a0a6b08 to your computer and use it in GitHub Desktop.
Save kazu69/d9353c6a91f10a0a6b08 to your computer and use it in GitHub Desktop.
Cross compile mruby of cli app using mruby-cli

mruby-cliを使ってmruby cliをクロスコンパイル

mruby-cliを使えば、mrubyのcliアプリケーションを

  • Linux (64-bit)
  • Linux (32-bit)
  • OS X (64-bit)
  • OS X (32-bit)
  • Windows (64-bit)
  • Windows (32-bit)

で使用できるようにクロスコンパイルできる。

--

require

create app

hello_worldアプリを作成する

$ mruby-cli --setup hello_world

# created skelton

  create  .gitignore
  create  mrbgem.rake
  create  build_config.rb
  create  Rakefile
  create  Dockerfile
  create  docker-compose.yml
  create  tools/
  create  tools/hello_world/
  create  tools/hello_world/hello_world.c
  create  mrblib/
  create  mrblib/hello_world.rb
  create  bintest/
  create  bintest/hello_world.rb
  create  test/
  create  test/test_hello_world.rb

tree -L 2
├── hello_world
│   ├── Dockerfile
│   ├── Rakefile
│   ├── bintest
│   ├── build_config.rb
│   ├── docker-compose.yml
│   ├── mrbgem.rake
│   ├── mrblib
│   ├── test
│   └── tools
└── mruby-cli

add hello_world.rb

vi mrblib/hello_world.rb
# mrblib/hello_world.rb
def __main__(argv)
  puts "Hello World"
end

unit test(mtest)

/testディレクトリのmrubyのテストを実行

docker-compose run mtest

integration tests(bintest)

/bintestディレクトリのcRubyのテストを実行

docker-compose run bintest

mtestとbintestを実行

docker-compose run test

アプリケーションを実行する

currentディレトリがコンテナの/home/mruby/code にマウントされているので、 コンテナ内で実行して試すことができる

docker-compose run shell
/home/mruby/code# mruby/build/host/bin/hello_world
Hello World

コンパイル

docker-compose run compile

以下のディレクトリにバイナリが置かれる

  • Linux (64-bit): mruby/build/host/bin
  • Linux (32-bit): mruby/build/i686-pc-linux-gnu/bin
  • OS X (64-bit): mruby/build/x86_64-apple-darwin14/bin/
  • OS X (32-bit): mruby/build/i386-apple-darwin14/bin
  • Windows (64-bit): mruby/build/x86_64-w64-mingw32/bin/
  • Windows (32-bit): mruby/build/i686-w64-mingw32/bin

cleanup

docker-compose run clean

Cleaned up target build folder
Cleaned up mrbgems build folder

rake task

rake -T
rake all           # build all targets, install (locally) in-repo
rake clean         # clean all built and in-repo installed artifacts / cleanup
rake compile       # compile binary
rake deep_clean    # clean everything!
rake doc           # generate document
rake test          # run all tests
rake test:bintest  # run integration tests
rake test:mtest    # run mruby & unit tests

githubみると release(tarで固めて/releaseに配置する)的なものもあるのでそのうち実装されそう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment