-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRakefile
More file actions
149 lines (134 loc) · 4.11 KB
/
Rakefile
File metadata and controls
149 lines (134 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
require "fileutils"
unless ENV.include? "PICO_SDK_PATH"
ENV["PICO_SDK_PATH"] = "#{File.dirname(__FILE__)}/lib/pico-sdk"
end
unless ENV.include? "PICO_EXTRAS_PATH"
ENV["PICO_EXTRAS_PATH"] = "#{File.dirname(__FILE__)}/lib/pico-extras"
end
PICO_SDK_TAG = "2.2.0"
PICO_EXTRAS_TAG = "sdk-#{PICO_SDK_TAG}"
def mruby_config(vm, board)
"#{File.expand_path('..', __FILE__)}/build_config/r2p2-#{vm}-#{board}.rb"
end
def mruby_build_path(vm, board)
"#{File.expand_path('..', __FILE__)}/lib/picoruby/build/r2p2-#{vm}-#{board}"
end
def def_board(board)
case board
when 'pico2_w'
'-D PICO_PLATFORM=rp2350 -D PICO_BOARD=pico2_w -D USE_WIFI=1'
when 'pico2'
'-D PICO_PLATFORM=rp2350 -D PICO_BOARD=pico2'
when 'pico_w'
'-D PICO_PLATFORM=rp2040 -D PICO_BOARD=pico_w -D USE_WIFI=1'
else
'-D PICO_PLATFORM=rp2040 -D PICO_BOARD=pico'
end
end
def def_build_type(mode)
case mode
when 'debug'
"-D CMAKE_BUILD_TYPE=Debug -D PICORUBY_DEBUG=1"
else
"-D CMAKE_BUILD_TYPE=Release -D NDEBUG=1"
end
end
def def_r2p2_name(vm, board)
"-D R2P2_NAME=R2P2-#{vm.upcase}-#{board.upcase}"
end
def def_msc(mode)
'-D PICORUBY_MSC_FLASH=1'
end
def def_picorb_vm(vm)
vm == 'picoruby' ? '-D PICORB_VM_MRUBYC=1' : '-D PICORB_VM_MRUBY=1'
end
def build_dir(vm, board, mode)
"build/#{vm}/#{board}/#{mode}"
end
task :setup do
sh "git submodule update --init"
FileUtils.cd "lib/picoruby" do
sh "bundle install"
end
end
%w[picoruby microruby].each do |vm|
namespace vm do
%w[pico pico_w pico2 pico2_w].each do |board|
namespace board do
%w[debug prod].each do |mode|
desc "Build #{vm} for #{board} (#{mode})"
task mode => :check_pico_sdk do
dir = build_dir(vm, board, mode)
FileUtils.mkdir_p dir
FileUtils.cd "lib/picoruby" do
sh "rake test" if ENV['DO_TEST']
sh "MRUBY_CONFIG=#{mruby_config(vm, board)} #{mode=='debug' ? 'PICORUBY_DEBUG=1' : ''} rake"
end
defs = <<~DEFS
-D EXTRA_LIBRARY_PATH=#{mruby_build_path(vm, board)}/lib \
-D EXTRA_INCLUDE_DIR=#{mruby_build_path(vm, board)}/include \
-D PICO_CYW43_SUPPORTED=1 \
-D MRUBY_CONFIG=#{mruby_config(vm, board)} \
-D BUILD_DIR=#{dir} \
#{def_picorb_vm(vm)} \
#{def_r2p2_name(vm, board)} \
#{def_board(board)} \
#{def_build_type(mode)} \
#{def_msc(mode)}
DEFS
sh "cmake -B #{dir} #{defs}"
sh "cmake --build #{dir}"
end
end
desc "Clean #{vm} for #{board} (both debug and prod)"
task :clean do
FileUtils.cd "lib/picoruby" do
config = mruby_config(vm, board)
if File.exist?(config)
sh "MRUBY_CONFIG=#{config} rake clean"
end
end
%w[debug prod].each do |mode|
dir = build_dir(vm, board, mode)
FileUtils.rm_f(Dir["#{dir}/R2P2*.*"]) if Dir.exist? dir
end
end
end
end
end
end
task :check_pico_sdk => :check_pico_sdk_path do
FileUtils.cd ENV['PICO_SDK_PATH'] do
if `git describe --tags --exact-match`.chomp != PICO_SDK_TAG
raise <<~MSG
pico-sdk #{PICO_SDK_TAG} is not checked out!\n
Tips for dealing with:\n
cd #{ENV['PICO_SDK_PATH']} && \\
git fetch origin --tags && \\
git checkout #{PICO_SDK_TAG} && \\
git submodule update --recursive\n
MSG
end
end
FileUtils.cd ENV['PICO_EXTRAS_PATH'] do
if `git describe --tags --exact-match`.chomp != PICO_EXTRAS_TAG
raise <<~MSG
pico-extras #{PICO_EXTRAS_TAG} is not checked out!\n
Tips for dealing with:\n
cd #{ENV['PICO_EXTRAS_PATH']} && \\
git fetch origin --tags && \\
git checkout #{PICO_EXTRAS_TAG} && \\
git submodule update --recursive\n
MSG
end
end
end
task :check_pico_sdk_path do
%w(PICO_SDK_PATH PICO_EXTRAS_PATH).each do |env|
unless ENV[env]
raise <<~MSG
Environment variable `#{env}` does not exist!
MSG
end
end
end