Skip to content

Commit 32cd023

Browse files
authored
Merge pull request rust-lang#244 from oli-obk/master
Add sysroot configuration to rls.toml
2 parents 1cd7043 + e5bbb8e commit 32cd023

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Currently we accept the following options:
166166
run) test code.
167167
* `unstable_features` (`bool`, defaults to `false`) enables unstable features.
168168
Currently, this includes renaming and formatting.
169+
* `sysroot` (`String`, defaults to `""`) if the given string is not empty, use
170+
the given path as the sysroot for all rustc invocations instead of trying to
171+
detect the sysroot automatically
169172

170173

171174
## Contributing

src/build.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -368,25 +368,27 @@ impl BuildQueue {
368368
if self.config.cfg_test {
369369
args.push("--test".to_owned());
370370
}
371-
args.push("--sysroot".to_owned());
372-
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
373-
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
374-
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
375-
format!("{}/toolchains/{}", home, toolchain)
376-
} else {
377-
option_env!("SYSROOT")
378-
.map(|s| s.to_owned())
379-
.or_else(|| Command::new("rustc")
380-
.arg("--print")
381-
.arg("sysroot")
382-
.output()
383-
.ok()
384-
.and_then(|out| String::from_utf8(out.stdout).ok())
385-
.map(|s| s.trim().to_owned()))
386-
.expect("need to specify SYSROOT env var, \
387-
or use rustup or multirust")
388-
};
389-
args.push(sys_root.to_owned());
371+
if self.config.sysroot.is_empty() {
372+
args.push("--sysroot".to_owned());
373+
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
374+
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
375+
let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) {
376+
format!("{}/toolchains/{}", home, toolchain)
377+
} else {
378+
option_env!("SYSROOT")
379+
.map(|s| s.to_owned())
380+
.or_else(|| Command::new("rustc")
381+
.arg("--print")
382+
.arg("sysroot")
383+
.output()
384+
.ok()
385+
.and_then(|out| String::from_utf8(out.stdout).ok())
386+
.map(|s| s.trim().to_owned()))
387+
.expect("need to specify SYSROOT env var, \
388+
or use rustup or multirust")
389+
};
390+
args.push(sys_root.to_owned());
391+
}
390392

391393
let envs = cmd.get_envs();
392394
trace!("envs: {:?}", envs);
@@ -428,9 +430,13 @@ impl BuildQueue {
428430
// However, if Cargo doesn't run a separate thread, then we'll just wait
429431
// forever. Therefore, we spawn an extra thread here to be safe.
430432
let handle = thread::spawn(move || {
431-
env::set_var("RUSTFLAGS",
432-
"-Zunstable-options -Zsave-analysis --error-format=json \
433-
-Zcontinue-parse-after-error");
433+
let hardcoded = "-Zunstable-options -Zsave-analysis --error-format=json \
434+
-Zcontinue-parse-after-error";
435+
if rls_config.sysroot.is_empty() {
436+
env::set_var("RUSTFLAGS", hardcoded);
437+
} else {
438+
env::set_var("RUSTFLAGS", &format!("--sysroot {} {}", rls_config.sysroot, hardcoded));
439+
}
434440

435441
let shell = MultiShell::from_write(Box::new(BufWriter(out.clone())),
436442
Box::new(BufWriter(err.clone())));

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ macro_rules! create_config {
191191
}
192192

193193
create_config! {
194+
sysroot: String, String::new(), false, "--sysroot";
194195
build_lib: bool, false, false, "cargo check --lib";
195196
cfg_test: bool, true, false, "build cfg(test) code";
196197
unstable_features: bool, false, false, "enable unstable features";

0 commit comments

Comments
 (0)