Load an initial module

This commit is contained in:
2024-12-30 20:09:11 -05:00
commit 9734478b9a
10 changed files with 421 additions and 0 deletions

4
src/entry/main.rs Normal file
View File

@ -0,0 +1,4 @@
fn main() {
println!("Hello, world!");
}

3
src/entry/mod.rs Normal file
View File

@ -0,0 +1,3 @@
mod main;
pub mod parser;

12
src/entry/parser.rs Normal file
View File

@ -0,0 +1,12 @@
use anyhow::{anyhow, Result};
pub fn build_entrypoint(module: &str, session: &slang::Session) -> Result<String>{
let module = session.load_module(module)?;
let entry_point_count = module.get_defined_entry_point_count();
if entry_point_count != 1 {
return Err(anyhow!("Did not have expected entry point count"));
}
Ok("".to_owned())
}

4
src/lib.rs Normal file
View File

@ -0,0 +1,4 @@
pub mod entry;
#[cfg(test)]
mod tests;

23
src/tests/entry.rs Normal file
View File

@ -0,0 +1,23 @@
use std::path::{PathBuf};
#[test]
fn compute_hello_world() {
let global_session = slang::GlobalSession::new().expect("Failed to create global session");
let target_desc = slang::TargetDescBuilder::new()
.format(slang::CompileTarget::Spirv)
.profile(global_session.find_profile("spirv_1_2"));
let search_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources/test-entry");
if !search_path.exists() {
return;
}
let search_path_bytes = unsafe { std::mem::transmute::<_, *const i8>(search_path.as_os_str().as_encoded_bytes().as_ptr()) };
let session_desc = slang::SessionDescBuilder::new()
.targets(&[*target_desc])
.search_paths(&[search_path_bytes]);
let session = global_session.create_session(&session_desc).expect("Failed to create session");
let _entry = crate::entry::parser::build_entrypoint("compute_hello-world.slang", &session).expect("Failed to build entry");
}

1
src/tests/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod entry;