-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
177 lines (155 loc) · 3.7 KB
/
Rakefile
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#
# Rakefile
#
# Basically you don't need to run this. Miscellaneous tasks
task :doc do
chdidr "doc/shg" do
sh "mdbook build"
end
end
desc "git ci, git tag and git push"
task :release do
ver = File.read('CHANGELOG.md')[/v([\d\.]+) /, 1]
v = "v" + ver
raise "Cargo.toml not updated" unless File.readlines("Cargo.toml").include?("version = \"#{ver}\"\n")
sh "git diff --cached"
puts "release as #{v}? [y/N]"
break unless $stdin.gets.chomp == "y"
sh "git ci -m '#{v}'"
sh "git tag '#{v}'"
sh "git push origin main --tags"
end
task :default => :test
task :compile do
cd "lib/skc_rustlib" do
sh "cargo build"
end
sh "cargo run -- build-corelib"
end
task :test do
cd "lib/skc_rustlib" do
sh "cargo build"
end
sh "cargo run -- build-corelib"
sh "cargo test -- --nocapture"
end
desc "Test if examples/*.sk runs as expected"
task :release_test do
Dir["examples/*.expected_out.*"].each do |exp|
next if ENV["FILTER"] && !exp.include?(ENV["FILTER"])
exp =~ %r{examples/(.*)\.expected_out\.(.*)} or raise
name, ext = $1, $2
actual = "examples/#{name}.actual.#{ext}"
sh "cargo run -- run examples/#{name}.sk > #{actual}"
if File.read(actual) != File.read(exp)
sh "diff #{exp} #{actual}"
raise "release_test failed for #{name}.sk"
end
end
end
task :llvm do
cd "lib/skc_rustlib" do
sh "cargo rustc -- --emit=llvm-ir -C debuginfo=0 -C opt-level=3 "
end
# ~/tmp/cargo_target/debug/deps/
end
RUST_FILES = Dir["lib/**/*.rs"] + Dir["src/*.rs"]
RUSTLIB_SIG = "lib/skc_rustlib/provided_methods.json5"
RUSTLIB_FILES = [
*Dir["lib/skc_rustlib/src/**/*.rs"],
RUSTLIB_SIG,
"lib/skc_rustlib/Cargo.toml",
]
CARGO_TARGET = ENV["SHIIKA_CARGO_TARGET"] || "./target"
RUSTLIB_A = File.expand_path "#{CARGO_TARGET}/debug/libskc_rustlib.a"
file RUSTLIB_A => RUSTLIB_FILES do
cd "lib/skc_rustlib" do
sh "cargo build"
end
end
BUILTIN_BC = "builtin/builtin.bc"
file BUILTIN_BC => [*RUST_FILES, RUSTLIB_SIG, *Dir["builtin/*.sk"]] do
sh "cargo run -- build-corelib"
end
A_OUT = "./a.sk.out"
file A_OUT => [*RUST_FILES, RUSTLIB_A, BUILTIN_BC, "./a.sk"] do
#sh "cargo fmt"
sh "cargo run -- run ./a.sk"
end
task :fmt do
sh "cargo fmt"
end
task :asm do
sh "llc ./a.sk.ll"
end
#
# debugify
#
A_BC = "./a.sk.bc"
file A_BC => RUST_FILES + [BUILTIN_BC, RUSTLIB_A, "./a.sk"] do
sh "cargo run -- compile ./a.sk"
end
A_LL = "./a.sk.ll"
file A_LL => RUST_FILES + [BUILTIN_BC, RUSTLIB_A, "./a.sk"] do
sh "cargo run -- compile ./a.sk"
end
DEBUG_LL = "./a.sk.debug.ll"
file DEBUG_LL => A_LL do
sh "opt #{A_LL} -debugify -S -o #{DEBUG_LL}"
end
DEBUG_OUT = "./a.debug.out"
file DEBUG_OUT => [A_BC, BUILTIN_BC, RUSTLIB_A, DEBUG_LL] do
sh "clang",
"-lm",
"-ldl",
"-lpthread",
"-o", DEBUG_OUT,
"-O0",
BUILTIN_BC,
RUSTLIB_A,
DEBUG_LL
end
task "clang" do
sh "clang",
"-lm",
"-ldl",
"-lpthread",
"-o", "a.sk.out",
"-framework", "Foundation",
"-O0",
BUILTIN_BC,
RUSTLIB_A,
"a.sk.ll"
end
task :debugify => DEBUG_OUT
task :a => :async
#task :a => [:fmt, A_OUT] do
#task :a => [:fmt] do
# sh "cargo clippy"
# sh "cargo run -- run a.sk"
#end
#
# new async runtime
#
task :async do
sh "cargo fmt"
cd "lib/skc_runtime/" do
sh "cargo build"
end
sh "cargo run --bin exp_shiika -- a.sk"
end
task async_test: :async do
sh "./a.out"
end
task :async_integration_test do
cd "lib/skc_runtime/" do
sh "cargo build"
end
Dir["tests/new_runtime/*.sk"].each do |path|
next if ENV["FILTER"] && !path.include?(ENV["FILTER"])
name = path.sub(".sk", "")
sh "cargo run --bin exp_shiika -- #{name}.sk"
sh "#{name}.out > #{name}.actual_out"
sh "diff #{name}.actual_out #{name}.expected_out"
end
end