Skip to content

Commit 0a456cf

Browse files
committed
Drop support for stitched sysroot
1 parent 482fbb4 commit 0a456cf

File tree

7 files changed

+12
-1168
lines changed

7 files changed

+12
-1168
lines changed

crates/project-model/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ fn parse_cfg(s: &str) -> Result<cfg::CfgAtom, String> {
263263
pub enum RustSourceWorkspaceConfig {
264264
CargoMetadata(CargoMetadataConfig),
265265
Json(ProjectJson),
266-
Stitched,
267266
}
268267

269268
impl Default for RustSourceWorkspaceConfig {

crates/project-model/src/sysroot.rs

+2-134
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44
//! but we can't process `.rlib` and need source code instead. The source code
55
//! is typically installed with `rustup component add rust-src` command.
66
7-
use std::{
8-
env, fs,
9-
ops::{self, Not},
10-
path::Path,
11-
process::Command,
12-
};
7+
use std::{env, fs, ops::Not, path::Path, process::Command};
138

149
use anyhow::{format_err, Result};
15-
use base_db::CrateName;
1610
use itertools::Itertools;
17-
use la_arena::{Arena, Idx};
1811
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
1912
use rustc_hash::FxHashMap;
2013
use stdx::format_to;
@@ -37,58 +30,9 @@ pub struct Sysroot {
3730
pub enum RustLibSrcWorkspace {
3831
Workspace(CargoWorkspace),
3932
Json(ProjectJson),
40-
Stitched(Stitched),
4133
Empty,
4234
}
4335

44-
#[derive(Debug, Clone, Eq, PartialEq)]
45-
pub struct Stitched {
46-
crates: Arena<RustLibSrcCrateData>,
47-
}
48-
49-
impl ops::Index<RustLibSrcCrate> for Stitched {
50-
type Output = RustLibSrcCrateData;
51-
fn index(&self, index: RustLibSrcCrate) -> &RustLibSrcCrateData {
52-
&self.crates[index]
53-
}
54-
}
55-
56-
impl Stitched {
57-
pub(crate) fn public_deps(
58-
&self,
59-
) -> impl Iterator<Item = (CrateName, RustLibSrcCrate, bool)> + '_ {
60-
// core is added as a dependency before std in order to
61-
// mimic rustcs dependency order
62-
[("core", true), ("alloc", false), ("std", true), ("test", false)].into_iter().filter_map(
63-
move |(name, prelude)| {
64-
Some((CrateName::new(name).unwrap(), self.by_name(name)?, prelude))
65-
},
66-
)
67-
}
68-
69-
pub(crate) fn proc_macro(&self) -> Option<RustLibSrcCrate> {
70-
self.by_name("proc_macro")
71-
}
72-
73-
pub(crate) fn crates(&self) -> impl ExactSizeIterator<Item = RustLibSrcCrate> + '_ {
74-
self.crates.iter().map(|(id, _data)| id)
75-
}
76-
77-
fn by_name(&self, name: &str) -> Option<RustLibSrcCrate> {
78-
let (id, _data) = self.crates.iter().find(|(_id, data)| data.name == name)?;
79-
Some(id)
80-
}
81-
}
82-
83-
pub(crate) type RustLibSrcCrate = Idx<RustLibSrcCrateData>;
84-
85-
#[derive(Debug, Clone, Eq, PartialEq)]
86-
pub(crate) struct RustLibSrcCrateData {
87-
pub(crate) name: String,
88-
pub(crate) root: ManifestPath,
89-
pub(crate) deps: Vec<RustLibSrcCrate>,
90-
}
91-
9236
impl Sysroot {
9337
pub const fn empty() -> Sysroot {
9438
Sysroot {
@@ -116,7 +60,6 @@ impl Sysroot {
11660
match &self.workspace {
11761
RustLibSrcWorkspace::Workspace(ws) => ws.packages().next().is_none(),
11862
RustLibSrcWorkspace::Json(project_json) => project_json.n_crates() == 0,
119-
RustLibSrcWorkspace::Stitched(stitched) => stitched.crates.is_empty(),
12063
RustLibSrcWorkspace::Empty => true,
12164
}
12265
}
@@ -129,7 +72,6 @@ impl Sysroot {
12972
match &self.workspace {
13073
RustLibSrcWorkspace::Workspace(ws) => ws.packages().count(),
13174
RustLibSrcWorkspace::Json(project_json) => project_json.n_crates(),
132-
RustLibSrcWorkspace::Stitched(c) => c.crates().count(),
13375
RustLibSrcWorkspace::Empty => 0,
13476
}
13577
}
@@ -258,51 +200,8 @@ impl Sysroot {
258200
} else if let RustSourceWorkspaceConfig::Json(project_json) = sysroot_source_config {
259201
return Some(RustLibSrcWorkspace::Json(project_json.clone()));
260202
}
261-
tracing::debug!("Stitching sysroot library: {src_root}");
262-
263-
let mut stitched = Stitched { crates: Arena::default() };
264-
265-
for path in SYSROOT_CRATES.trim().lines() {
266-
let name = path.split('/').last().unwrap();
267-
let root = [format!("{path}/src/lib.rs"), format!("lib{path}/lib.rs")]
268-
.into_iter()
269-
.map(|it| src_root.join(it))
270-
.filter_map(|it| ManifestPath::try_from(it).ok())
271-
.find(|it| fs::metadata(it).is_ok());
272-
273-
if let Some(root) = root {
274-
stitched.crates.alloc(RustLibSrcCrateData {
275-
name: name.into(),
276-
root,
277-
deps: Vec::new(),
278-
});
279-
}
280-
}
281203

282-
if let Some(std) = stitched.by_name("std") {
283-
for dep in STD_DEPS.trim().lines() {
284-
if let Some(dep) = stitched.by_name(dep) {
285-
stitched.crates[std].deps.push(dep)
286-
}
287-
}
288-
}
289-
290-
if let Some(alloc) = stitched.by_name("alloc") {
291-
for dep in ALLOC_DEPS.trim().lines() {
292-
if let Some(dep) = stitched.by_name(dep) {
293-
stitched.crates[alloc].deps.push(dep)
294-
}
295-
}
296-
}
297-
298-
if let Some(proc_macro) = stitched.by_name("proc_macro") {
299-
for dep in PROC_MACRO_DEPS.trim().lines() {
300-
if let Some(dep) = stitched.by_name(dep) {
301-
stitched.crates[proc_macro].deps.push(dep)
302-
}
303-
}
304-
}
305-
Some(RustLibSrcWorkspace::Stitched(stitched))
204+
return None;
306205
}
307206

308207
pub fn set_workspace(&mut self, workspace: RustLibSrcWorkspace) {
@@ -317,7 +216,6 @@ impl Sysroot {
317216
.crates()
318217
.filter_map(|(_, krate)| krate.display_name.clone())
319218
.any(|name| name.canonical_name().as_str() == "core"),
320-
RustLibSrcWorkspace::Stitched(stitched) => stitched.by_name("core").is_some(),
321219
RustLibSrcWorkspace::Empty => true,
322220
};
323221
if !has_core {
@@ -493,33 +391,3 @@ fn get_rust_lib_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
493391
None
494392
}
495393
}
496-
497-
const SYSROOT_CRATES: &str = "
498-
alloc
499-
backtrace
500-
core
501-
panic_abort
502-
panic_unwind
503-
proc_macro
504-
profiler_builtins
505-
std
506-
stdarch/crates/std_detect
507-
test
508-
unwind";
509-
510-
const ALLOC_DEPS: &str = "core";
511-
512-
const STD_DEPS: &str = "
513-
alloc
514-
panic_unwind
515-
panic_abort
516-
core
517-
profiler_builtins
518-
unwind
519-
std_detect
520-
test";
521-
522-
// core is required for our builtin derives to work in the proc_macro lib currently
523-
const PROC_MACRO_DEPS: &str = "
524-
std
525-
core";

crates/project-model/src/tests.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::Deref;
2-
31
use base_db::{CrateGraph, ProcMacroPaths};
42
use cargo_metadata::Metadata;
53
use cfg::{CfgAtom, CfgDiff};
@@ -225,18 +223,6 @@ fn rust_project_cfg_groups() {
225223
check_crate_graph(crate_graph, expect_file!["../test_data/output/rust_project_cfg_groups.txt"]);
226224
}
227225

228-
#[test]
229-
fn rust_project_is_proc_macro_has_proc_macro_dep() {
230-
let (crate_graph, _proc_macros) = load_rust_project("is-proc-macro-project.json");
231-
// Since the project only defines one crate (outside the sysroot crates),
232-
// it should be the one with the biggest Id.
233-
let crate_id = crate_graph.iter().max().unwrap();
234-
let crate_data = &crate_graph[crate_id];
235-
// Assert that the project crate with `is_proc_macro` has a dependency
236-
// on the proc_macro sysroot crate.
237-
crate_data.dependencies.iter().find(|&dep| *dep.name.deref() == sym::proc_macro).unwrap();
238-
}
239-
240226
#[test]
241227
fn crate_graph_dedup_identical() {
242228
let (mut crate_graph, proc_macros) = load_cargo("regex-metadata.json");

crates/project-model/src/workspace.rs

+5-56
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
cargo_workspace::{CargoMetadataConfig, DepKind, PackageData, RustLibSource},
2424
env::{cargo_config_env, inject_cargo_env, inject_cargo_package_env, inject_rustc_tool_env},
2525
project_json::{Crate, CrateArrayIdx},
26-
sysroot::{RustLibSrcCrate, RustLibSrcWorkspace},
26+
sysroot::RustLibSrcWorkspace,
2727
toolchain_info::{rustc_cfg, target_data_layout, target_tuple, version, QueryConfig},
2828
CargoConfig, CargoWorkspace, CfgOverrides, InvocationStrategy, ManifestPath, Package,
2929
ProjectJson, ProjectManifest, RustSourceWorkspaceConfig, Sysroot, TargetData, TargetKind,
@@ -436,7 +436,9 @@ impl ProjectWorkspace {
436436
if let Some(sysroot_project) = sysroot_project {
437437
sysroot.load_workspace(&RustSourceWorkspaceConfig::Json(*sysroot_project))
438438
} else {
439-
sysroot.load_workspace(&RustSourceWorkspaceConfig::Stitched)
439+
sysroot.load_workspace(&RustSourceWorkspaceConfig::CargoMetadata(
440+
sysroot_metadata_config(&config.extra_env, &targets),
441+
))
440442
}
441443
});
442444

@@ -689,7 +691,7 @@ impl ProjectWorkspace {
689691
exclude: krate.exclude.clone(),
690692
})
691693
.collect(),
692-
RustLibSrcWorkspace::Stitched(_) | RustLibSrcWorkspace::Empty => vec![],
694+
RustLibSrcWorkspace::Empty => vec![],
693695
};
694696

695697
r.push(PackageRoot {
@@ -1626,60 +1628,7 @@ fn sysroot_to_crate_graph(
16261628

16271629
extend_crate_graph_with_sysroot(crate_graph, cg, pm)
16281630
}
1629-
RustLibSrcWorkspace::Stitched(stitched) => {
1630-
let cfg_options = Arc::new({
1631-
let mut cfg_options = CfgOptions::default();
1632-
cfg_options.extend(rustc_cfg);
1633-
cfg_options.insert_atom(sym::debug_assertions.clone());
1634-
cfg_options.insert_atom(sym::miri.clone());
1635-
cfg_options
1636-
});
1637-
let sysroot_crates: FxHashMap<RustLibSrcCrate, CrateId> = stitched
1638-
.crates()
1639-
.filter_map(|krate| {
1640-
let file_id = load(&stitched[krate].root)?;
1641-
1642-
let display_name = CrateDisplayName::from_canonical_name(&stitched[krate].name);
1643-
let crate_id = crate_graph.add_crate_root(
1644-
file_id,
1645-
Edition::CURRENT_FIXME,
1646-
Some(display_name),
1647-
None,
1648-
cfg_options.clone(),
1649-
None,
1650-
Env::default(),
1651-
CrateOrigin::Lang(LangCrateOrigin::from(&*stitched[krate].name)),
1652-
false,
1653-
None,
1654-
);
1655-
Some((krate, crate_id))
1656-
})
1657-
.collect();
1658-
1659-
for from in stitched.crates() {
1660-
for &to in stitched[from].deps.iter() {
1661-
let name = CrateName::new(&stitched[to].name).unwrap();
1662-
if let (Some(&from), Some(&to)) =
1663-
(sysroot_crates.get(&from), sysroot_crates.get(&to))
1664-
{
1665-
add_dep(crate_graph, from, name, to);
1666-
}
1667-
}
1668-
}
16691631

1670-
let public_deps = SysrootPublicDeps {
1671-
deps: stitched
1672-
.public_deps()
1673-
.filter_map(|(name, idx, prelude)| {
1674-
Some((name, *sysroot_crates.get(&idx)?, prelude))
1675-
})
1676-
.collect::<Vec<_>>(),
1677-
};
1678-
1679-
let libproc_macro =
1680-
stitched.proc_macro().and_then(|it| sysroot_crates.get(&it).copied());
1681-
(public_deps, libproc_macro)
1682-
}
16831632
RustLibSrcWorkspace::Empty => (SysrootPublicDeps { deps: vec![] }, None),
16841633
}
16851634
}

crates/project-model/test_data/is-proc-macro-project.json

-13
This file was deleted.

0 commit comments

Comments
 (0)