feat: Initial GlobalSession

This commit is contained in:
2024-12-28 23:24:57 -05:00
commit 32e66fd29c
11 changed files with 448 additions and 0 deletions

18
src/lib.cpp Normal file
View File

@ -0,0 +1,18 @@
//
// Created by bspeice on 12/28/24.
//
#include "lib.h"
#include "slang-compiler-sys/src/lib.rs.h"
namespace slang_compiler {
GlobalSession::GlobalSession() {
slang::createGlobalSession(global_session_.writeRef());
}
std::unique_ptr<GlobalSession> create_global_session() {
return std::make_unique<GlobalSession>();
}
} // namespace slang_compiler

25
src/lib.h Normal file
View File

@ -0,0 +1,25 @@
//
// Created by bspeice on 12/28/24.
//
#pragma once
#include <slang-com-ptr.h>
#include <slang.h>
#include <memory>
#include "rust/cxx.h"
namespace slang_compiler {
class GlobalSession {
public:
explicit GlobalSession();
private:
Slang::ComPtr<slang::IGlobalSession> global_session_;
};
std::unique_ptr<GlobalSession> create_global_session();
} // namespace slang_compiler

19
src/lib.rs Normal file
View File

@ -0,0 +1,19 @@
#[cxx::bridge(namespace = "slang_compiler")]
mod ffi {
unsafe extern "C++" {
include!("lib.h");
type GlobalSession;
fn create_global_session() -> UniquePtr<GlobalSession>;
}
}
#[cfg(test)]
mod tests {
use crate::ffi::create_global_session;
#[test]
fn can_create_global_session() {
let _global_session = create_global_session();
}
}