Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ rustc_host_target = $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cu
RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library

rust-analyzer:
$(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) $(RUST_LIB_SRC) $(objtree)/rust/bindings_generated.rs > $(objtree)/rust-project.json
$(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) $(RUST_LIB_SRC) > $(objtree)/rust-project.json

$(objtree)/rust/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
$(objtree)/rust/compiler_builtins.o: $(srctree)/rust/compiler_builtins.rs \
Expand Down
28 changes: 9 additions & 19 deletions scripts/generate_rust_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pathlib
import sys

def generate_crates(srctree, objtree, sysroot_src, bindings_file):
def generate_crates(srctree, objtree, sysroot_src):
# Generate the configuration list.
cfg = []
with open(objtree / "include" / "generated" / "rustc_cfg") as fd:
Expand All @@ -23,12 +23,13 @@ def generate_crates(srctree, objtree, sysroot_src, bindings_file):
crates = []
crates_indexes = {}

def append_crate(display_name, root_module, is_workspace_member, deps, cfg):
def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False):
crates_indexes[display_name] = len(crates)
crates.append({
"display_name": display_name,
"root_module": str(root_module),
"is_workspace_member": is_workspace_member,
"is_proc_macro": is_proc_macro,
"deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
"cfg": cfg,
"edition": "2018",
Expand All @@ -41,52 +42,43 @@ def append_crate(display_name, root_module, is_workspace_member, deps, cfg):
append_crate(
"core",
sysroot_src / "core" / "src" / "lib.rs",
False,
[],
[],
is_workspace_member=False,
)

append_crate(
"compiler_builtins",
srctree / "rust" / "compiler_builtins.rs",
True,
[],
[],
)

append_crate(
"alloc",
srctree / "rust" / "alloc" / "lib.rs",
True,
["core", "compiler_builtins"],
[],
)

append_crate(
"macros",
srctree / "rust" / "macros" / "lib.rs",
True,
[],
[],
is_proc_macro=True,
)
crates[-1]["proc_macro_dylib_path"] = "rust/libmacros.so"

append_crate(
"build_error",
srctree / "rust" / "build_error.rs",
True,
["core", "compiler_builtins"],
[],
)

append_crate(
"kernel",
srctree / "rust" / "kernel" / "lib.rs",
True,
["core", "alloc", "macros", "build_error"],
cfg,
cfg=cfg,
)
crates[-1]["env"]["RUST_BINDINGS_FILE"] = str(bindings_file.resolve(True))
crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True))
crates[-1]["source"] = {
"include_dirs": [
str(srctree / "rust" / "kernel"),
Expand All @@ -111,9 +103,8 @@ def append_crate(display_name, root_module, is_workspace_member, deps, cfg):
append_crate(
name,
path,
True,
["core", "alloc", "kernel"],
cfg,
cfg=cfg,
)

return crates
Expand All @@ -124,7 +115,6 @@ def main():
parser.add_argument("srctree", type=pathlib.Path)
parser.add_argument("objtree", type=pathlib.Path)
parser.add_argument("sysroot_src", type=pathlib.Path)
parser.add_argument("bindings_file", type=pathlib.Path)
args = parser.parse_args()

logging.basicConfig(
Expand All @@ -133,7 +123,7 @@ def main():
)

rust_project = {
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.bindings_file),
"crates": generate_crates(args.srctree, args.objtree, args.sysroot_src),
"sysroot_src": str(args.sysroot_src),
}

Expand Down