Skip to content

Commit

Permalink
refactor: rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark24Code committed Jun 27, 2024
1 parent 309669f commit 2f60c78
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
mruby
build
.cache
*.tar.gz
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MacOS
Debian/Ubuntu/Mint Linux

- AMD64 ✅
- ARM64 ✅

---

Expand All @@ -29,31 +30,36 @@ Ruby3 提供 Rake

```
➜ build git:(main) rake -T
rake build[enter,output] # build program
rake compiler:build # build mruby
rake compiler:download # download mruby
rake init # init
rake install # install
rake run[enter] # run program
rake build # build program
rake build_merge # merge program in build
rake build_to_c # build to c code
rake cache_merge # merge program in cache
rake clean # clean
rake init_build # init build dir
rake init_cache # init develop cache dir
rake mruby:build # build mruby
rake mruby:build_config # replace mruby build config
rake mruby:custom_build # custom config build mruby
rake mruby:download # download mruby
rake mruby:init # init
rake run # run program
```

## 2.初次使用
## 1.模仿 golang 的 go run

`rake init` 初始化编译器
`rake run`

## 3.模仿 golang 的 go run
## 2.模仿 golang 的 go build

`rake 'run[main.rb]'`
`rake build`

## 4.模仿 golang 的 go build
## 3.交叉编译的包

`rake 'build[main.rb]'`
借助 Github Action 在 main 分支推送后,查看 Action 构建任务,下载产物

## TODO

- [ ] 交叉编译
- [ ] 添加基本的 gem
- [ ] 将编译器编译成 portable mruby 跳过本地编译
- [x] 交叉编译
- [x] 多文件

## 约定
Expand Down
24 changes: 9 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
namespace :mruby do
desc "download mruby"
task :download do
if !File.exist?("#{MRUBY_BIN}/mruby")
if !File.exist?("#{MRUBY_BIN}")
sh "rm -rf .tmp ; rm -rf #{MRUBY_DIR}"
sh "mkdir .tmp; mkdir -p #{COMPILER_DIR}"
sh "wget -O .tmp/#{MRUBY_NAME}.zip #{MRUBY_URL}"
Expand All @@ -88,18 +88,13 @@ namespace :mruby do
end

desc "init"
task :init => [:"mruby:download", :"mruby:build" ] do
if !File.exist? MRUBY_BUILD_CONFIG
sh "cp #{MRUBY_DIR}/build_config/default.rb #{MRUBY_BUILD_CONFIG}"
end
task :init => [:"mruby:download"] do
puts "init mruby #{MRUBY_NAME}"
end

desc "custom config build mruby"
task :custom_build do
if file_content_change?(MRUBY_BUILD_CONFIG, "#{MRUBY_DIR}/build_config/#{APP_NAME}_config.rb")
sh "cd #{MRUBY_DIR} && rake MRUBY_CONFIG=#{APP_NAME}_config"
end
sh "cd #{MRUBY_DIR} && rake MRUBY_CONFIG=#{APP_NAME}_config"
end

end
Expand Down Expand Up @@ -128,7 +123,7 @@ task :build_merge => [:init_build] do
end

desc "run program"
task :run => [:cache_merge, :"mruby:custom_build"] do
task :run => [:"mruby:init", :"mruby:build_config", :"mruby:custom_build", :cache_merge] do
sh "#{MRUBY} #{CACHE_DIR}/main.rb"
end

Expand Down Expand Up @@ -164,13 +159,12 @@ end


desc "build program"
task :build => [:"mruby:init", :build_merge, :build_to_c, :"mruby:build_config", :"mruby:custom_build"] do
task :build => [:"mruby:init", :"mruby:build_config", :"mruby:custom_build", :build_merge, :build_to_c] do
sh "cc -std=c99 -I#{MRUBY_INCLUDE} #{BUILD_DIR}/*.c -o #{BUILD_DIR}/#{APP_NAME} #{MRUBY_LIB}/libmruby.a -lm"
## TODO portable need gems
# sh "mkdir -p #{BUILD_DIR}/portable/"
# sh "cp #{MRUBY_BIN}/mruby #{BUILD_DIR}/portable/"
# sh "mv #{BUILD_DIR}/main.rb #{BUILD_DIR}/portable/"
sh "rm #{BUILD_DIR}/*.h; rm #{BUILD_DIR}/*.c; rm #{BUILD_DIR}/*.rb"
sh "mkdir -p #{BUILD_DIR}/portable/"
sh "cp #{MRUBY_BIN}/mruby #{BUILD_DIR}/portable/"
sh "mv #{BUILD_DIR}/main.rb #{BUILD_DIR}/portable/"
sh "rm -f #{BUILD_DIR}/*.h; rm -f #{BUILD_DIR}/*.c; rm -f #{BUILD_DIR}/*.rb"
sh "tar -czvf app.tar.gz #{BUILD_DIR}"
end

Expand Down

0 comments on commit 2f60c78

Please sign in to comment.