-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmrbgem.rake
81 lines (67 loc) · 2.67 KB
/
mrbgem.rake
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
require 'open3'
require 'fileutils'
$LOAD_PATH << File.expand_path('../mrblib', __FILE__)
unless defined? DEFAULT_LIBSECCOMP_VERSION
DEFAULT_LIBSECCOMP_VERSION = "2.3.1"
end
MRuby::Gem::Specification.new('mruby-seccomp') do |spec|
require 'seccomp/versions'
spec.license = 'MIT'
spec.authors = 'Uchio Kondo'
spec.version = Seccomp::VERSION
def run_command env, command
STDOUT.sync = true
puts "EXEC\t[mruby-seccomp] #{command}"
Open3.popen2e(env, command) do |stdin, stdout, thread|
print stdout.read
fail "#{command} failed" if thread.value != 0
end
end
def spec.get_libseccomp_version
if self.cc.defines.flatten.find{|d| d =~ /^MRB_SECCOMP_LIBVER=([\.0-9]+)$/ }
return $1
else
DEFAULT_LIBSECCOMP_VERSION
end
end
def spec.bundle_seccomp
version = get_libseccomp_version
def seccomp_dir(b); "#{b.build_dir}/vendor/libseccomp"; end
def seccomp_objs_dir(b); "#{seccomp_dir(b)}/.objs"; end
def seccomp_header(b); "#{seccomp_dir(b)}/include/seccomp.h"; end
def libseccomp_a(b); libfile "#{seccomp_objs_dir(b)}/lib/libseccomp"; end
task :clean do
FileUtils.rm_rf [seccomp_dir(build)]
end
file seccomp_header(build) do
unless File.exist? seccomp_dir(build)
tmpdir = '/tmp'
run_command ENV, "rm -rf #{tmpdir}/libseccomp-#{version}"
run_command ENV, "mkdir -p #{File.dirname(seccomp_dir(build))}"
run_command ENV, "curl -L https://github.com/seccomp/libseccomp/releases/download/v#{version}/libseccomp-#{version}.tar.gz | tar -xz -f - -C #{tmpdir}"
run_command ENV, "mv -f #{tmpdir}/libseccomp-#{version} #{seccomp_dir(build)}"
end
end
file libseccomp_a(build) => seccomp_header(build) do
sh "mkdir -p #{seccomp_objs_dir(build)}"
Dir.chdir seccomp_dir(build) do
run_command ENV, "./configure --enable-static --disable-shared --prefix=#{seccomp_objs_dir(build)}"
run_command ENV, "make"
run_command ENV, "make install"
end
end
libmruby_a = libfile("#{build.build_dir}/lib/libmruby")
file libmruby_a => libseccomp_a(build)
self.cc.include_paths << File.dirname(seccomp_header(build))
self.linker.library_paths << File.dirname(libseccomp_a(build))
self.linker.libraries << 'seccomp'
end
spec.bundle_seccomp
spec.add_dependency 'mruby-socket'
spec.add_test_dependency 'mruby-print'
spec.add_test_dependency 'mruby-io'
spec.add_test_dependency 'mruby-process', mgem: 'mruby-process'
spec.add_test_dependency 'mruby-uname', mgem: 'mruby-uname'
spec.add_test_dependency 'mruby-errno', mgem: 'mruby-errno'
spec.add_test_dependency 'mruby-exec', github: 'haconiwa/mruby-exec'
end