Skip to content

Commit 70e8b66

Browse files
Adjust cargo IDE sync tool to depend on external dependencies via git (#560)
## What is the goal of this PR? As part of the initiative to streamline the Rust developer experience, we aim to commit autogenerated cargo manifests. For them to be usable without Bazel, we add the ability to depend on internal git repositories rather than pointing the dependency via path into the generated cargo workspace. ## What are the changes implemented in this PR? We also merge crates at the same path that have the same name under the assumption that they represent alternative modes of compilation for the same target (i.e., enable different features).
1 parent 33d71e4 commit 70e8b66

File tree

9 files changed

+144
-28
lines changed

9 files changed

+144
-28
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ load("@crates//:defs.bzl", "crate_repositories")
103103
crate_repositories()
104104

105105
###############################################
106-
# Create @typedb_dependencies_workspace_refs #
106+
# Create @typedb_dependencies_workspace_refs #
107107
###############################################
108108

109109
load("@typedb_bazel_distribution//common:rules.bzl", "workspace_refs")

builder/rust/cargo/project_aspect.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ _LIB_ENTRY_POINT = "lib.rs"
2121
CrateInfo = provider(fields = [
2222
"kind", # str
2323
"crate_name", # str
24+
"workspace_name", # str
2425
"crate_path", # str
2526
"version", # str
2627
"features", # List[str]
@@ -81,13 +82,15 @@ def _crate_info(ctx, target):
8182
if tag.startswith("crate-name"):
8283
crate_name = tag.split("=")[1]
8384

85+
workspace_name = target.label.workspace_name
8486
crate_path = target.label.package
8587
deps = _crate_deps(ctx, target)
8688
transitive_deps = _transitive_crate_deps(deps)
8789

8890
return CrateInfo(
8991
kind = ctx.rule.kind,
9092
crate_name = crate_name,
93+
workspace_name = workspace_name,
9194
crate_path = crate_path,
9295
version = getattr(ctx.rule.attr, "version", "0.0.0"),
9396
features = getattr(ctx.rule.attr, "crate_features", []),
@@ -196,6 +199,7 @@ def _get_properties(target, ctx, source_files, crate_info):
196199
properties = {}
197200
properties["name"] = crate_info.crate_name
198201
properties["path"] = crate_info.crate_path
202+
properties["features"] = ",".join(crate_info.features)
199203
properties["target.name"] = target.label.name
200204
properties["type"] = target_type
201205
properties["version"] = crate_info.version
@@ -220,7 +224,7 @@ def _crate_deps_info(target, crate_info):
220224
if _is_universe_crate(dependency):
221225
location = "version={}".format(dependency_info.version)
222226
elif not _is_external_target(target) and _is_external_target(dependency):
223-
location = "path=../{}".format(dependency_info.crate_name)
227+
location = "path=../{};workspace_name={}".format(dependency_info.crate_name, dependency_info.workspace_name)
224228
else:
225229
target_to_root = _package_relative_path_to_root(target.label)
226230
root_to_dep = _package_path_from_root(dependency.label)

tool/ide/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ kt_jvm_library(
2525
"@typedb_bazel_distribution//common/shell",
2626
"@typedb_bazel_distribution//common/util",
2727

28+
"@maven//:com_eclipsesource_minimal_json_minimal_json",
2829
"@maven//:com_electronwill_night_config_core",
2930
"@maven//:com_electronwill_night_config_toml",
3031
"@maven//:info_picocli_picocli",

tool/ide/RustManifestSyncer.kt

Lines changed: 124 additions & 17 deletions
Large diffs are not rendered by default.

tool/ide/test/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ load("@typedb_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
88
rust_library(
99
name = "test-lib",
1010
srcs = ["lib.rs"],
11-
deps = ["@typedb_extern//:a"],
1211
)
1312

1413
checkstyle_test(

tool/ide/test/WORKSPACE

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ load("@typedb_dependencies//tool/common:deps.bzl", typedb_dependencies_tool_mave
5454
load("@typedb_dependencies//library/maven:rules.bzl", "maven")
5555
maven(typedb_dependencies_tool_maven_artifacts)
5656

57-
local_repository(
58-
name = "typedb_extern", # we filter external crates by `@typedb_`!
59-
path = "extern",
60-
)
57+
###############################
58+
# Create @test_workspace_refs #
59+
###############################
60+
61+
# Load //@typedb_bazel_distribution//common
62+
load("@typedb_bazel_distribution//common:deps.bzl", "rules_pkg")
63+
rules_pkg()
64+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
65+
rules_pkg_dependencies()
66+
67+
load("@typedb_bazel_distribution//common:rules.bzl", "workspace_refs")
68+
workspace_refs(name = "test_workspace_refs")

tool/ide/test/lib1/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ load("@typedb_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
99
rust_library(
1010
name = "lib1",
1111
srcs = ["lib.rs"],
12-
deps = ["@typedb_extern//:a", "//lib2:lib2"],
1312
)
1413

1514
rust_test(

tool/ide/test/lib2/tests/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ load("@typedb_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
99
rust_test(
1010
name = "lib2_integration_test",
1111
srcs = ["test.rs"],
12-
deps = ["//lib2:lib2", "@typedb_extern//:b"],
1312
)
1413

1514
checkstyle_test(

tool/ide/test/tool/ide/rust/sync.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
55

6-
7-
bazel run @typedb_dependencies//tool/ide:rust_sync
6+
bazel run @typedb_dependencies//tool/ide:rust_sync -- @test_workspace_refs//:refs.json

0 commit comments

Comments
 (0)