-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbuild_config.rb
141 lines (110 loc) · 4.04 KB
/
build_config.rb
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
def gem_config(conf)
conf.gem File.expand_path(File.dirname(__FILE__))
end
def debug_config(conf)
conf.instance_eval do
# In `enable_debug`, use this for release build too.
# Allow showing backtrace and prevent "fptr_finalize failed" error in mruby-io.
@mrbc.compile_options += ' -g'
end
end
def download_macos_sdk(path)
version = '11.3'
system('wget', "https://github.com/phracker/MacOSX-SDKs/releases/download/#{version}/MacOSX#{version}.sdk.tar.xz", exception: true)
system('tar', 'xf', "MacOSX#{version}.sdk.tar.xz", exception: true)
system('rm', "MacOSX#{version}.sdk.tar.xz", exception: true)
system('mv', "MacOSX#{version}.sdk", path, exception: true)
end
macos_sdk = File.expand_path('./MacOSX.sdk', __dir__)
build_targets = ENV.fetch('BUILD_TARGET', '').split(',')
# mruby's build system always requires to run host build for mrbc
MRuby::Build.new do |conf|
toolchain :gcc
#conf.enable_bintest
#conf.enable_debug
#conf.enable_test
debug_config(conf)
gem_config(conf)
end
if build_targets.include?('linux-x86_64')
MRuby::Build.new('linux-x86_64') do |conf|
toolchain :gcc
[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc -target x86_64-linux-musl'
end
conf.archiver.command = 'zig ar'
debug_config(conf)
gem_config(conf)
end
end
if build_targets.include?('linux-i386')
MRuby::CrossBuild.new('linux-i386') do |conf|
toolchain :gcc
[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc -target i386-linux-musl'
end
conf.archiver.command = 'zig ar'
# To configure: mrbgems/mruby-yaml, k0kubun/mruby-onig-regexp
conf.host_target = 'i386-pc-linux-gnu'
debug_config(conf)
gem_config(conf)
end
end
if build_targets.include?('linux-armhf')
MRuby::CrossBuild.new('linux-armhf') do |conf|
toolchain :gcc
[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc -target arm-linux-musleabihf'
end
conf.archiver.command = 'zig ar'
# To configure: mrbgems/mruby-yaml, k0kubun/mruby-onig-regexp
conf.host_target = 'arm-linux-musleabihf'
debug_config(conf)
gem_config(conf)
end
end
if build_targets.include?('linux-aarch64')
MRuby::CrossBuild.new('linux-aarch64') do |conf|
toolchain :gcc
[conf.cc, conf.linker].each do |cc|
cc.command = 'zig cc -target aarch64-linux-musl'
end
conf.archiver.command = 'zig ar'
# To configure: mrbgems/mruby-yaml, k0kubun/mruby-onig-regexp
conf.host_target = 'aarch64-linux-musl'
debug_config(conf)
gem_config(conf)
end
end
if build_targets.include?('darwin-x86_64')
MRuby::CrossBuild.new('darwin-x86_64') do |conf|
toolchain :gcc
unless Dir.exist?(macos_sdk)
download_macos_sdk(macos_sdk)
end
conf.cc.command = "zig cc -target x86_64-macos -mmacosx-version-min=10.14 -isysroot #{macos_sdk.shellescape} -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks"
conf.linker.command = "zig cc -target x86_64-macos -mmacosx-version-min=10.4 --sysroot #{macos_sdk.shellescape} -F/System/Library/Frameworks -L/usr/lib"
conf.archiver.command = 'zig ar'
ENV['RANLIB'] ||= 'zig ranlib'
# To configure: mrbgems/mruby-yaml, k0kubun/mruby-onig-regexp
conf.host_target = 'x86_64-darwin'
debug_config(conf)
gem_config(conf)
end
end
if build_targets.include?('darwin-aarch64')
MRuby::CrossBuild.new('darwin-aarch64') do |conf|
toolchain :gcc
unless Dir.exist?(macos_sdk)
download_macos_sdk(macos_sdk)
end
conf.cc.command = "zig cc -target aarch64-macos -mmacosx-version-min=11.1 -isysroot #{macos_sdk.shellescape} -iwithsysroot /usr/include -iframeworkwithsysroot /System/Library/Frameworks"
conf.linker.command = "zig cc -target aarch64-macos -mmacosx-version-min=11.1 --sysroot #{macos_sdk.shellescape} -F/System/Library/Frameworks -L/usr/lib"
conf.archiver.command = 'zig ar'
ENV['RANLIB'] ||= 'zig ranlib'
# To configure: mrbgems/mruby-yaml, k0kubun/mruby-onig-regexp
conf.host_target = 'aarch64-darwin'
debug_config(conf)
gem_config(conf)
end
end