Skip to content

Commit 7fa0c7e

Browse files
Merge branch 'main' into patrick/bazel9
2 parents eebf21e + 07634cc commit 7fa0c7e

8 files changed

Lines changed: 80 additions & 4 deletions

File tree

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
**/cargo-bazel-lock.json linguist-generated
33
crate_universe/3rdparty/crates/** linguist-generated
44
crate_universe/test_data/metadata/*/metadata.json linguist-generated
5-
examples/bzlmod/hello_world/third-party/crates/** linguist-generated
5+
examples/hello_world/third-party/crates/** linguist-generated
66
examples/crate_universe_unnamed/vendor_remote_manifests/crates/** linguist-generated
77
examples/crate_universe_unnamed/vendor_remote_pkgs/crates/** linguist-generated
88
examples/crate_universe/vendor_external/crates/** linguist-generated

crate_universe/extensions.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ For more details about repin, [please refer to the documentation](https://bazelb
144144
In cases where Rust targets have heavy interactions with other Bazel targets ([Cc](https://docs.bazel.build/versions/main/be/c-cpp.html), [Proto](https://rules-proto-grpc.com/en/4.5.0/lang/rust.html),
145145
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
146146
begin to be confused about missing targets or environment variables defined only in Bazel.
147-
In situations like this, it may be desirable to have a "Cargo free" setup. You find an example in the in the [example folder](https://github.com/bazelbuild/rules_rust/examples/bzlmod/hello_world_no_cargo).
147+
In situations like this, it may be desirable to have a "Cargo free" setup. You find an example in the in the [example folder](https://github.com/bazelbuild/rules_rust/tree/main/examples/hello_world_no_cargo).
148148
149149
crates_repository supports this through the packages attribute,
150150
as shown below.
@@ -227,7 +227,7 @@ Only a cargo workspace needs updating whenever the underlying Cargo.toml file ch
227227
In some cases, it is require that all external dependencies are vendored, meaning downloaded
228228
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,
229229
or to ensure full build reproducibility since no download error could possibly occur.
230-
You find a complete example in the in the [example folder](https://github.com/bazelbuild/rules_rust/examples/bzlmod/all_deps_vendor).
230+
You find a complete example in the in the [example folder](https://github.com/bazelbuild/rules_rust/tree/main/examples/all_deps_vendor).
231231
232232
For the setup, you need to add the skylib in addition to the rust rules to your `MODULE.bazel`.
233233
@@ -367,7 +367,7 @@ sys_deps()
367367
368368
Now, you can build the project as usual.
369369
370-
There are some more examples of using crate_universe with bzlmod in the [example folder](https://github.com/bazelbuild/rules_rust/blob/main/examples/bzlmod/).
370+
There are some more examples of using crate_universe with bzlmod in the [example folder](https://github.com/bazelbuild/rules_rust/blob/main/examples/).
371371
372372
"""
373373

tools/rust_analyzer/3rdparty/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ load("//crate_universe:defs.bzl", "crate", "crates_vendor")
33

44
crates_vendor(
55
name = "crates_vendor",
6+
annotations = {
7+
"io-lifetimes": [
8+
crate.annotation(
9+
patches = ["@rules_rust//tools/rust_analyzer/3rdparty/patches:io-lifetimes-determinism.patch"],
10+
),
11+
],
12+
"rustix": [
13+
crate.annotation(
14+
patches = ["@rules_rust//tools/rust_analyzer/3rdparty/patches:rustix-determinism.patch"],
15+
),
16+
],
17+
},
618
cargo_lockfile = "Cargo.Bazel.lock",
719
mode = "remote",
820
packages = {

tools/rust_analyzer/3rdparty/crates/defs.bzl

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports_files(glob(include = ["*.patch"]))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Crate Patches
2+
3+
Patches in this folder are used for patching crates in `../crates`, e.g. to fix non deterministic behavior.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git build.rs build.rs
2+
index 2fc2a38..5a01d04 100644
3+
--- build.rs
4+
+++ build.rs
5+
@@ -43,7 +43,6 @@ fn has_feature(feature: &str) -> bool {
6+
fn can_compile<T: AsRef<str>>(test: T) -> bool {
7+
use std::process::Stdio;
8+
9+
- let out_dir = var("OUT_DIR").unwrap();
10+
let rustc = var("RUSTC").unwrap();
11+
let target = var("TARGET").unwrap();
12+
13+
@@ -68,7 +67,7 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
14+
.arg("--target")
15+
.arg(target)
16+
.arg("--out-dir")
17+
- .arg(out_dir); // Put the output somewhere inconsequential.
18+
+ .arg("/dev/null"); // Put the output somewhere inconsequential to avoid non-determinism.
19+
20+
// If Cargo wants to set RUSTFLAGS, use that.
21+
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
diff --git build.rs build.rs
2+
index 320b3052..611bd280 100644
3+
--- build.rs
4+
+++ build.rs
5+
@@ -86,7 +86,10 @@ fn main() {
6+
// x86 our asm support requires naked functions. On PowerPC and MIPS,
7+
// Rust's inline asm is considered experimental, so only use it if
8+
// `--cfg=rustix_use_experimental_asm` is given.
9+
- if (feature_rustc_dep_of_std || vendor == "mustang" || can_compile("use std::arch::asm;"))
10+
+ // Note: On x86_64 linux, assume asm is available (any rustc >= 1.59 supports it)
11+
+ // to avoid non-deterministic probe compilation.
12+
+ let has_asm = arch == "x86_64" || feature_rustc_dep_of_std || vendor == "mustang" || can_compile("use std::arch::asm;");
13+
+ if has_asm
14+
&& (arch != "x86" || has_feature("naked_functions"))
15+
&& ((arch != "powerpc64" && arch != "mips" && arch != "mips64")
16+
|| rustix_use_experimental_asm)
17+
@@ -242,7 +245,6 @@ fn has_feature(feature: &str) -> bool {
18+
fn can_compile<T: AsRef<str>>(test: T) -> bool {
19+
use std::process::Stdio;
20+
21+
- let out_dir = var("OUT_DIR").unwrap();
22+
let rustc = var("RUSTC").unwrap();
23+
let target = var("TARGET").unwrap();
24+
25+
@@ -267,7 +269,7 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
26+
.arg("--target")
27+
.arg(target)
28+
.arg("--out-dir")
29+
- .arg(out_dir); // Put the output somewhere inconsequential.
30+
+ .arg("/dev/null"); // Put the output somewhere inconsequential.
31+
32+
// If Cargo wants to set RUSTFLAGS, use that.
33+
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {

0 commit comments

Comments
 (0)