Bug 1822324 [wpt PR 38989] - Improve interaction of pointer-events with scroll gestur...
[gecko.git] / build / build-rust / cargo-vendor-std.patch
blob74e059b810580bfcc60477456ee99d32416d13bb
1 Teaches Cargo to source all std dependencies from vendored sources in the rust-src
2 component, making -Zbuild-std compatible with vendored builds.
4 This was originally landed in https://github.com/rust-lang/cargo/pull/8834
5 but was backed out for causing breakage in other situations. It works fine
6 for Firefox's usecase, though.
8 Most of these changes just add/edit tests for the functionality. Only the
9 change to src/cargo/core/compiler/standard_lib.rs is important.
11 diff --git a/src/cargo/core/compiler/standard_lib.rs b/src/cargo/core/compiler/standard_lib.rs
12 index e0baebd51..547b84147 100644
13 --- a/src/cargo/core/compiler/standard_lib.rs
14 +++ b/src/cargo/core/compiler/standard_lib.rs
15 @@ -12,6 +12,7 @@ use crate::util::errors::CargoResult;
16 use crate::Config;
17 use std::collections::{HashMap, HashSet};
18 use std::env;
19 +use std::fs;
20 use std::path::PathBuf;
22 use super::BuildConfig;
23 @@ -74,27 +75,45 @@ pub fn resolve_std<'cfg>(
26 let src_path = detect_sysroot_src_path(target_data)?;
27 - let to_patch = [
28 - "rustc-std-workspace-core",
29 - "rustc-std-workspace-alloc",
30 - "rustc-std-workspace-std",
31 - ];
32 - let patches = to_patch
33 - .iter()
34 - .map(|&name| {
35 - let source_path = SourceId::for_path(&src_path.join("library").join(name))?;
36 - let dep = Dependency::parse(name, None, source_path)?;
38 + // Special std packages should be pulled from `library/` and should be
39 + // prefixed with `rustc-std-workspace-` in certain places.
40 + let libs_prefix = "library/";
41 + let special_std_prefix = "rustc-std-workspace-";
42 + let libs_path = src_path.join(libs_prefix);
44 + // Crates in rust-src to build. libtest is in some sense the "root" package
45 + // of std, as nothing else depends on it, so it must be explicitly added.
46 + let mut members = vec![format!("{}test", libs_prefix)];
48 + // If rust-src contains a "vendor" directory, then patch in all the crates it contains.
49 + let vendor_path = src_path.join("vendor");
50 + let vendor_dir = fs::read_dir(vendor_path)?;
51 + let patches = vendor_dir
52 + .into_iter()
53 + .map(|entry| {
54 + let entry = entry?;
55 + let name = entry
56 + .file_name()
57 + .into_string()
58 + .map_err(|_| anyhow::anyhow!("package name wasn't utf8"))?;
60 + // Remap the rustc-std-workspace crates to the actual rust-src libraries
61 + let path = if let Some(real_name) = name.strip_prefix(special_std_prefix) {
62 + // Record this crate as something to build in the workspace
63 + members.push(format!("{}{}", libs_prefix, real_name));
64 + libs_path.join(&name)
65 + } else {
66 + entry.path()
67 + };
68 + let source_path = SourceId::for_path(&path)?;
69 + let dep = Dependency::parse(&name, None, source_path)?;
70 Ok(dep)
72 .collect::<CargoResult<Vec<_>>>()?;
74 let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
75 let patch = HashMap::from([(crates_io_url, patches)]);
76 - let members = vec![
77 - String::from("library/std"),
78 - String::from("library/core"),
79 - String::from("library/alloc"),
80 - String::from("library/test"),
81 - ];
82 let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
83 &src_path,
84 &Some(members),
85 diff --git a/tests/testsuite/mock-std/library/test/Cargo.toml b/tests/testsuite/mock-std/library/test/Cargo.toml
86 index 299db7bfd..eb81bbf5e 100644
87 --- a/tests/testsuite/mock-std/library/test/Cargo.toml
88 +++ b/tests/testsuite/mock-std/library/test/Cargo.toml
89 @@ -10,6 +10,7 @@ std = { path = "../std" }
90 panic_unwind = { path = "../panic_unwind" }
91 compiler_builtins = { path = "../compiler_builtins" }
92 registry-dep-using-std = { version = "*", features = ['mockbuild'] }
93 +registry-dep-only-used-by-test = { version = "*" }
95 [features]
96 panic-unwind = []
97 diff --git a/tests/testsuite/mock-std/library/test/src/lib.rs b/tests/testsuite/mock-std/library/test/src/lib.rs
98 index a112855f5..224b89bb2 100644
99 --- a/tests/testsuite/mock-std/library/test/src/lib.rs
100 +++ b/tests/testsuite/mock-std/library/test/src/lib.rs
101 @@ -7,4 +7,5 @@ extern crate test;
102 pub use test::*;
104 pub fn custom_api() {
105 + registry_dep_only_used_by_test::wow_testing_is_so_easy();
107 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/Cargo.toml b/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/Cargo.toml
108 new file mode 100644
109 index 000000000..31ba65a98
110 --- /dev/null
111 +++ b/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/Cargo.toml
112 @@ -0,0 +1,9 @@
113 +[package]
114 +name = "registry-dep-only-used-by-test"
115 +version = "1.0.0"
116 +authors = ["Alex Crichton <alex@alexcrichton.com>"]
117 +edition = "2018"
119 +[dependencies]
121 +[features]
122 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/src/lib.rs b/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/src/lib.rs
123 new file mode 100644
124 index 000000000..a68d2aeef
125 --- /dev/null
126 +++ b/tests/testsuite/mock-std/vendor/registry-dep-only-used-by-test/src/lib.rs
127 @@ -0,0 +1,2 @@
128 +pub fn wow_testing_is_so_easy() {
130 \ No newline at end of file
131 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/Cargo.toml b/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/Cargo.toml
132 new file mode 100644
133 index 000000000..f7e4ab232
134 --- /dev/null
135 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/Cargo.toml
136 @@ -0,0 +1,12 @@
137 +[package]
138 +name = "registry-dep-using-alloc"
139 +version = "1.0.0"
140 +authors = ["Alex Crichton <alex@alexcrichton.com>"]
141 +edition = "2018"
143 +[dependencies]
144 +rustc-std-workspace-alloc = { version = "*", optional = true }
145 +rustc-std-workspace-core = { version = "*", optional = true }
147 +[features]
148 +mockbuild = ["rustc-std-workspace-alloc", "rustc-std-workspace-core"]
149 \ No newline at end of file
150 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/src/lib.rs b/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/src/lib.rs
151 new file mode 100644
152 index 000000000..b9ab30339
153 --- /dev/null
154 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-alloc/src/lib.rs
155 @@ -0,0 +1,9 @@
156 +#[cfg(feature = "mockbuild")]
157 +pub fn custom_api() {
160 +#[cfg(not(feature = "mockbuild"))]
161 +pub fn non_sysroot_api() {
162 + core::custom_api();
163 + alloc::custom_api();
165 \ No newline at end of file
166 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-core/Cargo.toml b/tests/testsuite/mock-std/vendor/registry-dep-using-core/Cargo.toml
167 new file mode 100644
168 index 000000000..befb83a63
169 --- /dev/null
170 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-core/Cargo.toml
171 @@ -0,0 +1,11 @@
172 +[package]
173 +name = "registry-dep-using-core"
174 +version = "1.0.0"
175 +authors = ["Alex Crichton <alex@alexcrichton.com>"]
176 +edition = "2018"
178 +[dependencies]
179 +rustc-std-workspace-core = { version = "*", optional = true }
181 +[features]
182 +mockbuild = ["rustc-std-workspace-core"]
183 \ No newline at end of file
184 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-core/src/lib.rs b/tests/testsuite/mock-std/vendor/registry-dep-using-core/src/lib.rs
185 new file mode 100644
186 index 000000000..f9dbac0f4
187 --- /dev/null
188 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-core/src/lib.rs
189 @@ -0,0 +1,8 @@
190 +#[cfg(feature = "mockbuild")]
191 +pub fn custom_api() {
194 +#[cfg(not(feature = "mockbuild"))]
195 +pub fn non_sysroot_api() {
196 + core::custom_api();
198 \ No newline at end of file
199 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-std/Cargo.toml b/tests/testsuite/mock-std/vendor/registry-dep-using-std/Cargo.toml
200 new file mode 100644
201 index 000000000..71ef0a42f
202 --- /dev/null
203 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-std/Cargo.toml
204 @@ -0,0 +1,11 @@
205 +[package]
206 +name = "registry-dep-using-std"
207 +version = "1.0.0"
208 +authors = ["Alex Crichton <alex@alexcrichton.com>"]
209 +edition = "2018"
211 +[dependencies]
212 +rustc-std-workspace-std = { version = "*", optional = true }
214 +[features]
215 +mockbuild = ["rustc-std-workspace-std"]
216 \ No newline at end of file
217 diff --git a/tests/testsuite/mock-std/vendor/registry-dep-using-std/src/lib.rs b/tests/testsuite/mock-std/vendor/registry-dep-using-std/src/lib.rs
218 new file mode 100644
219 index 000000000..f3af39178
220 --- /dev/null
221 +++ b/tests/testsuite/mock-std/vendor/registry-dep-using-std/src/lib.rs
222 @@ -0,0 +1,8 @@
223 +#[cfg(feature = "mockbuild")]
224 +pub fn custom_api() {
227 +#[cfg(not(feature = "mockbuild"))]
228 +pub fn non_sysroot_api() {
229 + std::custom_api();
231 \ No newline at end of file
232 diff --git a/tests/testsuite/mock-std/vendor/rustc-std-workspace-alloc/Cargo.toml b/tests/testsuite/mock-std/vendor/rustc-std-workspace-alloc/Cargo.toml
233 new file mode 100644
234 index 000000000..4465a08a8
235 --- /dev/null
236 +++ b/tests/testsuite/mock-std/vendor/rustc-std-workspace-alloc/Cargo.toml
237 @@ -0,0 +1 @@
238 +this file shouldn't be read
239 \ No newline at end of file
240 diff --git a/tests/testsuite/mock-std/vendor/rustc-std-workspace-core/Cargo.toml b/tests/testsuite/mock-std/vendor/rustc-std-workspace-core/Cargo.toml
241 new file mode 100644
242 index 000000000..4465a08a8
243 --- /dev/null
244 +++ b/tests/testsuite/mock-std/vendor/rustc-std-workspace-core/Cargo.toml
245 @@ -0,0 +1 @@
246 +this file shouldn't be read
247 \ No newline at end of file
248 diff --git a/tests/testsuite/mock-std/vendor/rustc-std-workspace-std/Cargo.toml b/tests/testsuite/mock-std/vendor/rustc-std-workspace-std/Cargo.toml
249 new file mode 100644
250 index 000000000..4465a08a8
251 --- /dev/null
252 +++ b/tests/testsuite/mock-std/vendor/rustc-std-workspace-std/Cargo.toml
253 @@ -0,0 +1 @@
254 +this file shouldn't be read
255 \ No newline at end of file
256 diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs
257 index d3be303ea..486a9b4e0 100644
258 --- a/tests/testsuite/standard_lib.rs
259 +++ b/tests/testsuite/standard_lib.rs
260 @@ -15,71 +15,18 @@ struct Setup {
263 fn setup() -> Setup {
264 - // Our mock sysroot requires a few packages from crates.io, so make sure
265 - // they're "published" to crates.io. Also edit their code a bit to make sure
266 - // that they have access to our custom crates with custom apis.
267 + // Register a version of one of the std dependencies that doesn't compile.
268 + // This ensures that the mock-std's vendor is actually being used.
269 Package::new("registry-dep-using-core", "1.0.0")
270 .file(
271 "src/lib.rs",
273 - #![no_std]
275 - #[cfg(feature = \"mockbuild\")]
276 - pub fn custom_api() {
279 - #[cfg(not(feature = \"mockbuild\"))]
280 - pub fn non_sysroot_api() {
281 - core::custom_api();
283 + don't compile me bro!!
286 .add_dep(Dependency::new("rustc-std-workspace-core", "*").optional(true))
287 .feature("mockbuild", &["rustc-std-workspace-core"])
288 .publish();
289 - Package::new("registry-dep-using-alloc", "1.0.0")
290 - .file(
291 - "src/lib.rs",
293 - #![no_std]
295 - extern crate alloc;
297 - #[cfg(feature = \"mockbuild\")]
298 - pub fn custom_api() {
301 - #[cfg(not(feature = \"mockbuild\"))]
302 - pub fn non_sysroot_api() {
303 - core::custom_api();
304 - alloc::custom_api();
306 - ",
308 - .add_dep(Dependency::new("rustc-std-workspace-core", "*").optional(true))
309 - .add_dep(Dependency::new("rustc-std-workspace-alloc", "*").optional(true))
310 - .feature(
311 - "mockbuild",
312 - &["rustc-std-workspace-core", "rustc-std-workspace-alloc"],
314 - .publish();
315 - Package::new("registry-dep-using-std", "1.0.0")
316 - .file(
317 - "src/lib.rs",
319 - #[cfg(feature = \"mockbuild\")]
320 - pub fn custom_api() {
323 - #[cfg(not(feature = \"mockbuild\"))]
324 - pub fn non_sysroot_api() {
325 - std::custom_api();
327 - ",
329 - .add_dep(Dependency::new("rustc-std-workspace-std", "*").optional(true))
330 - .feature("mockbuild", &["rustc-std-workspace-std"])
331 - .publish();
333 let p = ProjectBuilder::new(paths::root().join("rustc-wrapper"))
334 .file(
335 @@ -335,6 +282,81 @@ fn depend_same_as_std() {
336 fn test() {
337 let setup = setup();
339 + // Our mock sysroot requires a few packages from crates.io, so make sure
340 + // they're "published" to crates.io. Also edit their code a bit to make sure
341 + // that they have access to our custom crates with custom apis.
342 + Package::new("registry-dep-using-core", "1.0.0")
343 + .file(
344 + "src/lib.rs",
346 + #![no_std]
348 + #[cfg(feature = \"mockbuild\")]
349 + pub fn custom_api() {
352 + #[cfg(not(feature = \"mockbuild\"))]
353 + pub fn non_sysroot_api() {
354 + core::custom_api();
356 + ",
358 + .add_dep(Dependency::new("rustc-std-workspace-core", "*").optional(true))
359 + .feature("mockbuild", &["rustc-std-workspace-core"])
360 + .publish();
361 + Package::new("registry-dep-using-alloc", "1.0.0")
362 + .file(
363 + "src/lib.rs",
365 + #![no_std]
367 + extern crate alloc;
369 + #[cfg(feature = \"mockbuild\")]
370 + pub fn custom_api() {
373 + #[cfg(not(feature = \"mockbuild\"))]
374 + pub fn non_sysroot_api() {
375 + core::custom_api();
376 + alloc::custom_api();
378 + ",
380 + .add_dep(Dependency::new("rustc-std-workspace-core", "*").optional(true))
381 + .add_dep(Dependency::new("rustc-std-workspace-alloc", "*").optional(true))
382 + .feature(
383 + "mockbuild",
384 + &["rustc-std-workspace-core", "rustc-std-workspace-alloc"],
386 + .publish();
387 + Package::new("registry-dep-using-std", "1.0.0")
388 + .file(
389 + "src/lib.rs",
391 + #[cfg(feature = \"mockbuild\")]
392 + pub fn custom_api() {
395 + #[cfg(not(feature = \"mockbuild\"))]
396 + pub fn non_sysroot_api() {
397 + std::custom_api();
399 + ",
401 + .add_dep(Dependency::new("rustc-std-workspace-std", "*").optional(true))
402 + .feature("mockbuild", &["rustc-std-workspace-std"])
403 + .publish();
404 + Package::new("registry-dep-only-used-by-test", "1.0.0")
405 + .file(
406 + "src/lib.rs",
408 + pub fn wow_testing_is_so_easy() {
410 + ",
412 + .publish();
414 let p = project()
415 .file(
416 "src/lib.rs",