From f9bc97b2a123817b68e8cca28eeb039a5daa1c90 Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Mon, 29 Jul 2024 09:30:06 +0200 Subject: [PATCH] `crate_universe`: Enable modext isolation. This should allow us to build our python and ruby code independently - in particular, we can now do shallow checkouts of one without the other. Previously, the modext introduced cross-dependency. This also reduces the amount of work we do in the crate universe processing for the other language, even though it's unused. This does need renaming the module, as otherwise the generated paths from rules_rust get too long for Windows :( --- .bazelrc | 1 + .bazelrc.internal | 1 + MODULE.bazel | 23 ++++++++++++++----- .../bazel/internal/zipmerge/zipmerge_test.cpp | 2 +- ruby/extractor/BUILD.bazel | 2 +- shared/tree-sitter-extractor/BUILD.bazel | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.bazelrc b/.bazelrc index e2ccb69be902..9abda3e670a0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -24,5 +24,6 @@ common --registry=file:///%workspace%/misc/bazel/registry common --registry=https://bcr.bazel.build common --@rules_dotnet//dotnet/settings:strict_deps=false +common --experimental_isolated_extension_usages try-import %workspace%/local.bazelrc diff --git a/.bazelrc.internal b/.bazelrc.internal index f7718959c9de..dcc8dafa6c7f 100644 --- a/.bazelrc.internal +++ b/.bazelrc.internal @@ -8,3 +8,4 @@ common --registry=https://bcr.bazel.build # its implementation packages without providing any code itself. # We either can depend on internal implementation details, or turn of strict deps. common --@rules_dotnet//dotnet/settings:strict_deps=false +common --experimental_isolated_extension_usages diff --git a/MODULE.bazel b/MODULE.bazel index 3352e004375b..ae3cf7af38e6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,7 @@ module( - name = "codeql", + name = "ql", version = "0.0", + repo_name = "codeql", ) # this points to our internal repository when `codeql` is checked out as a submodule thereof @@ -30,11 +31,13 @@ bazel_dep(name = "rules_rust", version = "0.49.1") bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) -crate = use_extension( +# crate_py but shortened due to Windows file path considerations +cp = use_extension( "@rules_rust//crate_universe:extension.bzl", "crate", + isolate = True, ) -crate.from_cargo( +cp.from_cargo( name = "py_deps", cargo_lockfile = "//python/extractor/tsg-python:Cargo.lock", manifests = [ @@ -42,15 +45,23 @@ crate.from_cargo( "//python/extractor/tsg-python/tsp:Cargo.toml", ], ) -crate.from_cargo( - name = "ruby_deps", +use_repo(cp, "py_deps") + +# crate_ruby, but shortened due to windows file paths +r = use_extension( + "@rules_rust//crate_universe:extension.bzl", + "crate", + isolate = True, +) +r.from_cargo( + name = "rd", cargo_lockfile = "//ruby/extractor:Cargo.lock", manifests = [ "//ruby/extractor:Cargo.toml", "//ruby/extractor/codeql-extractor-fake-crate:Cargo.toml", ], ) -use_repo(crate, "py_deps", "ruby_deps") +use_repo(r, "rd") dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet") dotnet.toolchain(dotnet_version = "8.0.101") diff --git a/misc/bazel/internal/zipmerge/zipmerge_test.cpp b/misc/bazel/internal/zipmerge/zipmerge_test.cpp index ee30b764a6d2..9bee1a79c02f 100644 --- a/misc/bazel/internal/zipmerge/zipmerge_test.cpp +++ b/misc/bazel/internal/zipmerge/zipmerge_test.cpp @@ -75,7 +75,7 @@ std::string get_file(const char* name) { return ret; }(); // this works from both `codeql` and the internal repository - for (auto prefix : {"_main", "codeql~"}) { + for (auto prefix : {"_main", "ql~"}) { auto ret = runfiles->Rlocation(prefix + "/misc/bazel/internal/zipmerge/test-files/"s + name); if (fs::exists(ret)) { return ret; diff --git a/ruby/extractor/BUILD.bazel b/ruby/extractor/BUILD.bazel index e3c2a387af59..bb39608f3fc1 100644 --- a/ruby/extractor/BUILD.bazel +++ b/ruby/extractor/BUILD.bazel @@ -1,4 +1,4 @@ -load("@ruby_deps//:defs.bzl", "aliases", "all_crate_deps") +load("@rd//:defs.bzl", "aliases", "all_crate_deps") load("//misc/bazel:rust.bzl", "codeql_rust_binary") codeql_rust_binary( diff --git a/shared/tree-sitter-extractor/BUILD.bazel b/shared/tree-sitter-extractor/BUILD.bazel index e57a9f47ca13..5d9c4ca1ccf8 100644 --- a/shared/tree-sitter-extractor/BUILD.bazel +++ b/shared/tree-sitter-extractor/BUILD.bazel @@ -1,4 +1,4 @@ -load("@ruby_deps//:defs.bzl", "aliases", "all_crate_deps") +load("@rd//:defs.bzl", "aliases", "all_crate_deps") load("@rules_rust//rust:defs.bzl", "rust_library") package(default_visibility = ["//visibility:public"])