mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 21:34:50 +00:00
Include all the .60 files in sixtyfps_widgets by default
This commit is contained in:
parent
abe6888296
commit
ad12ffaa46
6 changed files with 89 additions and 11 deletions
|
@ -3,6 +3,7 @@ name = "sixtyfps_compilerlib"
|
|||
version = "0.1.0"
|
||||
authors = ["Sixty FPS <info@sixtyfps.io>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
|
44
sixtyfps_compiler/build.rs
Normal file
44
sixtyfps_compiler/build.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use std::fs::read_dir;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let mut library_dir = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
|
||||
library_dir.pop();
|
||||
library_dir.push("sixtyfps_widgets");
|
||||
|
||||
println!("cargo:rerun-if-changed={}", library_dir.display());
|
||||
|
||||
let output_file_path = Path::new(&std::env::var_os("OUT_DIR").unwrap())
|
||||
.join(Path::new("included_library").with_extension("rs"));
|
||||
|
||||
let library_files: Vec<PathBuf> = read_dir(library_dir)?
|
||||
.filter_map(Result::ok)
|
||||
.filter(|entry| {
|
||||
entry.path().is_file()
|
||||
&& entry.path().extension().unwrap_or_default() == std::ffi::OsStr::new("60")
|
||||
})
|
||||
.map(|entry| entry.path())
|
||||
.collect();
|
||||
|
||||
let mut file = std::fs::File::create(&output_file_path)?;
|
||||
write!(file, "pub fn widget_library() -> &'static [(&'static str, &'static str)] {{ &[")?;
|
||||
write!(
|
||||
file,
|
||||
"{}",
|
||||
library_files
|
||||
.iter()
|
||||
.map(|file| format!(
|
||||
"(\"{}\" ,include_str!(\"{}\"))",
|
||||
file.file_name().unwrap().to_string_lossy(),
|
||||
file.display()
|
||||
))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
)?;
|
||||
write!(file, "] }}")?;
|
||||
|
||||
println!("cargo:rustc-env=SIXTYFPS_WIDGETS_LIBRARY={}", output_file_path.display());
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -61,9 +61,18 @@ pub fn compile_syntax_node(
|
|||
let mut build_diagnostics = diagnostics::BuildDiagnostics::default();
|
||||
|
||||
let global_type_registry = typeregister::TypeRegister::builtin();
|
||||
let type_registry = if !compiler_config.include_paths.is_empty() {
|
||||
let library = Rc::new(RefCell::new(typeregister::TypeRegister::new(&global_type_registry)));
|
||||
let type_registry =
|
||||
Rc::new(RefCell::new(typeregister::TypeRegister::new(&global_type_registry)));
|
||||
|
||||
for (path, source) in library::widget_library() {
|
||||
build_diagnostics.add(typeregister::TypeRegister::add_type_from_source(
|
||||
&type_registry,
|
||||
source.to_string(),
|
||||
&path,
|
||||
));
|
||||
}
|
||||
|
||||
if !compiler_config.include_paths.is_empty() {
|
||||
build_diagnostics.extend(
|
||||
compiler_config
|
||||
.include_paths
|
||||
|
@ -77,16 +86,13 @@ pub fn compile_syntax_node(
|
|||
} else {
|
||||
path.clone()
|
||||
};
|
||||
typeregister::TypeRegister::add_from_directory(&library, path)
|
||||
typeregister::TypeRegister::add_from_directory(&type_registry, path)
|
||||
})
|
||||
.filter_map(Result::ok)
|
||||
.flatten(),
|
||||
);
|
||||
|
||||
library
|
||||
} else {
|
||||
global_type_registry
|
||||
};
|
||||
|
||||
let doc = crate::object_tree::Document::from_node(doc_node, &mut diagnostics, &type_registry);
|
||||
|
||||
build_diagnostics.add(diagnostics);
|
||||
|
@ -112,3 +118,7 @@ pub fn run_passes(
|
|||
passes::repeater_component::create_repeater_components(&doc.root_component);
|
||||
passes::move_declarations::move_declarations(&doc.root_component);
|
||||
}
|
||||
|
||||
mod library {
|
||||
include!(env!("SIXTYFPS_WIDGETS_LIBRARY"));
|
||||
}
|
||||
|
|
|
@ -447,6 +447,24 @@ impl TypeRegister {
|
|||
/// Loads the .60 file and adds it to the type registry. An error is returned if there were I/O problems,
|
||||
/// otherwise the diagnostics collected during the parsing are returned.
|
||||
pub fn add_type_from_source<P: AsRef<std::path::Path>>(
|
||||
registry: &Rc<RefCell<Self>>,
|
||||
source: String,
|
||||
path: P,
|
||||
) -> FileDiagnostics {
|
||||
let (syntax_node, mut diag) = crate::parser::parse(source, Some(path.as_ref()));
|
||||
|
||||
let doc = crate::object_tree::Document::from_node(syntax_node, &mut diag, ®istry);
|
||||
|
||||
if !doc.root_component.id.is_empty() {
|
||||
registry.borrow_mut().add(doc.root_component);
|
||||
}
|
||||
|
||||
diag
|
||||
}
|
||||
|
||||
/// Loads the .60 file and adds it to the type registry. An error is returned if there were I/O problems,
|
||||
/// otherwise the diagnostics collected during the parsing are returned.
|
||||
pub fn add_type_from_path<P: AsRef<std::path::Path>>(
|
||||
registry: &Rc<RefCell<Self>>,
|
||||
path: P,
|
||||
) -> std::io::Result<FileDiagnostics> {
|
||||
|
@ -482,7 +500,7 @@ impl TypeRegister {
|
|||
}
|
||||
})
|
||||
.map(|path| {
|
||||
TypeRegister::add_type_from_source(registry, &path)
|
||||
TypeRegister::add_type_from_path(registry, &path)
|
||||
.unwrap_or_else(|ioerr| FileDiagnostics::new_from_error(path, ioerr))
|
||||
})
|
||||
.collect())
|
||||
|
@ -528,7 +546,7 @@ fn test_extend_registry_from_source() {
|
|||
}
|
||||
|
||||
test_source_path.set_file_name("lib_test.60");
|
||||
let result = TypeRegister::add_type_from_source(&local_types, &test_source_path);
|
||||
let result = TypeRegister::add_type_from_path(&local_types, &test_source_path);
|
||||
assert!(result.is_ok());
|
||||
|
||||
assert_ne!(local_types.borrow().lookup("PublicType"), Type::Invalid);
|
||||
|
@ -536,7 +554,7 @@ fn test_extend_registry_from_source() {
|
|||
|
||||
// Now try again.
|
||||
test_source_path.set_file_name("lib_test2.60");
|
||||
let result = TypeRegister::add_type_from_source(&local_types, &test_source_path);
|
||||
let result = TypeRegister::add_type_from_path(&local_types, &test_source_path);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let diagnostics = result.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue