Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contain build artifacts to a pkg directory. #1

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
mruby*zip
mruby

*rb.c

build
pkg
41 changes: 21 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
# frozen_string_literal: true

MRUBY_URL = 'https://github.com/mruby/mruby/archive/3.0.0.zip'
PKG_PATH = 'pkg'
BUILD_CONFIG = 'tml'
BUILD_CONFIG_PATH = "mruby/build_config/#{BUILD_CONFIG}.rb"
MRBC_PATH = 'mruby/bin/mrbc'
MRUBY_CONFIG_PATH = 'mruby/bin/mruby-config'
LIBYAML_PATH = 'mruby/build/host/mrbgems/mruby-yaml/libyaml/build/lib/libyaml.a'
MRUBY_PATH = "#{PKG_PATH}/mruby"
BUILD_CONFIG_PATH = "#{MRUBY_PATH}/build_config/#{BUILD_CONFIG}.rb"
MRBC_PATH = "#{MRUBY_PATH}/bin/mrbc"
MRUBY_CONFIG_PATH = "#{MRUBY_PATH}/bin/mruby-config"
LIBYAML_PATH = "#{MRUBY_PATH}/build/host/mrbgems/mruby-yaml/libyaml/build/lib/libyaml.a"

task default: :compile_script

file 'mruby.zip' do
sh "wget -c -O mruby.zip #{MRUBY_URL}"
end
directory "build"
directory "pkg"

file 'mruby' => 'mruby.zip' do
sh 'unzip mruby.zip'
dirname = Dir['mruby*'].find { File.directory?(_1) }
FileUtils.mv dirname, 'mruby'
file MRUBY_PATH => "pkg" do
sh "wget -c -O #{PKG_PATH}/mruby.zip #{MRUBY_URL}"
sh "unzip #{PKG_PATH}/mruby.zip -d #{PKG_PATH}"
dirname = Dir["#{PKG_PATH}/mruby-*"].first
FileUtils.mv dirname, "#{PKG_PATH}/mruby"
FileUtils.rm("#{PKG_PATH}/mruby.zip")
end

file BUILD_CONFIG_PATH => ['mruby', 'build_config.rb'] do |t|
file BUILD_CONFIG_PATH => [MRUBY_PATH, 'build_config.rb'] do |t|
FileUtils.cp 'build_config.rb', t.name
end

file 'mruby/bin' => ['mruby', BUILD_CONFIG_PATH]
file 'mruby/build' => 'mruby/bin'
file "#{MRUBY_PATH}/bin" => [MRUBY_PATH, BUILD_CONFIG_PATH]
file "#{MRUBY_PATH}/build" => "#{MRUBY_PATH}/bin"

file MRBC_PATH => ['mruby', BUILD_CONFIG_PATH] + Dir.glob('ext/**/*.rb') + Dir.glob('ext/**/*.c') do
file MRBC_PATH => [MRUBY_PATH, BUILD_CONFIG_PATH] + Dir.glob('ext/**/*.rb') + Dir.glob('ext/**/*.c') do
ENV['MRUBY_CONFIG'] = BUILD_CONFIG
Dir.chdir('mruby') { sh 'rake' }
Dir.chdir(MRUBY_PATH) { sh 'rake' }
end

desc 'Build mruby with our build config'
task mruby_build: MRBC_PATH

file 'mainrb.c' => ['main.rb', MRBC_PATH] do |t|
file "#{PKG_PATH}/mainrb.c" => ['main.rb', MRBC_PATH] do |t|
sh "#{MRBC_PATH} -Bmainrb -o #{t.name} main.rb"
end

directory 'build'

desc 'Compile script'
task compile_script: ['mainrb.c', 'runner.c', 'build'] + Dir.glob('mruby/build/host/**/*.a') do
task compile_script: ["#{PKG_PATH}/mainrb.c", 'runner.c', 'build'] + Dir.glob("#{MRUBY_PATH}/build/host/**/*.a") do
cflags = `#{MRUBY_CONFIG_PATH} --cflags`.strip
ldflags = `#{MRUBY_CONFIG_PATH} --ldflags`.strip
libs = `#{MRUBY_CONFIG_PATH} --libs`.strip
Expand Down
2 changes: 1 addition & 1 deletion build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
conf.gem mgem: 'mruby-yaml'
conf.gem mgem: 'mruby-dir'
conf.gem mgem: 'mruby-env'
conf.gem '../ext'
conf.gem '../../ext'

# C compiler settings
# conf.cc do |cc|
Expand Down
2 changes: 1 addition & 1 deletion runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <mruby/irep.h>
#include <mruby/array.h>
#include <mruby/value.h>
#include <mainrb.c>
#include <pkg/mainrb.c>

int
main(int argc, char ** argv)
Expand Down