From 07850f27e4a852e1d5e30ff5b2269a6460cd072f Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Wed, 9 Feb 2022 15:03:09 -0500 Subject: [PATCH 1/2] Contain build artifacts to a pkg directory. In an effort to make the build process cleaner and not pollute the root directory with build artifacts, I have updated the build script to ensure that any build artifacts are places in a pkg directory. This allows easier understanding and easier cleanup. --- .gitignore | 6 +----- Rakefile | 43 +++++++++++++++++++++++-------------------- build_config.rb | 2 +- runner.c | 2 +- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 9abb80b..bd45ad3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ -mruby*zip -mruby - -*rb.c - build +pkg diff --git a/Rakefile b/Rakefile index 70571b5..bf63f01 100644 --- a/Rakefile +++ b/Rakefile @@ -1,47 +1,50 @@ # 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' } + puts "in here #{MRUBY_PATH}" + Dir.chdir(MRUBY_PATH) { sh 'rake' } + puts "out here" 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 diff --git a/build_config.rb b/build_config.rb index 24f1d0a..b568672 100644 --- a/build_config.rb +++ b/build_config.rb @@ -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| diff --git a/runner.c b/runner.c index 18c590f..4020967 100644 --- a/runner.c +++ b/runner.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include int main(int argc, char ** argv) From a97a568773fd9810929c91140b25336c36033497 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Wed, 9 Feb 2022 15:09:30 -0500 Subject: [PATCH 2/2] cleanup --- Rakefile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index bf63f01..4f9b43d 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ task default: :compile_script directory "build" directory "pkg" -file "#{MRUBY_PATH}" => "pkg" do +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 @@ -22,18 +22,16 @@ file "#{MRUBY_PATH}" => "pkg" do FileUtils.rm("#{PKG_PATH}/mruby.zip") end -file "#{BUILD_CONFIG_PATH}" => [MRUBY_PATH, '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_PATH}/bin" => [MRUBY_PATH, BUILD_CONFIG_PATH] file "#{MRUBY_PATH}/build" => "#{MRUBY_PATH}/bin" -file "#{MRBC_PATH}" => [MRUBY_PATH, 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 - puts "in here #{MRUBY_PATH}" Dir.chdir(MRUBY_PATH) { sh 'rake' } - puts "out here" end desc 'Build mruby with our build config'