-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile.toml
482 lines (423 loc) · 16.9 KB
/
Makefile.toml
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
[config]
skip_core_tasks = true
min_version = "0.31.0"
default_to_workspace = false
[env]
CARGO_MAKE_CRATE_INSTALLATION_LOCKED = "true"
RUST_TARGET_PATH = "${CARGO_MAKE_WORKING_DIRECTORY}"
XARGO_RUST_SRC = "${CARGO_MAKE_WORKING_DIRECTORY}/rust/src"
GDB_PORT = { script = ["echo ${GDB_PORT:-9090}"] }
VNC_PORT = { script = ["echo ${VNC_PORT:-:0}"] }
CLIPPY_RULES = """
-A clippy::redundant_field_names \
-A clippy::unreadable_literal \
-A clippy::identity_op \
-A clippy::zero_prefixed_literal \
-A clippy::redundant_closure \
-W clippy::cast_possible_wrap \
-W clippy::cast_sign_loss \
-W clippy::default_trait_access \
-W clippy::explicit_into_iter_loop \
-W clippy::explicit_iter_loop \
-W clippy::missing_docs_in_private_items \
-W clippy::mut_mut \
-W clippy::used_underscore_binding \
-W clippy::wildcard_dependencies \
-W clippy::wrong_pub_self_convention"""
QEMU_COMMON_FLAGS = """\
-boot d \
-cdrom os.iso \
-serial mon:stdio \
-vnc ${VNC_PORT} \
-no-reboot \
-drive id=diskA,file=DISK.img,format=raw,if=none -device ahci,id=ahci \
-device ide-drive,drive=diskA,bus=ahci.0 \
-machine q35 \
-m 512M"""
#### Profile-specific flags
# Which subfolder of target will rustc put its files into. Target is
# automatically prepended if necessary.
PROFILE_NAME = "debug"
# Flags to pass to cargo when building any project.
COMPILER_FLAGS = "--locked"
# Extra flags to pass when building the kernel. Appended to COMPILER_FLAGS.
KERNEL_FLAGS = ""
# Extra flags to pass to qemu.
QEMU_PROFILE_FLAGS = ""
[env.development]
PROFILE_NAME = "debug"
COMPILER_FLAGS = "--locked"
KERNEL_FLAGS = "-Z package-features --features=panic-on-exception"
QEMU_EXTRA_FLAGS = "-d cpu_reset"
[env.production]
PROFILE_NAME = "release"
COMPILER_FLAGS = "--locked --release"
KERNEL_FLAGS = ""
QEMU_EXTRA_FLAGS = ""
[tasks.bootstrap-linker]
script_runner = "@shell"
script = ["cp linker-scripts/bootstrap.ld link.T"]
[tasks.kernel-linker]
script_runner = "@shell"
script = ["cp linker-scripts/kernel.ld link.T"]
[tasks.install-rust-src]
install_crate = { rustup_component_name = "rust-src" }
[tasks.install-mkisofs-rs]
install_crate = { crate_name = "mkisofs-rs", binary = "mkisofs-rs", test_arg = "--help", min_version = "0.1.2" }
[tasks.install-xargo]
dependencies = ["install-rust-src"]
install_crate = { crate_name = "xargo", binary = "xargo", test_arg = "--version", min_version = "0.3.18" }
[tasks.bootstrap]
description = "Compiles the i386 bootstrap"
dependencies = ["bootstrap-linker", "install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-none", "--package=sunrise-bootstrap", "@@split(COMPILER_FLAGS, )" ]
[tasks.kernel]
description = "Compiles the kernel"
dependencies = ["kernel-linker", "install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-none", "--package=sunrise-kernel", "@@split(COMPILER_FLAGS, )", "@@split(KERNEL_FLAGS, )"]
[tasks.vi]
description = "Compiles sunrise-vi"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-vi", "@@split(COMPILER_FLAGS, )"]
[tasks.sm]
description = "Compiles sunrise-sm"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-sm", "@@split(COMPILER_FLAGS, )"]
[tasks.shell]
description = "Compiles sunrise-shell"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-shell", "@@split(COMPILER_FLAGS, )"]
[tasks.wall-clock]
description = "Compiles sunrise-wall-clock"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-wall-clock", "@@split(COMPILER_FLAGS, )"]
[tasks.ahci]
description = "Compiles sunrise-ahci"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-ahci", "@@split(COMPILER_FLAGS, )"]
[tasks.time]
description = "Compiles sunrise-time"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-time", "@@split(COMPILER_FLAGS, )"]
[tasks.fs]
description = "Compiles sunrise-fs"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-fs", "@@split(COMPILER_FLAGS, )"]
[tasks.loader]
description = "Compiles sunrise-loader"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-loader", "@@split(COMPILER_FLAGS, )"]
[tasks.keyboard]
description = "Compiles sunrise-keyboard"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-keyboard", "@@split(COMPILER_FLAGS, )"]
[tasks.twili]
description = "Compiles sunrise-twili"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=sunrise-twili", "@@split(COMPILER_FLAGS, )"]
[tasks.std_hello_world]
description = "Compiles std_hello_world"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=std_hello_world", "@@split(COMPILER_FLAGS, )"]
[tasks.df]
description = "Compiles df"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=df", "@@split(COMPILER_FLAGS, )"]
[tasks.uutils]
description = "Compiles uutils (coreutils)"
dependencies = ["install-xargo", "setup-rust"]
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "--package=uutils", "-Z", "package-features", "--features=sunrise", "--no-default-features", "@@split(COMPILER_FLAGS, )"]
[tasks.userspace-nostd]
internal = true
command = "xargo"
args = ["build", "--target=i386-unknown-sunrise-user", "@@split(COMPILER_FLAGS, )",
"-p", "sunrise-shell", "-p", "sunrise-wall-clock", "-p", "sunrise-sm",
"-p", "sunrise-vi", "-p", "sunrise-ahci", "-p", "sunrise-time",
"-p", "sunrise-fs", "-p", "sunrise-loader", "-p", "sunrise-keyboard",
"-p", "sunrise-twili"
]
[tasks.userspace]
description = "Compiles userspace apps"
dependencies = ["userspace-nostd", "std_hello_world", "uutils", "df"]
[tasks.iso]
description = "Creates a bootable ISO containing the kernel and grub."
dependencies = ["bootstrap", "kernel", "userspace", "install-mkisofs-rs"]
script_runner = "@shell"
script = [
'''
cp target/i386-unknown-none/$PROFILE_NAME/sunrise-bootstrap isofiles/boot/
cp target/i386-unknown-none/$PROFILE_NAME/sunrise-kernel isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-shell isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-time isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-wall-clock isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-sm isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-vi isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-ahci isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-fs isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-loader isofiles/boot/
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-keyboard isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]
[tasks.disk]
description = "Creates an empty disk image."
script = [
'''
mkdir -p external/filesystem/disk_template/bin/wall-clock/flags
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-wall-clock external/filesystem/disk_template/bin/wall-clock/main
# TODO: https://github.com/sagiegurari/shell2batch/issues/9
touch external/filesystem/disk_template/bin/wall-clock/flags/boot.flag
mkdir -p external/filesystem/disk_template/bin/std_hello_world/flags
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/std_hello_world external/filesystem/disk_template/bin/std_hello_world/main
mkdir -p external/filesystem/disk_template/bin/twili/flags
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/sunrise-twili external/filesystem/disk_template/bin/twili/main
touch external/filesystem/disk_template/bin/twili/flags/boot.flag
mkdir -p external/filesystem/disk_template/bin/uutils
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/uutils external/filesystem/disk_template/bin/uutils/main
mkdir -p external/filesystem/disk_template/bin/df
cp target/i386-unknown-sunrise-user/$PROFILE_NAME/df external/filesystem/disk_template/bin/df/main
cargo run --manifest-path disk-initializer/Cargo.toml -- DISK.img 157286400 external/filesystem/disk_template/
'''
]
[tasks.qemu]
description = "Runs the bootable ISO in qemu."
dependencies = ["iso", "disk"]
command = "qemu-system-i386"
args = [
"@@split(QEMU_COMMON_FLAGS, )", "@@split(QEMU_EXTRA_FLAGS, )"
]
[tasks.qemu-gdb]
description = "Runs the bootable ISO in qemu."
dependencies = ["iso", "disk"]
command = "qemu-system-i386"
args = [
"@@split(QEMU_COMMON_FLAGS, )", "@@split(QEMU_EXTRA_FLAGS, )",
"-gdb", "tcp::${GDB_PORT}", "-S"
]
[tasks.doc]
description = "Generate the project's documentation"
env = { "RUSTDOCFLAGS" = "-Z unstable-options --enable-index-page" }
command = "cargo"
args = ["doc", "--no-deps"]
[tasks.doc-full]
description = "Generate the project's documentation, including private items"
env = { "RUSTDOCFLAGS" = "-Z unstable-options --enable-index-page" }
command = "cargo"
args = ["doc", "--no-deps", "--document-private-items",
"-p", "docs",
"-p", "sunrise-bootstrap",
"-p", "sunrise-kernel",
"-p", "sunrise-shell",
"-p", "sunrise-time",
"-p", "sunrise-libuser",
"-p", "sunrise-wall-clock",
"-p", "sunrise-sm",
"-p", "sunrise-vi",
"-p", "sunrise-ahci",
"-p", "sunrise-fs",
"-p", "sunrise-libutils",
"-p", "sunrise-libkern",
"-p", "sunrise-libtimezone",
"-p", "sunrise-loader",
"-p", "sunrise-keyboard",
"-p", "swipc-gen",
"-p", "swipc-parser",
"-p", "disk-initializer",
]
[tasks.deploy-doc]
install_crate = { crate_name = "cargo-travis", binary = "cargo", test_arg = ["doc-upload", "--help"] }
install_crate_args = ["--git", "https://github.com/roblabla/cargo-travis", "--rev", "doc-upload-target"]
description = "Upload this project's documentation on github pages. Should only run on CI."
command = "cargo"
args = ["doc-upload", "--clobber-index"]
[tasks.test]
description = "Run all the tests."
command = "cargo"
args = ["test", "--target=i686-unknown-linux-gnu",
"-p", "docs",
"-p", "sunrise-bootstrap",
"-p", "sunrise-kernel",
"-p", "sunrise-shell",
"-p", "sunrise-time",
"-p", "sunrise-libuser",
"-p", "sunrise-wall-clock",
"-p", "sunrise-sm",
"-p", "sunrise-vi",
"-p", "sunrise-ahci",
"-p", "sunrise-fs",
"-p", "sunrise-libutils",
"-p", "sunrise-libkern",
"-p", "sunrise-libtimezone",
"-p", "sunrise-loader",
"-p", "sunrise-keyboard",
"-p", "swipc-gen",
"-p", "swipc-parser",
"-p", "disk-initializer",
]
[tasks.clippy-sunrise-kernel-target]
description = "Run clippy on sunrise kernel and bootstrap"
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-none",
"-p", "sunrise-kernel",
"-p", "sunrise-bootstrap",
"--",
"@@split(CLIPPY_RULES, )",
"${@}",
]
[tasks.clippy-sunrise-userspace-target-nostd]
description = "Run clippy on sunrise userspace (no std)"
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-sunrise-user",
"-p", "sunrise-shell",
"-p", "sunrise-time",
"-p", "sunrise-libuser",
"-p", "sunrise-wall-clock",
"-p", "sunrise-sm",
"-p", "sunrise-vi",
"-p", "sunrise-ahci",
"-p", "sunrise-fs",
"-p", "sunrise-libutils",
"-p", "sunrise-libkern",
"-p", "sunrise-libtimezone",
"-p", "sunrise-loader",
"-p", "sunrise-keyboard",
"--",
"@@split(CLIPPY_RULES, )",
"${@}",
]
[tasks.clippy-sunrise-userspace-target-std]
description = "Run clippy on sunrise userspace (std)"
dependencies = ["install-xargo", "setup-rust"]
install_crate = { rustup_component_name = "clippy" }
command = "xargo"
args = ["clippy", "--target=i386-unknown-sunrise-user",
"-p", "std_hello_world",
"-p", "df",
"--",
"@@split(CLIPPY_RULES, )",
"${@}",
]
[tasks.clippy-host-target]
description = "Run clippy on host components (relying on std)"
install_crate = { rustup_component_name = "clippy" }
command = "cargo"
args = ["clippy",
"-p", "swipc-gen", "-p", "swipc-parser", "-p", "docs", "-p", "disk-initializer",
"--",
"@@split(CLIPPY_RULES, )",
"${@}",
]
[tasks.setup-rust]
script_runner = "@duckscript"
script = [
'''
version = readfile rust-toolchain
date = split ${version} "-"
array_remove ${date} 0
date = array_join ${date} "-"
datetime = concat ${date} " 12:00:00 +0000"
function apply_patches
patches = glob_array ${CARGO_MAKE_WORKING_DIRECTORY}/rust-patches/*.patch
patches = array_join ${patches} " "
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
exec git am --committer-date-is-author-date %{patches}
end
# If rust folder doesn't exist, create it, and import the rust source.
if not is_path_exists ${CARGO_MAKE_WORKING_DIRECTORY}/rust
output = exec rustc --print sysroot
output.stdout = trim ${output.stdout}
sysroot = concat ${output.stdout} /lib/rustlib/src/rust/
cp ${sysroot} ${CARGO_MAKE_WORKING_DIRECTORY}
cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/
exec git init
exec git add .
set_env GIT_COMMITTER_NAME patchsystem
set_env GIT_COMMITTER_EMAIL patchsystem
set_env GIT_COMMITTER_DATE ${datetime}
set_env GIT_AUTHOR_NAME patchsystem
set_env GIT_AUTHOR_EMAIL patchsystem
set_env GIT_AUTHOR_DATE ${datetime}
echo "Importing rust-src"
exec git commit -m ${version} -q
unset_env GIT_AUTHOR_DATE
unset_env GIT_AUTHOR_EMAIL
unset_env GIT_AUTHOR_NAME
end
use_dirty_rust_repo = get_env USE_DIRTY_RUST_REPO
if not is_empty ${use_dirty_rust_repo}
echo "Using dirty rust repository."
exit 0
end
cd ${CARGO_MAKE_WORKING_DIRECTORY}/rust/
# Check the original commit matches the current rust version. If it doesn't,
# bail out, tell user they need to update their patches.
head_rev = exec git rev-list --max-parents=0 HEAD
head_rev = trim ${head_rev.stdout}
message = exec git log --format=%B -n 1 ${head_rev}
message = trim ${message.stdout}
assert_eq ${message} ${version} "\nRust version doesn't match rust-toolchain. The patches will need to be updated. See docs/UPDATE_RUST.md for more information."
# Check if there's any uncommitted changes. If there are, bail out, tell
# user.
exec git update-index --refresh
status = exec git status --porcelain -z
status = trim ${status.stdout}
status_empty = is_empty ${status}
assert ${status_empty} "\nUncommited changes were found in the rust folder.\nEither commit them and create a patch, or set the USE_DIRTY_RUST_REPO environment variable."
# Check if there's any commits that got changed. If there are, tell the user
# to create patches.
output = exec git log --committer=^(?!patchsystem).*$ --perl-regexp --format=oneline
output = trim ${output.stdout}
output_empty = is_empty ${output}
assert ${output_empty} "\nRust repo has commits that weren't properly added to the patch system.\nEither run create-patches, or set the USE_DIRTY_RUST_REPO environment variable."
# Every commit belongs to the patchsystem, re-applying the patches is safe.
# Reset to initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}
exec git reset --hard ${head}
# Apply all patches.
apply_patches
''']
[tasks.create-patches]
script_runner = "@duckscript"
script = [
'''
cd rust
# Get initial commit (which imports the rust tree)
head = exec git rev-list --max-parents=0 HEAD
head = trim ${head.stdout}
# Change committer for the previous patches so they show up as being committed
# by patchsystem.
set_env FILTER_BRANCH_SQUELCH_WARNING 1
exec git update-ref -d refs/original/refs/heads/master
exec git filter-branch --env-filter "export GIT_COMMITTER_NAME=patchsystem; export GIT_COMMITTER_EMAIL=patchsystem" -- ${head}..
# Create patch for every commit after initial commit.
exec git format-patch -o ../rust-patches ${head}..
''']
[tasks.clippy]
dependencies = ["clippy-host-target", "clippy-sunrise-kernel-target", "clippy-sunrise-userspace-target-nostd", "clippy-sunrise-userspace-target-std"]
[tasks.swipc-gen]
description = "Get the output of running gen_ipc on an ipcdef file"
command = "cargo"
args = ["run", "--manifest-path", "swipc-gen/Cargo.toml", "--features=binaries", "--", "${@}"]
[tasks.default]
run_task = "qemu"