64 LILA_INFO(Emitter::INTERPRETER,
"Initializing Clang interpreter");
66#ifdef MAYAFLUX_PLATFORM_WINDOWS
67 llvm::sys::DynamicLibrary::LoadLibraryPermanently(
"msvcp140.dll");
68 llvm::sys::DynamicLibrary::LoadLibraryPermanently(
"vcruntime140.dll");
69 llvm::sys::DynamicLibrary::LoadLibraryPermanently(
"ucrtbase.dll");
70 llvm::sys::DynamicLibrary::LoadLibraryPermanently(
"MayaFluxLib.dll");
73 llvm::InitializeNativeTarget();
74 llvm::InitializeNativeTargetAsmPrinter();
75 llvm::InitializeNativeTargetAsmParser();
77 m_impl->compile_flags.clear();
78 m_impl->compile_flags.emplace_back(
"-std=c++23");
79 m_impl->compile_flags.emplace_back(
"-DMAYASIMPLE");
81#ifdef MAYAFLUX_PLATFORM_LINUX
82 m_impl->compile_flags.emplace_back(
"-mcmodel=large");
83 m_impl->compile_flags.emplace_back(
"-fPIC");
84 m_impl->compile_flags.emplace_back(
"-fPIE");
88 if (std::filesystem::exists(MayaFlux::Config::PCH_RUNTIME_PATH)) {
89 pch_dir = MayaFlux::Config::RUNTIME_DATA_DIR;
91 std::string(
"Using installed PCH from: ") + std::string(MayaFlux::Config::PCH_RUNTIME_PATH));
93 }
else if (std::filesystem::exists(MayaFlux::Config::PCH_SOURCE_PATH)) {
94 pch_dir = std::string(MayaFlux::Config::SOURCE_DIR) +
"/cmake";
96 std::string(
"Using source PCH from: ") + std::string(MayaFlux::Config::PCH_SOURCE_PATH));
99 m_last_error =
"Cannot find pch.h in runtime or source locations";
100 LILA_ERROR(Emitter::INTERPRETER, m_last_error);
104 m_impl->compile_flags.push_back(
"-I" + pch_dir);
107 if (!resource_dir.empty()) {
108 m_impl->compile_flags.push_back(
"-resource-dir=" + resource_dir);
110 std::string(
"Using clang resource dir: ") + resource_dir);
112 m_impl->compile_flags.emplace_back(
"-resource-dir=/usr/lib/clang/21");
114 "Using default clang resource dir: /usr/lib/clang/21");
118 for (
const auto& include : system_includes) {
119 m_impl->compile_flags.push_back(
"-isystem" + include);
122#ifndef MAYAFLUX_PLATFORM_WINDOWS
124 if (!eigen_include.empty()) {
125 m_impl->compile_flags.push_back(
"-isystem" + eigen_include);
127 std::string(
"Added Eigen include path: ") + eigen_include);
130 "Could not find Eigen include path - some features may not work");
134#ifdef MAYAFLUX_PLATFORM_MACOS
137 std::string sdk_path = MayaFlux::Platform::SystemConfig::get_macos_sdk_path();
138 if (!sdk_path.empty()) {
139 m_impl->compile_flags.push_back(
"-isysroot" + sdk_path);
140 LILA_DEBUG(Emitter::INTERPRETER,
"Using macOS SDK: " + sdk_path);
143 "Could not find macOS SDK - JIT may fail to find system headers");
147 for (
const auto& path : m_impl->include_paths) {
148 m_impl->compile_flags.push_back(
"-I" + path);
151#ifdef MAYAFLUX_PLATFORM_WINDOWS
152 m_impl->compile_flags.emplace_back(
"-fno-function-sections");
153 m_impl->compile_flags.emplace_back(
"-fno-data-sections");
154 m_impl->compile_flags.emplace_back(
"-fno-unique-section-names");
157 std::vector<const char*> args;
158 for (
const auto& flag : m_impl->compile_flags) {
159 args.push_back(flag.c_str());
162 clang::IncrementalCompilerBuilder ICB;
163 ICB.SetCompilerArgs(args);
165 auto CI = ICB.CreateCpp();
167 m_last_error =
"Failed to create CompilerInstance: " + llvm::toString(CI.takeError());
168 LILA_ERROR(Emitter::INTERPRETER, m_last_error);
172 auto interp = clang::Interpreter::create(std::move(*CI));
174 m_last_error =
"Failed to create interpreter: " + llvm::toString(interp.takeError());
175 LILA_ERROR(Emitter::INTERPRETER, m_last_error);
179 m_impl->interpreter = std::move(*interp);
181 LILA_INFO(Emitter::INTERPRETER,
"Clang interpreter created successfully");
183 auto result = m_impl->interpreter->ParseAndExecute(
184 "#include \"pch.h\"\n"
185 "#include \"Lila/LiveAid.hpp\"\n");
188 std::string warning =
"Failed to load MayaFlux headers: " + llvm::toString(std::move(result));
189 LILA_WARN(Emitter::INTERPRETER, warning);
191 LILA_INFO(Emitter::INTERPRETER,
"MayaFlux headers loaded successfully");
194 result = m_impl->interpreter->ParseAndExecute(
"std::cout << \"Ready for Live\" << std::flush;");
201#ifdef MAYAFLUX_PLATFORM_MACOS
207 if (!
m_impl->interpreter) {
208 result.
error =
"Interpreter not initialized";
209 LILA_ERROR(Emitter::INTERPRETER, result.error);
213 LILA_DEBUG(Emitter::INTERPRETER,
"Evaluating code...");
215#ifdef MAYAFLUX_PLATFORM_MACOS
216 dispatch_sync(dispatch_get_main_queue(), ^{
217 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
220 result.success =
true;
221 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
223 result.success =
false;
224 result.error =
"Execution failed: " + llvm::toString(std::move(eval_result));
225 LILA_ERROR(Emitter::INTERPRETER, result.error);
229#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
230 auto completed = std::make_shared<std::atomic<bool>>(
false);
232 auto* task =
new std::function<void()>([&, completed]() {
233 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
236 result.success =
true;
237 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
239 result.success =
false;
240 result.error =
"Execution failed: " + llvm::toString(std::move(eval_result));
241 LILA_ERROR(Emitter::INTERPRETER, result.error);
244 completed->store(
true, std::memory_order_release);
247 PostThreadMessage(MayaFlux::Parallel::g_MainThreadId, MAYAFLUX_WM_DISPATCH, 0, (LPARAM)task);
249 while (!completed->load(std::memory_order_acquire)) {
250 std::this_thread::sleep_for(std::chrono::microseconds(100));
254 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
257 result.success =
true;
258 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
260 result.success =
false;
261 result.error =
"Execution failed: " + llvm::toString(std::move(eval_result));
262 LILA_ERROR(Emitter::INTERPRETER, result.error);