Skip to content

Instantly share code, notes, and snippets.

@qichunren
Last active May 11, 2021 08:41
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 qichunren/28e1830298b351aeb0356217005c588e to your computer and use it in GitHub Desktop.
Save qichunren/28e1830298b351aeb0356217005c588e to your computer and use it in GitHub Desktop.
mruby cross compie to arm64

Target device:

uname -a

Linux rockchip 4.4.167 #2 SMP PREEMPT Thu Nov 14 12:03:34 CST 2019 aarch64 GNU/Linux

On ubuntu 20.04

sudo apt install gcc-aarch64-linux-gnu
git clone https://github.com/mruby/mruby.git

aarch64-linux-gnu-gcc -o stest -lm -lmruby test/simpletest.c  -I/home/qichunren/arm-hello/mruby/include -L/home/qichunren/arm-hello/mruby/build/rockchip_aarch64/lib   -std=gnu99 -g -O3 -Wall -Wundef -Werror-implicit-function-declaration -Wwrite-strings -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX
MRuby::Build.new do |conf|
# load specific toolchain settings
conf.toolchain
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-onig-regexp'
# conf.gem :github => 'mattn/mruby-onig-regexp'
# conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
# include the GEM box
conf.gembox 'default'
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w()
# cc.option_include_path = %q[-I"%s"]
# cc.option_define = '-D%s'
# cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
# end
# mrbc settings
# conf.mrbc do |mrbc|
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers
# end
# Linker settings
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
# linker.flags_before_libraries = []
# linker.libraries = %w()
# linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o "%{outfile}" %{objs} %{libs}"
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs "%{outfile}" %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = %q[-o "%{outfile}" "%{infile}"]
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
# end
# file extensions
# conf.exts do |exts|
# exts.object = '.o'
# exts.executable = '' # '.exe' if Windows
# exts.library = '.a'
# end
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
# conf.enable_debug
conf.enable_bintest
conf.enable_test
end
MRuby::CrossBuild.new("rockchip_aarch64") do |conf|
toolchain :gcc
# C compiler
conf.cc do |cc|
cc.command = "/usr/bin/aarch64-linux-gnu-gcc"
# cc.flags = '-fPIC'
cc.flags << ["-O2"]
#cc.flags << ["-mthumb-interwork", "-mthumb", "-O2"]
puts "##### cc.compile_options:#{cc.compile_options}"
cc.compile_options = %(%{flags} -o "%{outfile}" -c "%{infile}")
end
# # C++ compiler
conf.cxx do |cxx|
cxx.command = "/usr/bin/aarch64-linux-gnu-cpp"
# cxx.include_paths = conf.cc.include_paths.dup
# cxx.flags = conf.cc.flags.dup
# cxx.flags << %w[-fno-rtti -fno-exceptions]
# cxx.defines = conf.cc.defines.dup
# cxx.compile_options = conf.cc.compile_options.dup
end
conf.archiver do |archiver|
archiver.command = "/usr/bin/aarch64-linux-gnu-ar"
end
# # Linker
conf.linker do |linker|
linker.command = "/usr/bin/aarch64-linux-gnu-gcc"
#linker.flags << ["-mthumb-interwork", "-mthumb", "-specs=gba.specs"]
end
# # No executables
conf.bins = []
#conf.enable_test
#conf.enable_bintest
# # Do not build executable test
# conf.build_mrbtest_lib_only
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# removing mruby-io
conf.gembox 'default'
end
#include "mruby.h"
//#include "mruby/irep.h"
//#include "simplest_mrb.h"
int main(void)
{
mrb_state *mrb = mrb_open();
//mrb_load_irep(mrb, simplest_mrb);
mrb_close(mrb);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment