Skip to content

Allow sysroots to only consist of the source root dir #17287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/hir-ty/src/layout/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chalk_ir::{AdtId, TyKind};
use either::Either;
use hir_def::db::DefDatabase;
use project_model::target_data_layout::RustcDataLayoutConfig;
use project_model::{target_data_layout::RustcDataLayoutConfig, Sysroot};
use rustc_hash::FxHashMap;
use test_fixture::WithFixture;
use triomphe::Arc;
Expand All @@ -17,7 +17,7 @@ mod closure;

fn current_machine_data_layout() -> String {
project_model::target_data_layout::get(
RustcDataLayoutConfig::Rustc(None),
RustcDataLayoutConfig::Rustc(&Sysroot::empty()),
None,
&FxHashMap::default(),
)
Expand Down
14 changes: 7 additions & 7 deletions crates/project-model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl WorkspaceBuildScripts {
allowed_features: &FxHashSet<String>,
manifest_path: &ManifestPath,
toolchain: Option<&Version>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> io::Result<Command> {
const RUST_1_75: Version = Version::new(1, 75, 0);
let mut cmd = match config.run_build_script_command.as_deref() {
Expand All @@ -75,7 +75,7 @@ impl WorkspaceBuildScripts {
cmd
}
_ => {
let mut cmd = Sysroot::tool(sysroot, Tool::Cargo);
let mut cmd = sysroot.tool(Tool::Cargo);

cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]);
cmd.args(&config.extra_args);
Expand Down Expand Up @@ -149,7 +149,7 @@ impl WorkspaceBuildScripts {
workspace: &CargoWorkspace,
progress: &dyn Fn(String),
toolchain: Option<&Version>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> io::Result<WorkspaceBuildScripts> {
let current_dir = match &config.invocation_location {
InvocationLocation::Root(root) if config.run_build_script_command.is_some() => {
Expand Down Expand Up @@ -195,7 +195,7 @@ impl WorkspaceBuildScripts {
// This is not gonna be used anyways, so just construct a dummy here
&ManifestPath::try_from(workspace_root.clone()).unwrap(),
None,
None,
&Sysroot::empty(),
)?;
// NB: Cargo.toml could have been modified between `cargo metadata` and
// `cargo check`. We shouldn't assume that package ids we see here are
Expand Down Expand Up @@ -412,15 +412,15 @@ impl WorkspaceBuildScripts {
rustc: &CargoWorkspace,
current_dir: &AbsPath,
extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> Self {
let mut bs = WorkspaceBuildScripts::default();
for p in rustc.packages() {
bs.outputs.insert(p, BuildScriptOutput::default());
}
let res = (|| {
let target_libdir = (|| {
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
let mut cargo_config = sysroot.tool(Tool::Cargo);
cargo_config.envs(extra_env);
cargo_config
.current_dir(current_dir)
Expand All @@ -429,7 +429,7 @@ impl WorkspaceBuildScripts {
if let Ok(it) = utf8_stdout(cargo_config) {
return Ok(it);
}
let mut cmd = Sysroot::tool(sysroot, Tool::Rustc);
let mut cmd = sysroot.tool(Tool::Rustc);
cmd.envs(extra_env);
cmd.args(["--print", "target-libdir"]);
utf8_stdout(cmd)
Expand Down
14 changes: 7 additions & 7 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ impl CargoWorkspace {
cargo_toml: &ManifestPath,
current_dir: &AbsPath,
config: &CargoConfig,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
progress: &dyn Fn(String),
) -> anyhow::Result<cargo_metadata::Metadata> {
let targets = find_list_of_build_targets(config, cargo_toml, sysroot);

let cargo = Sysroot::tool(sysroot, Tool::Cargo);
let cargo = sysroot.tool(Tool::Cargo);
let mut meta = MetadataCommand::new();
meta.cargo_path(cargo.get_program());
cargo.get_envs().for_each(|(var, val)| _ = meta.env(var, val.unwrap_or_default()));
Expand Down Expand Up @@ -536,7 +536,7 @@ impl CargoWorkspace {
fn find_list_of_build_targets(
config: &CargoConfig,
cargo_toml: &ManifestPath,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> Vec<String> {
if let Some(target) = &config.target {
return [target.into()].to_vec();
Expand All @@ -553,9 +553,9 @@ fn find_list_of_build_targets(
fn rustc_discover_host_triple(
cargo_toml: &ManifestPath,
extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> Option<String> {
let mut rustc = Sysroot::tool(sysroot, Tool::Rustc);
let mut rustc = sysroot.tool(Tool::Rustc);
rustc.envs(extra_env);
rustc.current_dir(cargo_toml.parent()).arg("-vV");
tracing::debug!("Discovering host platform by {:?}", rustc);
Expand All @@ -581,9 +581,9 @@ fn rustc_discover_host_triple(
fn cargo_config_build_target(
cargo_toml: &ManifestPath,
extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> Vec<String> {
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
let mut cargo_config = sysroot.tool(Tool::Cargo);
cargo_config.envs(extra_env);
cargo_config
.current_dir(cargo_toml.parent())
Expand Down
4 changes: 2 additions & 2 deletions crates/project-model/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub(crate) fn inject_rustc_tool_env(env: &mut Env, cargo_name: &str, kind: Targe
pub(crate) fn cargo_config_env(
manifest: &ManifestPath,
extra_env: &FxHashMap<String, String>,
sysroot: Option<&Sysroot>,
sysroot: &Sysroot,
) -> FxHashMap<String, String> {
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
let mut cargo_config = sysroot.tool(Tool::Cargo);
cargo_config.envs(extra_env);
cargo_config
.current_dir(manifest.parent())
Expand Down
8 changes: 4 additions & 4 deletions crates/project-model/src/rustc_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{cfg::CfgFlag, utf8_stdout, ManifestPath, Sysroot};
pub(crate) enum RustcCfgConfig<'a> {
/// Use `rustc --print cfg`, either from with the binary from the sysroot or by discovering via
/// [`toolchain::rustc`].
Rustc(Option<&'a Sysroot>),
Rustc(&'a Sysroot),
/// Use `cargo --print cfg`, either from with the binary from the sysroot or by discovering via
/// [`toolchain::cargo`].
Cargo(Option<&'a Sysroot>, &'a ManifestPath),
Cargo(&'a Sysroot, &'a ManifestPath),
}

pub(crate) fn get(
Expand Down Expand Up @@ -65,7 +65,7 @@ fn get_rust_cfgs(
) -> anyhow::Result<String> {
let sysroot = match config {
RustcCfgConfig::Cargo(sysroot, cargo_toml) => {
let mut cmd = Sysroot::tool(sysroot, Tool::Cargo);
let mut cmd = sysroot.tool(Tool::Cargo);

cmd.envs(extra_env);
cmd.current_dir(cargo_toml.parent())
Expand All @@ -86,7 +86,7 @@ fn get_rust_cfgs(
RustcCfgConfig::Rustc(sysroot) => sysroot,
};

let mut cmd = Sysroot::tool(sysroot, Tool::Rustc);
let mut cmd = sysroot.tool(Tool::Rustc);
cmd.envs(extra_env);
cmd.args(["--print", "cfg", "-O"]);
if let Some(target) = target {
Expand Down
Loading