Skip to content

Ruby: Change how we pull in shared/tree-sitter-extractor dependency #16585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024

Conversation

criemen
Copy link
Collaborator

@criemen criemen commented May 24, 2024

Previously, we pulled in the shared tree-sitter extractor via a git dependency in Cargo.toml to address a rules_rust limitation (no path dependencies outside of the cargo workspace)). This was a problem, as that means we're cloning github/codeql again for the build, which is quite slow.

I found another way that is faster, and still produces correct builds for both cargo`` and rules_rust`:

  • Cargo depends on a fake crate that has the same dependencies as the real crate (thanks to sync-files.py). Therefore, cargo pulls in the right dependencies into the lockfile, which bazel targets
  • For local builds, we override the path to that dependency in a cargo config, so we're pulling in the correct code
  • rules_rust only uses path dependencies for collecting transitive dependencies, it never pulls in the code from there. So far that, we manually provide a BUILD.bazel file for the shared extractor, and depend on that.

The git dependency was also a major source of slowdown for the upcoming bzlmod/rules_rust conversion, so we needed to get rid of it for that reason, too.

@criemen criemen force-pushed the criemen/ruby-codeql-extractor-hack branch 2 times, most recently from 2aa4561 to f6a3106 Compare May 24, 2024 10:41
Previously, we pulled in the shared tree-sitter extractor via a `git`
dependency in `Cargo.toml` to address a `rules_rust` limitation (no `path`
dependencies outside of the cargo workspace)). This was a problem,
as that means we're cloning `github/codeql` _again_ for the build, which is
quite slow.

I found another way that is faster, and still produces correct builds
for both `cargo`` and `rules_rust`:
* Cargo depends on a fake crate that has the same dependencies as the real crate (thanks to `sync-files.py`). Therefore, cargo pulls in the right dependencies into the lockfile, which bazel targets
* For local builds, we override the path to that dependency in a cargo config, so we're pulling in the correct code
* rules_rust only uses `path` dependencies for collecting transitive dependencies, it never pulls in the code from there. So far that, we manually provide a `BUILD.bazel` file for the shared extractor, and depend on that.
@criemen criemen force-pushed the criemen/ruby-codeql-extractor-hack branch from f6a3106 to 8c46b61 Compare May 24, 2024 13:39
@criemen criemen marked this pull request as ready for review May 24, 2024 13:42
@criemen criemen requested a review from a team as a code owner May 24, 2024 13:42
@criemen criemen requested a review from redsun82 May 24, 2024 13:42
redsun82
redsun82 previously approved these changes May 24, 2024
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

ingenious!

@criemen
Copy link
Collaborator Author

criemen commented May 24, 2024

Ah, one more note: If this weren't a public repository/windows support wouldn't be a concern, I'd have symlinked the files, or even the project directory, but that then creates problems for people checking out the repo on Windows that don't have symlinks enabled. All our developers need to have those enabled anyways for bazel to work, but external contributors probably haven't, so that's a non-starter.

@criemen criemen force-pushed the criemen/ruby-codeql-extractor-hack branch from 23b7645 to 6c88b95 Compare May 24, 2024 14:07
We've removed cross from the internal build when converting to bazel,
mirror that here.
@criemen criemen force-pushed the criemen/ruby-codeql-extractor-hack branch from 6c88b95 to b09f3c1 Compare May 24, 2024 14:17

[patch.crates-io]
tree-sitter = {git = "https://github.com/redsun82/tree-sitter.git", rev = "1f5c1112ceaa8fc6aff61d1852690407670d2a96"}
tree-sitter = { git = "https://github.com/redsun82/tree-sitter.git", rev = "1f5c1112ceaa8fc6aff61d1852690407670d2a96" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have our own fork of tree-sitter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's unrelated to this PR, and is I believe no longer necessary:
tree-sitter/tree-sitter#3352 was merged (which broke our build otherwise), and we're now waiting on tree-sitter cutting a new release for us to pull in that fix via crates.io instead of git.

@criemen criemen merged commit 44f666c into main May 27, 2024
35 checks passed
@criemen criemen deleted the criemen/ruby-codeql-extractor-hack branch May 27, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants