2
2
of a crate in the current workspace.
3
3
"""
4
4
5
+ load ("@rules_rust//rust:repositories.bzl" , "load_arbitrary_tool" , "DEFAULT_RUST_VERSION" )
6
+
5
7
def _impl (repository_ctx ):
6
8
# Link cxx repository into @third-party.
7
9
lockfile = repository_ctx .path (repository_ctx .attr .lockfile )
@@ -14,8 +16,27 @@ def _impl(repository_ctx):
14
16
root_lockfile = repository_ctx .path ("workspace/Cargo.lock" )
15
17
_copy_file (repository_ctx , src = vendor_lockfile , dst = root_lockfile )
16
18
17
- # Execute cargo vendor.
18
- cmd = ["cargo" , "vendor" , "--versioned-dirs" , "third-party/vendor" ]
19
+ # Figure out which version of cargo to use.
20
+ if repository_ctx .attr .target_triple :
21
+ target_triple = repository_ctx .attr .target_triple
22
+ elif "mac" in repository_ctx .os .name :
23
+ target_triple = "x86_64-apple-darwin"
24
+ elif "windows" in repository_ctx .os .name :
25
+ target_triple = "x86_64-pc-windows-msvc"
26
+ else :
27
+ target_triple = "x86_64-unknown-linux-gnu"
28
+
29
+ # Download cargo.
30
+ load_arbitrary_tool (
31
+ ctx = repository_ctx ,
32
+ tool_name = "cargo" ,
33
+ tool_subdirectories = ["cargo" ],
34
+ version = repository_ctx .attr .cargo_version ,
35
+ iso_date = repository_ctx .attr .cargo_iso_date ,
36
+ target_triple = target_triple ,
37
+ )
38
+
39
+ cmd = ["{}/bin/cargo" .format (repository_ctx .path ("." )), "vendor" , "--versioned-dirs" , "third-party/vendor" ]
19
40
result = repository_ctx .execute (
20
41
cmd ,
21
42
quiet = True ,
@@ -54,6 +75,16 @@ def _log_cargo_vendor(repository_ctx, result):
54
75
vendor = repository_rule (
55
76
doc = "A rule used to vendor the dependencies of a crate in the current workspace" ,
56
77
attrs = {
78
+ "cargo_version" : attr .string (
79
+ doc = "The version of cargo to use" ,
80
+ default = DEFAULT_RUST_VERSION ,
81
+ ),
82
+ "cargo_iso_date" : attr .string (
83
+ doc = "The date of the tool (or None, if the version is a specific version)" ,
84
+ ),
85
+ "target_triple" : attr .string (
86
+ doc = "The target triple of the cargo binary to download" ,
87
+ ),
57
88
"lockfile" : attr .label (
58
89
doc = "A lockfile providing the set of crates to vendor" ,
59
90
),
0 commit comments