Skip to content

Commit a66f820

Browse files
committed
Rust: Vendor 3rdparty dependencies.
We've been observing some performance issues using crate_universe on CI. Therefore, we're moving to vendor the auto-generated BUILD files in our repository. This should provide a nice speed boost, while getting rid of the complexity of the "rust cache" job we've been using when we had a lot of git dependencies. This PR includes a vendor script, and I'll put up a CI job internally that runs that vendor script on Cargo.toml and Cargo.lock changes, to check that the vendored files are in sync.
1 parent 570260b commit a66f820

File tree

339 files changed

+36471
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

339 files changed

+36471
-47
lines changed

.bazelrc

-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ common --registry=file:///%workspace%/misc/bazel/registry
2323
common --registry=https://bcr.bazel.build
2424

2525
common --@rules_dotnet//dotnet/settings:strict_deps=false
26-
common --experimental_isolated_extension_usages
2726

2827
try-import %workspace%/local.bazelrc

.bazelrc.internal

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ common --registry=https://bcr.bazel.build
88
# its implementation packages without providing any code itself.
99
# We either can depend on internal implementation details, or turn of strict deps.
1010
common --@rules_dotnet//dotnet/settings:strict_deps=false
11-
common --experimental_isolated_extension_usages

BUILD.bazel

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
exports_files(["LICENSE"])
1+
exports_files([
2+
"LICENSE",
3+
"Cargo.lock",
4+
"Cargo.toml",
5+
])

MODULE.bazel

+34-31
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,44 @@ bazel_dep(name = "rules_rust", version = "0.52.2")
3131

3232
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
3333

34-
# crate_py but shortened due to Windows file path considerations
35-
cp = use_extension(
36-
"@rules_rust//crate_universe:extension.bzl",
37-
"crate",
38-
isolate = True,
39-
)
40-
cp.from_cargo(
41-
name = "py_deps",
42-
cargo_lockfile = "//python/extractor/tsg-python:Cargo.lock",
43-
manifests = [
44-
"//python/extractor/tsg-python:Cargo.toml",
45-
"//python/extractor/tsg-python/tsp:Cargo.toml",
34+
# Keep edition and version approximately in sync with internal repo.
35+
# the versions there are canonical, the versions here are used for CI in github/codeql, as well as for the vendoring of dependencies.
36+
RUST_EDITION = "2021"
37+
38+
RUST_VERSION = "1.81.0"
39+
40+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
41+
rust.toolchain(
42+
edition = RUST_EDITION,
43+
# We need those extra target triples so that we can build universal binaries on macos
44+
extra_target_triples = [
45+
"x86_64-apple-darwin",
46+
"aarch64-apple-darwin",
4647
],
48+
versions = [RUST_VERSION],
4749
)
48-
use_repo(cp, "py_deps")
50+
use_repo(rust, "rust_toolchains")
4951

50-
# deps for ruby+rust, but shortened due to windows file paths
51-
r = use_extension(
52-
"@rules_rust//crate_universe:extension.bzl",
53-
"crate",
54-
isolate = True,
55-
)
56-
r.from_cargo(
57-
name = "r",
58-
cargo_lockfile = "//:Cargo.lock",
59-
manifests = [
60-
"//:Cargo.toml",
61-
"//ruby/extractor:Cargo.toml",
62-
"//rust/extractor:Cargo.toml",
63-
"//rust/extractor/macros:Cargo.toml",
64-
"//rust/ast-generator:Cargo.toml",
65-
"//shared/tree-sitter-extractor:Cargo.toml",
66-
],
52+
register_toolchains("@rust_toolchains//:all")
53+
54+
rust_host_tools = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")
55+
56+
# Don't download a second toolchain as host toolchain, make sure this is the same version as above
57+
# The host toolchain is used for vendoring dependencies.
58+
rust_host_tools.host_tools(
59+
edition = RUST_EDITION,
60+
version = RUST_VERSION,
6761
)
68-
use_repo(r, tree_sitter_extractors_deps = "r")
62+
63+
# deps for python extractor
64+
# keep in sync by running `misc/bazel/3rdparty/update_cargo_deps.sh`
65+
py_deps = use_extension("//misc/bazel/3rdparty:py_deps_extension.bzl", "p")
66+
use_repo(py_deps, "vendor__anyhow-1.0.44", "vendor__cc-1.0.70", "vendor__clap-2.33.3", "vendor__regex-1.5.5", "vendor__smallvec-1.6.1", "vendor__string-interner-0.12.2", "vendor__thiserror-1.0.29", "vendor__tree-sitter-0.20.4", "vendor__tree-sitter-graph-0.7.0")
67+
68+
# deps for ruby+rust
69+
# keep in sync by running `misc/bazel/3rdparty/update_cargo_deps.sh`
70+
tree_sitter_extractors_deps = use_extension("//misc/bazel/3rdparty:tree_sitter_extractors_extension.bzl", "r")
71+
use_repo(tree_sitter_extractors_deps, "vendor__anyhow-1.0.93", "vendor__argfile-0.2.1", "vendor__chrono-0.4.38", "vendor__clap-4.5.20", "vendor__encoding-0.2.33", "vendor__figment-0.10.19", "vendor__flate2-1.0.34", "vendor__glob-0.3.1", "vendor__globset-0.4.15", "vendor__itertools-0.10.5", "vendor__itertools-0.13.0", "vendor__lazy_static-1.5.0", "vendor__log-0.4.22", "vendor__num-traits-0.2.19", "vendor__num_cpus-1.16.0", "vendor__proc-macro2-1.0.89", "vendor__quote-1.0.37", "vendor__ra_ap_base_db-0.0.232", "vendor__ra_ap_hir-0.0.232", "vendor__ra_ap_hir_def-0.0.232", "vendor__ra_ap_hir_expand-0.0.232", "vendor__ra_ap_ide_db-0.0.232", "vendor__ra_ap_load-cargo-0.0.232", "vendor__ra_ap_parser-0.0.232", "vendor__ra_ap_paths-0.0.232", "vendor__ra_ap_project_model-0.0.232", "vendor__ra_ap_span-0.0.232", "vendor__ra_ap_syntax-0.0.232", "vendor__ra_ap_vfs-0.0.232", "vendor__rand-0.8.5", "vendor__rayon-1.10.0", "vendor__regex-1.11.1", "vendor__serde-1.0.214", "vendor__serde_json-1.0.132", "vendor__serde_with-3.11.0", "vendor__stderrlog-0.6.0", "vendor__syn-2.0.87", "vendor__tracing-0.1.40", "vendor__tracing-subscriber-0.3.18", "vendor__tree-sitter-0.24.4", "vendor__tree-sitter-embedded-template-0.23.2", "vendor__tree-sitter-json-0.24.8", "vendor__tree-sitter-ql-0.23.1", "vendor__tree-sitter-ruby-0.23.1", "vendor__triomphe-0.1.14", "vendor__ungrammar-1.16.1")
6972

7073
dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
7174
dotnet.toolchain(dotnet_version = "8.0.101")

misc/bazel/3rdparty/.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/tree_sitter_extractors_deps/** linguist-generated=true
2+
/py_deps/** linguist-generated=true

misc/bazel/3rdparty/BUILD.bazel

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("@rules_rust//crate_universe:defs.bzl", "crates_vendor")
2+
3+
# The targets in this file re-do the vendoring of the rust cargo dependencies. Use the update_cargo_deps.sh script to run the targets, and do all the necessary work around vendoring.
4+
crates_vendor(
5+
name = "vendor_tree_sitter_extractors",
6+
cargo_lockfile = "//:Cargo.lock",
7+
generate_build_scripts = True,
8+
manifests = [
9+
"//:Cargo.toml",
10+
"//ruby/extractor:Cargo.toml",
11+
"//rust/extractor:Cargo.toml",
12+
"//rust/extractor/macros:Cargo.toml",
13+
"//rust/ast-generator:Cargo.toml",
14+
"//shared/tree-sitter-extractor:Cargo.toml",
15+
],
16+
mode = "remote",
17+
repository_name = "vendor",
18+
tags = ["manual"],
19+
vendor_path = "tree_sitter_extractors_deps",
20+
)
21+
22+
crates_vendor(
23+
name = "vendor_py_deps",
24+
cargo_lockfile = "//python/extractor/tsg-python:Cargo.lock",
25+
generate_build_scripts = True,
26+
manifests = [
27+
"//python/extractor/tsg-python:Cargo.toml",
28+
"//python/extractor/tsg-python/tsp:Cargo.toml",
29+
],
30+
mode = "remote",
31+
repository_name = "vendor",
32+
tags = ["manual"],
33+
vendor_path = "py_deps",
34+
)

misc/bazel/3rdparty/py_deps/BUILD.ahash-0.4.7.bazel

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/bazel/3rdparty/py_deps/BUILD.aho-corasick-0.7.18.bazel

+88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/bazel/3rdparty/py_deps/BUILD.ansi_term-0.11.0.bazel

+93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)