Skip to content

Commit 30b099f

Browse files
authored
Update toolchain (#361)
1 parent 0151c14 commit 30b099f

File tree

31 files changed

+232
-69
lines changed

31 files changed

+232
-69
lines changed

Cargo.lock

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"flux",
55
"flux-bin",
66
"flux-common",
7+
"flux-config",
78
"flux-desugar",
89
"flux-driver",
910
"flux-errors",

flux-bin/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[package]
2+
edition = "2021"
23
name = "flux-bin"
34
version = "0.1.0"
4-
edition = "2021"
55

66
[[bin]]
7+
doctest = false
78
name = "cargo-flux"
89
test = false
9-
doctest = false
1010

1111
[[bin]]
12+
doctest = false
1213
name = "rustc-flux"
1314
test = false
14-
doctest = false
1515

1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1717

1818
[dependencies]
19-
flux-common = { path = "../flux-common" }
2019
anyhow = "1.0.68"
2120
dirs = "4.0.0"
21+
flux-config = { path = "../flux-config" }
2222
rust-toolchain-file = "0.1.0"

flux-bin/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{env, ffi::OsString, fs, path::PathBuf};
22

33
use anyhow::{anyhow, Result};
4-
use flux_common::config;
4+
use flux_config as config;
55

66
#[cfg(target_os = "windows")]
77
pub const LIB_PATH: &str = "PATH";

flux-common/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ version = "0.1.0"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
config = "0.12"
10-
once_cell = "1.9"
11-
serde = { version = "1.0", features = ["derive"] }
12-
toml = "0.5"
9+
flux-config = { path = "../flux-config" }
1310

1411
[package.metadata.rust-analyzer]
1512
rustc_private = true

flux-common/src/cache.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::{fs::File, path::PathBuf};
22

3+
use flux_config as config;
34
use rustc_hash::FxHashMap;
45

5-
use crate::config;
6-
76
pub struct QueryCache {
87
entries: FxHashMap<String, u64>,
98
}

flux-common/src/dbg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use std::{
44
io::{self, Write},
55
};
66

7+
use flux_config as config;
78
use rustc_hir::def_id::DefId;
89
use rustc_middle::ty::TyCtxt;
910

10-
use crate::config;
11-
1211
pub fn writer_for_item(
1312
tcx: TyCtxt,
1413
def_id: DefId,

flux-common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(rustc_private, try_trait_v2, try_blocks, never_type, once_cell)]
22

3+
extern crate rustc_driver;
34
extern crate rustc_errors;
45
extern crate rustc_hash;
56
extern crate rustc_hir;
@@ -9,7 +10,6 @@ extern crate rustc_span;
910
extern crate serde_json;
1011

1112
pub mod cache;
12-
pub mod config;
1313
pub mod dbg;
1414
pub mod format;
1515
pub mod index;

flux-config/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
edition = "2021"
3+
name = "flux-config"
4+
version = "0.1.0"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
config = "0.12"
10+
serde = { version = "1.0", features = ["derive"] }
11+
toml = "0.5"

flux-config/src/lib.rs

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#![feature(once_cell)]
2+
3+
use std::{io::Read, path::PathBuf, sync::LazyLock};
4+
5+
use config::{Environment, File};
6+
use serde::Deserialize;
7+
pub use toml::Value;
8+
9+
const FLUX_ENV_VAR_PREFIX: &str = "FLUX";
10+
const FLUX_CONFIG_ENV_VAR: &str = "FLUX_CONFIG";
11+
12+
#[derive(Debug, Deserialize, Copy, Clone)]
13+
#[serde(rename_all = "lowercase")]
14+
pub enum AssertBehavior {
15+
Ignore,
16+
Assume,
17+
Check,
18+
}
19+
20+
pub fn check_def() -> &'static str {
21+
&CONFIG.check_def
22+
}
23+
24+
pub fn dump_timings() -> bool {
25+
CONFIG.dump_timings
26+
}
27+
28+
pub fn dump_checker_trace() -> bool {
29+
CONFIG.dump_checker_trace
30+
}
31+
32+
pub fn dump_mir() -> bool {
33+
CONFIG.dump_mir
34+
}
35+
36+
pub fn dump_constraint() -> bool {
37+
CONFIG.dump_constraint
38+
}
39+
40+
pub fn dump_fhir() -> bool {
41+
CONFIG.dump_fhir
42+
}
43+
44+
pub fn pointer_width() -> u64 {
45+
CONFIG.pointer_width
46+
}
47+
48+
pub fn assert_behavior() -> AssertBehavior {
49+
CONFIG.check_asserts
50+
}
51+
52+
pub fn log_dir() -> &'static PathBuf {
53+
&CONFIG.log_dir
54+
}
55+
56+
pub fn is_cache_enabled() -> bool {
57+
CONFIG.cache
58+
}
59+
60+
pub fn cache_path() -> PathBuf {
61+
log_dir().join(&CONFIG.cache_file)
62+
}
63+
64+
pub fn driver_path() -> Option<&'static PathBuf> {
65+
CONFIG.driver_path.as_ref()
66+
}
67+
68+
impl std::str::FromStr for AssertBehavior {
69+
type Err = ();
70+
71+
fn from_str(s: &str) -> Result<Self, Self::Err> {
72+
match s {
73+
"ignore" => Ok(AssertBehavior::Ignore),
74+
"assume" => Ok(AssertBehavior::Assume),
75+
"check" => Ok(AssertBehavior::Check),
76+
_ => Err(()),
77+
}
78+
}
79+
}
80+
81+
#[derive(Debug)]
82+
pub struct CrateConfig {
83+
pub log_dir: PathBuf,
84+
pub dump_constraint: bool,
85+
pub dump_checker_trace: bool,
86+
pub check_asserts: AssertBehavior,
87+
}
88+
89+
#[derive(Deserialize)]
90+
struct Config {
91+
driver_path: Option<PathBuf>,
92+
log_dir: PathBuf,
93+
dump_constraint: bool,
94+
dump_checker_trace: bool,
95+
dump_timings: bool,
96+
dump_fhir: bool,
97+
check_asserts: AssertBehavior,
98+
dump_mir: bool,
99+
pointer_width: u64,
100+
check_def: String,
101+
cache: bool,
102+
cache_file: String,
103+
}
104+
105+
static CONFIG: LazyLock<Config> = LazyLock::new(|| {
106+
fn build() -> Result<Config, config::ConfigError> {
107+
let mut config_builder = config::Config::builder()
108+
.set_default("driver_path", None::<String>)?
109+
.set_default("log_dir", "./log/")?
110+
.set_default("dump_constraint", false)?
111+
.set_default("dump_checker_trace", false)?
112+
.set_default("dump_timings", false)?
113+
.set_default("dump_mir", false)?
114+
.set_default("dump_fhir", false)?
115+
.set_default("check_asserts", "assume")?
116+
.set_default("pointer_width", 64)?
117+
.set_default("check_def", "")?
118+
.set_default("cache", false)?
119+
.set_default("cache_file", "cache.json")?;
120+
// Config comes first, enviroment settings override it.
121+
if let Some(config_path) = CONFIG_PATH.as_ref() {
122+
config_builder = config_builder.add_source(File::from(config_path.to_path_buf()));
123+
};
124+
config_builder
125+
.add_source(Environment::with_prefix(FLUX_ENV_VAR_PREFIX).ignore_empty(true))
126+
.build()?
127+
.try_deserialize()
128+
}
129+
build().unwrap()
130+
});
131+
132+
pub static CONFIG_PATH: LazyLock<Option<PathBuf>> = LazyLock::new(|| {
133+
if let Ok(file) = std::env::var(FLUX_CONFIG_ENV_VAR) {
134+
return Some(PathBuf::from(file));
135+
}
136+
137+
// find config file in current or parent directories
138+
let mut path = std::env::current_dir().unwrap();
139+
loop {
140+
for name in ["flux.toml", ".flux.toml"] {
141+
let file = path.join(name);
142+
if file.exists() {
143+
return Some(file);
144+
}
145+
}
146+
if !path.pop() {
147+
return None;
148+
}
149+
}
150+
});
151+
152+
pub static CONFIG_FILE: LazyLock<Value> = LazyLock::new(|| {
153+
if let Some(path) = &*CONFIG_PATH {
154+
let mut file = std::fs::File::open(path).unwrap();
155+
let mut contents = String::new();
156+
file.read_to_string(&mut contents).unwrap();
157+
toml::from_str(&contents).unwrap()
158+
} else {
159+
toml::from_str("").unwrap()
160+
}
161+
});

0 commit comments

Comments
 (0)