Skip to content

Instantly share code, notes, and snippets.

@arika
Last active April 29, 2020 07:17
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 arika/d35116211ec519928e6891d6c565b05f to your computer and use it in GitHub Desktop.
Save arika/d35116211ec519928e6891d6c565b05f to your computer and use it in GitHub Desktop.
mrubyのLinux/macOS向けクロスビルドのためのDockerfile(素のmrubyをビルドするだけならcurlとlibssl-devはたぶんいらない)
FROM debian:buster
ENV OSX_CROSS_PATH=/osxcross
COPY --from=dockercore/golang-cross:1.13.10 "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -q --no-install-recommends \
bison \
clang \
curl \
git \
libc6-dev \
libssl-dev \
make \
musl-tools \
ruby-dev \
&& rm -rf /var/lib/apt/lists/*
ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH
def build_conf(conf)
conf.gembox 'default'
end
MRuby::Build.new do |conf|
toolchain :gcc
build_conf(conf)
conf.enable_test
conf.enable_debug if ENV['ENABLE_DEBUG']
end
MRuby::Build.new('linux-x86_64') do |conf|
toolchain :gcc
[conf.cc, conf.linker].each do |cc|
cc.command = 'musl-gcc'
cc.flags += %w[-static -Os]
end
build_conf(conf)
end
MRuby::CrossBuild.new('darwin-x86_64') do |conf|
toolchain :clang
[conf.cc, conf.linker].each do |cc|
cc.command = 'x86_64-apple-darwin14-clang'
end
conf.cxx.command = 'x86_64-apple-darwin14-clang++'
conf.archiver.command = 'x86_64-apple-darwin14-ar'
# To configure: k0kubun/mruby-onig-regexp etc.
conf.build_target = 'x86_64-pc-linux-gnu'
conf.host_target = 'x86_64-apple-darwin14'
build_conf(conf)
end
docker build -t mruby-cross .
# copy Rakefile from https://gist.github.com/arika/38daeec40b67d8e9042e5234b4720927
# copy sample_build_config.rb to build_config.rb
mkdir vendor
cd $_
curl -fsSL https://github.com/mruby/mruby/archive/2.1.0.tar.gz | tar xf -
mv mruby-2.1.0 mruby
cd -
docker run -v $(pwd):/work -w /work mruby-cross rake
@arika
Copy link
Author

arika commented Apr 29, 2020

$ file vendor/mruby/build/*/bin/mruby
vendor/mruby/build/darwin-x86_64/bin/mruby: Mach-O 64-bit executable x86_64
vendor/mruby/build/host/bin/mruby:          ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=154b8cd45cdb7abefd6357d74aa116aa451e68ab, with debug_info, not stripped
vendor/mruby/build/linux-x86_64/bin/mruby:  ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

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