mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Use autocfg to determine rust version
This commit is contained in:
parent
c486f8477a
commit
06754b78ac
3 changed files with 12 additions and 25 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1823,6 +1823,7 @@ dependencies = [
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -6,6 +6,7 @@ authors = ["rust-analyzer developers"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
autocfg = "0.1"
|
||||||
walkdir = "2.1.3"
|
walkdir = "2.1.3"
|
||||||
pico-args = "0.3.0"
|
pico-args = "0.3.0"
|
||||||
quote = "1.0.2"
|
quote = "1.0.2"
|
||||||
|
|
|
@ -9,17 +9,18 @@
|
||||||
//! `.cargo/config`.
|
//! `.cargo/config`.
|
||||||
mod help;
|
mod help;
|
||||||
|
|
||||||
|
use autocfg;
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use core::str;
|
use core::str;
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
use xtask::{
|
use xtask::{
|
||||||
codegen::{self, Mode},
|
codegen::{self, Mode},
|
||||||
install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, run_with_output, Cmd, Result,
|
install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Latest stable, feel free to send a PR if this lags behind.
|
// Latest stable, feel free to send a PR if this lags behind.
|
||||||
const REQUIRED_RUST_VERSION: u32 = 39;
|
const REQUIRED_RUST_VERSION: (usize, usize) = (1, 39);
|
||||||
|
|
||||||
struct InstallOpt {
|
struct InstallOpt {
|
||||||
client: Option<ClientOpt>,
|
client: Option<ClientOpt>,
|
||||||
|
@ -226,20 +227,14 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_server(opts: ServerOpt) -> Result<()> {
|
fn install_server(opts: ServerOpt) -> Result<()> {
|
||||||
let mut old_rust = false;
|
let ac = autocfg::AutoCfg::with_dir("target")?;
|
||||||
if let Ok(output) = run_with_output("cargo --version", ".") {
|
|
||||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
let old_rust = !ac.probe_rustc_version(REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1);
|
||||||
println!("{}", stdout);
|
|
||||||
if !check_version(&stdout, REQUIRED_RUST_VERSION) {
|
|
||||||
old_rust = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if old_rust {
|
if old_rust {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
|
"\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n",
|
||||||
REQUIRED_RUST_VERSION
|
REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,20 +246,10 @@ fn install_server(opts: ServerOpt) -> Result<()> {
|
||||||
|
|
||||||
if res.is_err() && old_rust {
|
if res.is_err() && old_rust {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
|
"\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n",
|
||||||
REQUIRED_RUST_VERSION
|
REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_version(version_output: &str, min_minor_version: u32) -> bool {
|
|
||||||
// Parse second the number out of
|
|
||||||
// cargo 1.39.0-beta (1c6ec66d5 2019-09-30)
|
|
||||||
let minor: Option<u32> = version_output.split('.').nth(1).and_then(|it| it.parse().ok());
|
|
||||||
match minor {
|
|
||||||
None => true,
|
|
||||||
Some(minor) => minor >= min_minor_version,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue