-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjustfile
94 lines (79 loc) · 2.49 KB
/
justfile
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
set dotenv-load := true
KERNELDIR := env_var("KERNELDIR")
LLVM := env_var("LLVM")
KERNEL_MODULES := "current proc_iter mem_layout bsa kmalloc_box"
DEFAULT_MODULE := "all"
default:
@just --list
vars:
echo "KERNELDIR={{KERNELDIR}}"
echo "LLVM={{LLVM}}"
fmt:
rustfmt */*.rs
build module=DEFAULT_MODULE:
#!/usr/bin/env zx
const kernelModules = "{{module}}" === "all" ? "{{KERNEL_MODULES}}" : "{{module}}";
const kernelDir = "../{{KERNELDIR}}";
const llvmParam = "{{LLVM}}";
for (const moduleName of kernelModules.split(" ")) {
await cd(`./${moduleName}`);
await $`make KRUSTFLAGS="--color=always" KERNELDIR=${kernelDir} LLVM=${llvmParam} modules`;
}
clean module=DEFAULT_MODULE:
#!/usr/bin/env zx
const kernelModules = "{{module}}" === "all" ? "{{KERNEL_MODULES}}" : "{{module}}";
const kernelDir = "../{{KERNELDIR}}";
const llvmParam = "{{LLVM}}";
for (const moduleName of kernelModules.split(" ")) {
await cd(`./${moduleName}`);
await $`make KERNELDIR=${kernelDir} LLVM=${llvmParam} clean`;
}
create module:
#!/usr/bin/env zx
const moduleDir = "{{module}}";
await $`cp -r ./mod_template ${moduleDir}`;
await $`sed -i 's/mod_template/${moduleDir}/g' ./${moduleDir}/Makefile`;
await $`sed -i 's/mod_template/${moduleDir}/g' ./${moduleDir}/main.rs`;
const moduleName = moduleDir.split("_").map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1)
}).join("");
await $`sed -i 's/ModTemplate/${moduleName}/g' ./${moduleDir}/main.rs`;
// TODO: rust-analyzer generation
// TODO: add to KERNEL_MODULES variable
rust-analyzer:
#!/usr/bin/env zx
const kernelDir = "{{KERNELDIR}}"
const kernelModules = "{{KERNEL_MODULES}}".split(" ");
const analyzerPath = "./rust-project.json";
const analyzerObj = {
crates: [
{
display_name: "kernel",
root_module: `${kernelDir}/rust/kernel/lib.rs`,
edition: "2018",
deps: []
},
{
display_name: "alloc",
root_module: `${kernelDir}/rust/alloc/lib.rs`,
edition: "2018",
deps: []
},
]
};
function addKernelModule(kernelModuleName) {
const kernelModuleCrate = {
display_name: kernelModuleName,
root_module: `./${kernelModuleName}/main.rs`,
edition: "2018",
deps: [{ crate: 0, name: "kernel" }, { crate: 1, name: "alloc" }]
};
analyzerObj.crates.push(kernelModuleCrate);
}
for (const kernelModule of kernelModules) {
addKernelModule(kernelModule);
}
if (fs.existsSync(analyzerPath)) {
fs.removeSync(analyzerPath);
}
fs.writeFileSync(analyzerPath, JSON.stringify(analyzerObj, null, 2));