Skip to content

Commit ba49599

Browse files
authored
Remove unnecessary external dependencies (#3088)
Addresses some failures identified in #3077
1 parent 1352e43 commit ba49599

File tree

14 files changed

+2040
-84
lines changed

14 files changed

+2040
-84
lines changed

crate_universe/docs_bzlmod.bzl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ There are some examples of using crate_universe with bzlmod in the [example fold
2525
2626
To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:
2727
28-
```starlark
28+
```python
2929
bazel_dep(name = "rules_rust", version = "0.49.3")
3030
```
3131
@@ -34,7 +34,7 @@ You find the latest version on the [release page](https://github.com/bazelbuild/
3434
3535
After adding `rules_rust` in your MODULE.bazel, set the following to begin using `crate_universe`:
3636
37-
```starlark
37+
```python
3838
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
3939
// # ... Dependencies
4040
use_repo(crate, "crates")
@@ -54,7 +54,7 @@ One of the simpler ways to wire up dependencies would be to first structure your
5454
The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there.
5555
You find a complete example in the in the [example folder](../examples/bzlmod/all_crate_deps).
5656
57-
```starlark
57+
```python
5858
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
5959
6060
crate.from_cargo(
@@ -73,7 +73,7 @@ Since these macros come from the generated repository, the dependencies and alia
7373
they return will automatically update BUILD targets. In your BUILD files,
7474
you use these macros for a Rust library as shown below:
7575
76-
```starlark
76+
```python
7777
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
7878
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
7979
@@ -107,7 +107,7 @@ rust_test(
107107
For a Rust binary that does not depend on any macro, use the following configuration
108108
in your build file:
109109
110-
```starlark
110+
```python
111111
rust_binary(
112112
name = "bin",
113113
srcs = ["src/main.rs"],
@@ -142,7 +142,7 @@ In situations like this, it may be desirable to have a “Cargo free” setup. Y
142142
crates_repository supports this through the packages attribute,
143143
as shown below.
144144
145-
```starlark
145+
```python
146146
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
147147
148148
crate.spec(package = "serde", features = ["derive"], version = "1.0")
@@ -156,7 +156,7 @@ use_repo(crate, "crates")
156156
Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.
157157
In your BUILD files, you use direct dependencies as shown below:
158158
159-
```starlark
159+
```python
160160
rust_binary(
161161
name = "bin",
162162
crate_root = "src/main.rs",
@@ -185,7 +185,7 @@ You find a complete example in the in the [example folder](../examples/bzlmod/al
185185
186186
For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.
187187
188-
```starlark
188+
```python
189189
module(
190190
name = "deps_vendored",
191191
version = "0.0.0"
@@ -230,7 +230,7 @@ but by convention, its either thirdparty or 3rdparty to indicate vendored depend
230230
In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor.
231231
In the example, we vendor a specific version of bzip2.
232232
233-
```starlark
233+
```python
234234
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
235235
236236
crates_vendor(
@@ -284,7 +284,7 @@ that depends on a vendored dependency. You find a list of all available vendored
284284
in the BUILD file of the generated folder: `basic/3rdparty/crates/BUILD.bazel`
285285
You declare a vendored dependency in you target as following:
286286
287-
```starlark
287+
```python
288288
load("@rules_rust//rust:defs.bzl", "rust_binary")
289289
290290
rust_binary(
@@ -298,7 +298,7 @@ Note, the vendored dependency is not yet accessible because you have to define f
298298
how to load the vendored dependencies. For that, you first create a file `sys_deps.bzl`
299299
and add the following content:
300300
301-
```starlark
301+
```python
302302
# rename the default name "crate_repositories" in case you import multiple vendored folders.
303303
load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories")
304304
@@ -314,7 +314,7 @@ just load the vendored dependencies.
314314
In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that.
315315
Instead, you create a new file `WORKSPACE.bzlmod` and add the following content.
316316
317-
```starlark
317+
```python
318318
load("//:sys_deps.bzl", "sys_deps")
319319
sys_deps()
320320
```

docs/src/crate_universe_bzlmod.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ There are some examples of using crate_universe with bzlmod in the [example fold
2626

2727
To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:
2828

29-
```starlark
29+
```python
3030
bazel_dep(name = "rules_rust", version = "0.49.3")
3131
```
3232

@@ -35,7 +35,7 @@ You find the latest version on the [release page](https://github.com/bazelbuild/
3535

3636
After adding `rules_rust` in your MODULE.bazel, set the following to begin using `crate_universe`:
3737

38-
```starlark
38+
```python
3939
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
4040
// # ... Dependencies
4141
use_repo(crate, "crates")
@@ -55,7 +55,7 @@ One of the simpler ways to wire up dependencies would be to first structure your
5555
The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there.
5656
You find a complete example in the in the [example folder](../examples/bzlmod/all_crate_deps).
5757

58-
```starlark
58+
```python
5959
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
6060

6161
crate.from_cargo(
@@ -74,7 +74,7 @@ Since these macros come from the generated repository, the dependencies and alia
7474
they return will automatically update BUILD targets. In your BUILD files,
7575
you use these macros for a Rust library as shown below:
7676

77-
```starlark
77+
```python
7878
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
7979
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
8080

@@ -108,7 +108,7 @@ rust_test(
108108
For a Rust binary that does not depend on any macro, use the following configuration
109109
in your build file:
110110

111-
```starlark
111+
```python
112112
rust_binary(
113113
name = "bin",
114114
srcs = ["src/main.rs"],
@@ -143,7 +143,7 @@ In situations like this, it may be desirable to have a “Cargo free” se
143143
crates_repository supports this through the packages attribute,
144144
as shown below.
145145

146-
```starlark
146+
```python
147147
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
148148

149149
crate.spec(package = "serde", features = ["derive"], version = "1.0")
@@ -157,7 +157,7 @@ use_repo(crate, "crates")
157157
Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.
158158
In your BUILD files, you use direct dependencies as shown below:
159159

160-
```starlark
160+
```python
161161
rust_binary(
162162
name = "bin",
163163
crate_root = "src/main.rs",
@@ -186,7 +186,7 @@ You find a complete example in the in the [example folder](../examples/bzlmod/al
186186

187187
For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.
188188

189-
```starlark
189+
```python
190190
module(
191191
name = "deps_vendored",
192192
version = "0.0.0"
@@ -231,7 +231,7 @@ but by convention, its either thirdparty or 3rdparty to indicate vendored depend
231231
In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor.
232232
In the example, we vendor a specific version of bzip2.
233233

234-
```starlark
234+
```python
235235
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
236236

237237
crates_vendor(
@@ -285,7 +285,7 @@ that depends on a vendored dependency. You find a list of all available vendored
285285
in the BUILD file of the generated folder: `basic/3rdparty/crates/BUILD.bazel`
286286
You declare a vendored dependency in you target as following:
287287

288-
```starlark
288+
```python
289289
load("@rules_rust//rust:defs.bzl", "rust_binary")
290290

291291
rust_binary(
@@ -299,7 +299,7 @@ Note, the vendored dependency is not yet accessible because you have to define f
299299
how to load the vendored dependencies. For that, you first create a file `sys_deps.bzl`
300300
and add the following content:
301301

302-
```starlark
302+
```python
303303
# rename the default name "crate_repositories" in case you import multiple vendored folders.
304304
load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories")
305305

@@ -315,7 +315,7 @@ just load the vendored dependencies.
315315
In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that.
316316
Instead, you create a new file `WORKSPACE.bzlmod` and add the following content.
317317

318-
```starlark
318+
```python
319319
load("//:sys_deps.bzl", "sys_deps")
320320
sys_deps()
321321
```

examples/crate_universe/WORKSPACE.bazel

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -630,31 +630,16 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende
630630
rules_foreign_cc_dependencies()
631631

632632
http_archive(
633-
name = "aspect_bazel_lib",
634-
sha256 = "f5ea76682b209cc0bd90d0f5a3b26d2f7a6a2885f0c5f615e72913f4805dbb0d",
635-
strip_prefix = "bazel-lib-2.5.0",
636-
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz",
637-
)
638-
639-
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")
640-
641-
aspect_bazel_lib_dependencies()
642-
643-
aspect_bazel_lib_register_toolchains()
644-
645-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
646-
647-
git_repository(
648633
name = "boringssl",
649-
commit = "44b3df6f03d85c901767250329c571db405122d5",
650634
patch_args = ["-p1"],
651635
patches = [
652636
"//complicated_dependencies:boringssl-filegroup.patch",
653637
# On the macOS bazelci builders, there's a system-installed openssl, and that takes priority over -isystem flags, which is what cc_library.includes uses.
654638
# This forces our local system-includes to be chosen with higher priority, which avoids conflicts.
655639
"//complicated_dependencies:boringssl-system-includes.patch",
656640
],
657-
remote = "https://github.com/google/boringssl.git",
641+
strip_prefix = "boringssl-44b3df6f03d85c901767250329c571db405122d5",
642+
urls = ["https://github.com/google/boringssl/archive/44b3df6f03d85c901767250329c571db405122d5.zip"],
658643
)
659644

660645
crates_repository(

examples/crate_universe/complicated_dependencies/BUILD.bazel

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
21
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("@rules_rust//rust:defs.bzl", "rust_binary")
3+
load(":boringssl_utils.bzl", "boringssl_build_script_dir")
4+
5+
rust_binary(
6+
name = "build_script_dir_maker",
7+
srcs = ["build_script_dir_maker.rs"],
8+
edition = "2021",
9+
)
310

411
# This target lays out the output needed from boringssl in the directory structure needed by the boring-sys build script.
5-
copy_to_directory(
12+
boringssl_build_script_dir(
613
name = "boringssl_gen_dir",
7-
srcs = [
8-
"@boringssl//:crypto",
9-
"@boringssl//:ssl",
10-
],
1114
out = "boringssl_gen_dir_out",
12-
include_external_repositories = ["*"],
13-
replace_prefixes = {
14-
"libcrypto.a": "build/libcrypto.a",
15-
"libssl.a": "build/libssl.a",
16-
},
15+
crypto = "@boringssl//:crypto",
16+
ssl = "@boringssl//:ssl",
1717
visibility = ["//visibility:public"],
1818
)
1919

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""BoringSSL Utils"""
2+
3+
def _boringssl_build_script_dir_impl(ctx):
4+
output = ctx.actions.declare_directory(ctx.attr.out)
5+
6+
ssl = ctx.files.ssl[0]
7+
crypto = ctx.files.crypto[0]
8+
9+
inputs = depset([ssl, crypto])
10+
11+
ctx.actions.run(
12+
executable = ctx.executable._maker,
13+
outputs = [output],
14+
inputs = inputs,
15+
env = {
16+
"ARG_CRYPTO": crypto.path,
17+
"ARG_OUTPUT": output.path,
18+
"ARG_SSL": ssl.path,
19+
},
20+
)
21+
22+
return [DefaultInfo(
23+
files = depset([output]),
24+
runfiles = ctx.runfiles([output]),
25+
)]
26+
27+
boringssl_build_script_dir = rule(
28+
doc = "A utility rule for building directories compatible with its `cargo_build_script` target.",
29+
implementation = _boringssl_build_script_dir_impl,
30+
attrs = {
31+
"crypto": attr.label(
32+
doc = "The `crypto`/`libcrypto` library.",
33+
allow_files = True,
34+
mandatory = True,
35+
),
36+
"out": attr.string(
37+
doc = "The name of the output directory.",
38+
mandatory = True,
39+
),
40+
"ssl": attr.label(
41+
doc = "The `ssl`/`libssl` library.",
42+
allow_files = True,
43+
mandatory = True,
44+
),
45+
"_maker": attr.label(
46+
cfg = "exec",
47+
executable = True,
48+
default = Label("//complicated_dependencies:build_script_dir_maker"),
49+
),
50+
},
51+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! A utility script for the "complicated dependencies" example.
2+
3+
use std::path::PathBuf;
4+
use std::{env, fs};
5+
6+
fn main() {
7+
let ssl = PathBuf::from(env::var("ARG_SSL").unwrap());
8+
let crypto = PathBuf::from(env::var("ARG_CRYPTO").unwrap());
9+
let output = PathBuf::from(env::var("ARG_OUTPUT").unwrap());
10+
11+
let build_dir = output.join("build");
12+
13+
fs::create_dir_all(&build_dir).unwrap();
14+
15+
fs::copy(&ssl, build_dir.join(ssl.file_name().unwrap())).unwrap();
16+
fs::copy(&crypto, build_dir.join(crypto.file_name().unwrap())).unwrap();
17+
}

examples/musl_cross_compiling/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary")
21
load("@bazel_skylib//rules:build_test.bzl", "build_test")
32
load("@rules_rust//rust:defs.bzl", "rust_binary")
43
load("@rules_shell//shell:sh_test.bzl", "sh_test")
4+
load(":musl_utils.bzl", "platform_transition_binary")
55

66
rust_binary(
77
name = "hello",
@@ -12,7 +12,7 @@ rust_binary(
1212
platform_transition_binary(
1313
name = "hello_linux_x86_64_musl",
1414
binary = ":hello",
15-
target_platform = "//platforms:linux_x86_64_musl",
15+
platform = "//platforms:linux_x86_64_musl",
1616
)
1717

1818
sh_test(
@@ -28,7 +28,7 @@ sh_test(
2828
platform_transition_binary(
2929
name = "hello_linux_arm64_musl",
3030
binary = ":hello",
31-
target_platform = "//platforms:linux_arm64_musl",
31+
platform = "//platforms:linux_arm64_musl",
3232
)
3333

3434
sh_test(
@@ -51,7 +51,7 @@ rust_binary(
5151
platform_transition_binary(
5252
name = "keyring_linux_x86_64_musl",
5353
binary = ":keyring",
54-
target_platform = "//platforms:linux_x86_64_musl",
54+
platform = "//platforms:linux_x86_64_musl",
5555
)
5656

5757
build_test(

0 commit comments

Comments
 (0)