Skip to content

Commit 9f89fcd

Browse files
author
Grant Wuerker
committed
library2
1 parent 5e2cf56 commit 9f89fcd

File tree

17 files changed

+1283
-0
lines changed

17 files changed

+1283
-0
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/driver2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description = "Provides Fe driver"
1212
[dependencies]
1313
salsa = { git = "https://github.com/salsa-rs/salsa", package = "salsa-2022" }
1414
codespan-reporting = "0.11"
15+
library2 = { path = "../library2", package = "fe-library2" }
1516

1617
hir = { path = "../hir", package = "fe-hir" }
1718
common = { path = "../common2", package = "fe-common2" }

crates/driver2/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ impl DriverDataBase {
9191
map_file_to_mod(self, file)
9292
}
9393

94+
fn top_mod_from_ingot(&self, ingot: InputIngot) -> TopLevelMod {
95+
map_file_to_mod(self, ingot.root_file(self))
96+
}
97+
98+
pub fn top_mod_from_std_ingot(&mut self) -> TopLevelMod {
99+
let ingot = library2::std_lib_input_ingot(self);
100+
self.top_mod_from_ingot(ingot)
101+
}
102+
94103
/// Prints accumulated diagnostics to stderr.
95104
pub fn emit_diags(&self) {
96105
let writer = BufferWriter::stderr(ColorChoice::Auto);

crates/driver2/tests/std_lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use fe_driver2::DriverDataBase;
2+
3+
#[test]
4+
fn check_std_lib() {
5+
let mut driver = DriverDataBase::default();
6+
let top_mod = driver.top_mod_from_std_ingot();
7+
driver.run_on_top_mod(top_mod);
8+
let diags = driver.format_diags();
9+
if !diags.is_empty() {
10+
panic!("{diags}")
11+
}
12+
}

crates/hir-analysis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ regex = "1.10"
2727
[dev-dependencies]
2828
codespan-reporting = "0.11"
2929
dir-test = "0.1"
30+
library2 = { path = "../library2", package = "fe-library2" }

crates/library2/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "fe-library2"
3+
version = "0.23.0"
4+
authors = ["The Fe Developers <[email protected]>"]
5+
edition = "2021"
6+
license = "Apache-2.0"
7+
repository = "https://github.com/ethereum/fe"
8+
9+
[dependencies]
10+
include_dir = "0.7.2"
11+
common = { path = "../common2", package = "fe-common2" }

crates/library2/build.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo:rerun-if-changed=./std");
3+
}

crates/library2/src/lib.rs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::collections::BTreeSet;
2+
3+
pub use ::include_dir;
4+
use common::{
5+
input::{IngotKind, Version},
6+
InputDb, InputFile, InputIngot,
7+
};
8+
use include_dir::{include_dir, Dir};
9+
10+
pub const STD: Dir = include_dir!("$CARGO_MANIFEST_DIR/std");
11+
12+
fn std_src_input_files(db: &mut dyn InputDb, ingot: InputIngot) -> BTreeSet<InputFile> {
13+
static_dir_files(&STD)
14+
.into_iter()
15+
.map(|(path, content)| InputFile::new(db, ingot, path.into(), content.into()))
16+
.collect()
17+
}
18+
19+
pub fn std_lib_input_ingot(db: &mut dyn InputDb) -> InputIngot {
20+
let ingot = InputIngot::new(
21+
db,
22+
"std",
23+
IngotKind::Std,
24+
Version::new(0, 0, 0),
25+
BTreeSet::default(),
26+
);
27+
28+
let input_files = std_src_input_files(db, ingot);
29+
let root_file = input_files
30+
.iter()
31+
.find(|file| file.path(db).ends_with("lib.fe"))
32+
.unwrap()
33+
.to_owned();
34+
35+
ingot.set_root_file(db, root_file);
36+
37+
ingot.set_files(db, input_files);
38+
ingot
39+
}
40+
41+
// pub fn std_src_files() -> Vec<(&'static str, &'static str)> {
42+
// static_dir_files(STD.get_dir("src").unwrap())
43+
// }
44+
45+
pub fn static_dir_files(dir: &'static Dir) -> Vec<(&'static str, &'static str)> {
46+
fn add_files(dir: &'static Dir, accum: &mut Vec<(&'static str, &'static str)>) {
47+
accum.extend(dir.files().map(|file| {
48+
(
49+
file.path().to_str().unwrap(),
50+
file.contents_utf8().expect("non-utf8 static file"),
51+
)
52+
}));
53+
54+
for sub_dir in dir.dirs() {
55+
add_files(sub_dir, accum)
56+
}
57+
}
58+
59+
let mut files = vec![];
60+
add_files(dir, &mut files);
61+
files
62+
}

0 commit comments

Comments
 (0)