Skip to content

Conversation

wittrock
Copy link
Contributor

Many projects using Rust with complicated build systems use rust-project.json to tell rust-analyzer about their source files. We can transform rust-project.json into a .kzip pretty trivially, without needing build system integration. This is simpler than integrating an extractor into every possible build system which large Rust projects use.

Add an extractor called rust_project_to_kzip which takes in a rust-project.json and outputs a .kzip. This kzip will have one CompilationUnit per Rust crate, and each CompilationUnit will include a copy of rust-project.json for the Kythe Rust indexer.

This extractor doesn't yet extract non-.rs files or the stdlib.

Test: added unit tests
Fixes #6167

Copy link
Contributor

@sam-mccall sam-mccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks John, and sorry about the delay. Easter and then I got sick...

My main high-level comments are:

  • aggregating transitive sets of source dirs into a data structure, far away from where it's used, seems unnecessary (and I think gets exclude dirs wrong)
  • I think passing the input rust-project.json through unmodified for every CU is a bit magic/risky, and would rather we synthesized one per CU that (explicitly) drops unused crates and (implicitly) drops unknown fields

Otherwise the approach looks sound to me, and I'll try it out with some existing projects.

(I haven't tried yet as I'm pretty sure e.g. the absence of implicit include of the root_module dir means things will not work with the rust-project.json generators I've been using)

Copy link
Contributor Author

@wittrock wittrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I've addressed all your comments, but I've also broken the indexing pipeline somehow: my kzips look correct but the decorations service returns no decorations for expected source files.

I'll continue to dig into that on Monday. It's likely some misconfiguration on my end.

os.Exit(1)
}

project_json_digest, err := kzip_writer.AddFile(bytes.NewReader(buf.Bytes()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually thought you wanted the entire rust-project.json in each CU! So that's good to know.

I've added synthesizeProjectJson which creates a custom rust-project.json for each CU. Please let me know if you see issues with it!

Copy link
Contributor

@sam-mccall sam-mccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LG with a few comments - most of these are minor/style and optional, up to you how to resolve.

let's do one more pass & then I'll merge

@wittrock
Copy link
Contributor Author

Thanks! All comments resolved, I'm going to make sure the pipeline works before we merge.

@wittrock wittrock force-pushed the master branch 2 times, most recently from 17932df to d88554e Compare April 28, 2025 20:24
@wittrock
Copy link
Contributor Author

I've confirmed that I've got decorations back for my Fuchsia pipeline. It turned out to be three separate bugs. If you're happy, let's merge!

Copy link
Contributor

@sam-mccall sam-mccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it!

@sam-mccall
Copy link
Contributor

/gcbrun

@sam-mccall
Copy link
Contributor

/gcbrun

Many projects using Rust with complicated build systems use
rust-project.json to tell rust-analyzer about their source files. We
can transform rust-project.json into a .kzip pretty trivially, without
needing build system integration. This is simpler than integrating an
extractor into every possible build system which large Rust projects
use.

Add an extractor called rust_project_to_kzip which takes in a
rust-project.json and outputs a .kzip. This kzip will have one
CompilationUnit per Rust crate, and each CompilationUnit will include
a copy of rust-project.json for the Kythe Rust indexer.

This extractor doesn't yet extract non-.rs files or the stdlib.

Test: added unit tests
Fixes kythe#6167
@sam-mccall
Copy link
Contributor

/gcbpush

@sam-mccall
Copy link
Contributor

/gcbrun

@sam-mccall sam-mccall merged commit 383ee9b into kythe:master Apr 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a Rust extractor for rust-project.json files
2 participants