forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This target creates ${objtree}/rust-project.json which can be read by rust-analyzer to help with autocompletion for the kernel crate. The raw bindings do not work yet, as rust-analyzer seems to have a problem with the include macro. Signed-off-by: Finn Behrens <me@kloenk.de>
- Loading branch information
Showing
5 changed files
with
108 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env bash | ||
|
||
srctree=$1 | ||
objtree=$2 | ||
lib_src=$3 | ||
bindgen_file=$4 | ||
|
||
|
||
# TODO: create issue at RA to accept @arg file | ||
function generate_cfgs() { | ||
echo '[' | ||
cfgs=$(cat $objtree/include/generated/rustc_cfg | sed 's/--cfg=//' | sed 's/"/\\"/g' | sed 's/$/",/' | sed 's/^/"/') | ||
echo ${cfgs::-1} | ||
echo ']' | ||
} | ||
|
||
function generate_crate() { | ||
name=$1 | ||
module=$2 | ||
member=${3:-"true"} | ||
cfg=${4:-$(generate_cfgs)} | ||
deps=${5:-'[{"crate":0,"name":"core"},{"crate":2,"name":"alloc"},{"crate":4,"name":"kernel"}]'} | ||
extra=${CRATE_EXTRA:-""} | ||
|
||
echo "{ | ||
\"display_name\":\"$name\", | ||
\"root_module\":\"$module\", | ||
\"edition\":\"2018\", | ||
\"deps\":$deps, | ||
\"is_workspace_member\": $member, | ||
\"cfg\": $cfg, | ||
\"env\": { | ||
\"RUST_BINDINGS_FILE\": \"$bindgen_file\", | ||
\"RUST_MODFILE\": \"This is only for rust-analyzer\" | ||
} | ||
$extra | ||
}" | ||
} | ||
|
||
function generate_kernel() { | ||
generate_crate "core" "${lib_src}/core/src/lib.rs" "false" "[]" "[]" | ||
echo "," | ||
generate_crate "compiler_builtins" "${srctree}/rust/compiler_builtins.rs" "true" "[]" "[]" | ||
echo "," | ||
generate_crate "alloc" "${lib_src}/alloc/src/lib.rs" "false" "[]" \ | ||
'[{"crate":0,"name":"core"},{"crate":1,"name":"compiler_builtins"}]' | ||
echo "," | ||
echo '{ | ||
"display_name":"module", | ||
"root_module":"'${srctree}'/rust/module.rs", | ||
"edition":"2018", | ||
"is_workspace_member":true, | ||
"deps": [], | ||
"proc_macro_dylib_path": "rust/libmodule.so", | ||
"cfg": [] | ||
},' | ||
generate_crate "kernel" "${srctree}/rust/kernel/lib.rs" "true" "$(generate_cfgs)" \ | ||
'[{"crate":0,"name":"core"},{"crate":2,"name":"alloc"},{"crate":3,"name":"module"}]' | ||
echo "," | ||
} | ||
|
||
function check_and_generate() { | ||
filepath=$1 | ||
file=$(basename $filepath) | ||
makefile=$(dirname $filepath)/Makefile | ||
name=${file%.rs} | ||
objname=${name}.o | ||
echo "checking $filepath" >&2 | ||
if grep -q $objname $makefile; then | ||
echo "building crate $name" >&2 | ||
echo $(generate_crate "$name" "$filepath") | ||
echo "," | ||
fi | ||
} | ||
|
||
function generate_drivers() { | ||
drivers=$(find "$srctree/drivers" -name '*.rs') | ||
for x in $drivers; do | ||
check_and_generate $x | ||
done | ||
echo "" | ||
} | ||
|
||
function generate_samples() { | ||
samples=$(find "$srctree/samples/rust" -name '*.rs') | ||
for x in $samples; do | ||
check_and_generate $x | ||
done | ||
} | ||
|
||
echo '{"crates":[' | ||
generate_kernel | ||
generate_drivers | ||
samples=$(generate_samples) | ||
echo ${samples::-1} | ||
echo '], | ||
"sysroot_src": "'${lib_src}'"}' |