hosting wip
This commit is contained in:
Родитель
e856fe528f
Коммит
52cc9579ca
|
@ -83,7 +83,6 @@ slnx.sqlite
|
|||
/src/Modules/Spark/spark-trinity/project/target
|
||||
/src/Modules/Spark/spark-trinity/target
|
||||
/src/Modules/Spark/spark-trinity/.idea
|
||||
/src/Trinity.C/Makefile
|
||||
xUnitReports
|
||||
tools/NuGet.exe
|
||||
tools/dotnet/*
|
||||
|
@ -110,3 +109,4 @@ tests/new_test.exe
|
|||
ServiceFabricBackup
|
||||
tests/benchmarks/**/*Artifacts*
|
||||
**/.vim
|
||||
/*-build/
|
||||
|
|
|
@ -4,3 +4,6 @@
|
|||
[submodule "src/Modules/GraphEngine.Jit/asmjit"]
|
||||
path = src/Modules/GraphEngine.Jit/asmjit
|
||||
url = https://github.com/asmjit/asmjit.git
|
||||
[submodule "src/RxCpp"]
|
||||
path = src/RxCpp
|
||||
url = https://github.com/ReactiveX/RxCpp.git
|
||||
|
|
|
@ -16,6 +16,10 @@ SET(TRINITY_SRC_DIR ${TRINITY_REPO_ROOT}/src)
|
|||
SET(TRINITY_C_DIR ${TRINITY_SRC_DIR}/Trinity.C)
|
||||
SET(TRINITY_NUGET_EXE ${TRINITY_TOOLS_DIR}/NuGet.exe)
|
||||
|
||||
SET(RXCPP_DIR ${TRINITY_SRC_DIR}/RxCpp)
|
||||
SET(RX_INCLUDE_DIR ${RXCPP_DIR}/RxCpp/Rx/v2/src/rxcpp)
|
||||
SET(IX_INCLUDE_DIR ${RXCPP_DIR}/Ix/CPP/src/cpplinq)
|
||||
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TRINITY_OUTPUT_DIR})
|
||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${TRINITY_OUTPUT_DIR})
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${TRINITY_OUTPUT_DIR})
|
||||
|
@ -28,15 +32,16 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${TRINITY_OUTPUT_DIR})
|
|||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${TRINITY_OUTPUT_DIR})
|
||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${TRINITY_OUTPUT_DIR})
|
||||
|
||||
IF(WIN32 AND NOT EXISTS ${TRINITY_NUGET_EXE})
|
||||
FILE(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${TRINITY_NUGET_EXE})
|
||||
ENDIF()
|
||||
|
||||
IF(WIN32)
|
||||
SET(CMAKE_CXX_FLAGS "/volatile:iso /EHa /fp:except- /Zi /Gy /MP /W3 /DEBUG")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "/Oi /Ot /Ob2 /Oy /O2 /MT /GS- /GL")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "/Od /MTd /GS")
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "/LTCG /OPT:REF /OPT:ICF /SUBSYSTEM:WINDOWS /INCREMENTAL:NO")
|
||||
|
||||
IF(NOT EXISTS ${TRINITY_NUGET_EXE})
|
||||
FILE(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${TRINITY_NUGET_EXE})
|
||||
ENDIF()
|
||||
# SET(CMAKE_SHARED_LINKER_FLAGS "/LTCG /OPT:REF /OPT:ICF /SUBSYSTEM:WINDOWS /INCREMENTAL:NO")
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "/LTCG /OPT:REF /OPT:ICF /SUBSYSTEM:WINDOWS /INCREMENTAL")
|
||||
ELSEIF(UNIX)
|
||||
ADD_COMPILE_OPTIONS(-fpermissive -Wall -Wno-write-strings -Wno-unknown-pragmas -pthread)
|
||||
ELSE()
|
||||
|
|
|
@ -5,9 +5,9 @@ cmake_minimum_required (VERSION 3.0.0)
|
|||
|
||||
INCLUDE_DIRECTORIES(${TRINITY_C_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(${TRINITY_C_DIR}/include)
|
||||
INCLUDE_DIRECTORIES(${IX_INCLUDE_DIR})
|
||||
FILE(GLOB_RECURSE SRCS *.cpp)
|
||||
FILE(DOWNLOAD https://raw.githubusercontent.com/dotnet/coreclr/master/src/pal/prebuilt/inc/mscoree.h ${CMAKE_CURRENT_SOURCE_DIR}/mscoree.h)
|
||||
ADD_DEFINITIONS(-DTRINITYC_EXPORTS)
|
||||
|
||||
ADD_LIBRARY(trinity_host SHARED ${SRCS})
|
||||
TARGET_INCLUDE_DIRECTORIES(trinity_host PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#include <io>
|
||||
#include "GraphEngine.Hosting.h"
|
||||
#include "mscoree.h"
|
||||
#include <linq.hpp>
|
||||
|
||||
using namespace cpplinq;
|
||||
using namespace Trinity;
|
||||
|
||||
#if defined(TRINITY_PLATFORM_WINDOWS)
|
||||
|
@ -21,7 +23,8 @@ static const String coreCLRDll("libcoreclr.dylib");
|
|||
String withstr(std::function<DWORD(const Array<u16char>&)> fn)
|
||||
{
|
||||
Array<u16char> charray(MAX_LONGPATH);
|
||||
return String::FromWcharArray(charray, fn(charray));
|
||||
auto len = fn(charray);
|
||||
return String::FromWcharArray(charray, len);
|
||||
}
|
||||
|
||||
// Encapsulates the environment that CoreCLR will run in, including the TPALIST
|
||||
|
@ -57,15 +60,50 @@ class HostEnvironment
|
|||
// The path to the directory that CoreCLR is in
|
||||
String m_coreCLRDirectoryPath;
|
||||
|
||||
List<String> GetCoreCLRPaths()
|
||||
{
|
||||
auto base_path =
|
||||
from(Environment::Run("dotnet --info"))
|
||||
.where([](auto &p) {return p.Contains("Base Path:"); })
|
||||
.first_or_default();
|
||||
auto idx = base_path.IndexOf(':');
|
||||
if (idx == String::npos)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
else
|
||||
{
|
||||
base_path = base_path.Substring(idx + 1).Trim();
|
||||
if (base_path.Empty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (*base_path.rbegin() == Path::DirectorySeparator)
|
||||
{
|
||||
base_path.PopBack();
|
||||
}
|
||||
|
||||
base_path = Path::GetParent(Path::GetParent(base_path));
|
||||
base_path = Path::Combine(base_path, "shared", "Microsoft.NETCore.App");
|
||||
return
|
||||
from(Directory::GetDirectories(base_path))
|
||||
.select(Path::GetFileName)
|
||||
// TODO proper version validation
|
||||
.where([](auto& p) { return p.StartsWith("2."); })
|
||||
.select([&](auto& p) { return Path::Combine(base_path, p); })
|
||||
.to_vector();
|
||||
//Path::GetDirectoryName
|
||||
}
|
||||
}
|
||||
|
||||
// Attempts to load CoreCLR.dll from the given directory.
|
||||
// On success pins the dll, sets m_coreCLRDirectoryPath and returns the HMODULE.
|
||||
// On failure returns nullptr.
|
||||
HMODULE TryLoadCoreCLR(const String& directoryPath)
|
||||
{
|
||||
String coreCLRPath(directoryPath);
|
||||
coreCLRPath.Append(coreCLRDll);
|
||||
|
||||
HMODULE result = ::LoadLibraryExW(coreCLRPath.ToWcharArray(), NULL, 0);
|
||||
String coreCLRPath = Path::Combine(directoryPath, coreCLRDll);
|
||||
HMODULE result = ::LoadLibraryExW(coreCLRPath.ToWcharArray(), NULL, 0);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
|
@ -85,12 +123,19 @@ class HostEnvironment
|
|||
TrinityErrorCode _Init()
|
||||
{
|
||||
// Discover the path to this exe's module. All other files are expected to be in the same directory.
|
||||
m_hostPath = withstr([](auto charray) { return ::GetModuleFileNameW(::GetModuleHandleW(nullptr), (LPWSTR)charray.data(), MAX_LONGPATH); });
|
||||
m_hostPath = withstr([](const Array<u16char>& charray) { return ::GetModuleFileNameW(NULL, (LPWSTR)charray.data(), MAX_LONGPATH); });
|
||||
m_hostDirectoryPath = Path::GetDirectoryName(m_hostPath);
|
||||
m_hostExeName = Path::GetFileName(m_hostPath);
|
||||
|
||||
//TODO guess coreclr path
|
||||
m_coreCLRModule = TryLoadCoreCLR(m_hostDirectoryPath);
|
||||
for (auto& coreCLRPath : GetCoreCLRPaths())
|
||||
{
|
||||
m_coreCLRModule = TryLoadCoreCLR(coreCLRPath);
|
||||
if (m_coreCLRModule)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_coreCLRModule)
|
||||
{
|
||||
|
@ -309,7 +354,7 @@ public:
|
|||
IN const String& entryAsm,
|
||||
IN const String& entryClass,
|
||||
IN const String& entryMethod,
|
||||
OUT TrinityErrorCode& eresult) :
|
||||
OUT TrinityErrorCode& eresult) :
|
||||
m_CLRRuntimeHost(nullptr),
|
||||
m_coreCLRModule(nullptr),
|
||||
m_appPaths(appPaths),
|
||||
|
@ -412,7 +457,7 @@ TrinityErrorCode GraphEngineInit_impl(
|
|||
OUT void*& lpenv)
|
||||
{
|
||||
TrinityErrorCode err;
|
||||
String apppaths = String::Join(";", Array<String> (n_apppaths, [&](auto i) { return String::FromWcharArray(lp_apppaths[i], wcslen(lp_apppaths[i])); }));
|
||||
String apppaths = String::Join(";", Array<String>(n_apppaths, [&](auto i) { return String::FromWcharArray(lp_apppaths[i], wcslen(lp_apppaths[i])); }));
|
||||
String entry_asm = String::FromWcharArray(lp_entry_asm, wcslen(lp_entry_asm));
|
||||
String entry_class = String::FromWcharArray(lp_entry_class, wcslen(lp_entry_class));
|
||||
String entry_method = String::FromWcharArray(lp_entry_method, wcslen(lp_entry_method));
|
||||
|
@ -440,7 +485,7 @@ DLL_EXPORT TrinityErrorCode GraphEngineUninit(
|
|||
{
|
||||
return TrinityErrorCode::E_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
|
||||
auto lpenv = reinterpret_cast<const HostEnvironment*>(_lpenv);
|
||||
|
||||
ICLRRuntimeHost4* host = lpenv->GetCLRRuntimeHost();
|
||||
|
|
|
@ -4,8 +4,11 @@ namespace Trinity.Hosting
|
|||
{
|
||||
public class Initializer
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
public static int Init()
|
||||
{
|
||||
Console.WriteLine("Hello from selfhost CLR!");
|
||||
Console.ReadKey();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,7 @@ cmake_minimum_required (VERSION 3.0.0)
|
|||
|
||||
INCLUDE_DIRECTORIES(${TRINITY_C_DIR}/include)
|
||||
INCLUDE_DIRECTORIES(${TRINITY_C_DIR}/src)
|
||||
INCLUDE_DIRECTORIES(../trinity_host)
|
||||
FILE(GLOB_RECURSE SRCS *.cpp)
|
||||
|
||||
TARGET_LINK_LIBRARIES(trinity_host)
|
||||
|
||||
ADD_EXECUTABLE (trinity_host_test ${SRCS})
|
||||
ADD_EXECUTABLE (trinity_host_test ${SRCS})
|
||||
TARGET_LINK_LIBRARIES(trinity_host_test trinity_host)
|
|
@ -3,5 +3,13 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
void* lpenv;
|
||||
printf("GraphEngineInit result = %d\n",
|
||||
GraphEngineInit(0, nullptr,
|
||||
L"D:\git\GraphEngine\src\GraphEngine\trinity_host_dummy\bin\Debug\netstandard2.0\trinity_host_dummy.dll",
|
||||
L"Trinity.Hosting.Initializer",
|
||||
L"Init",
|
||||
lpenv));
|
||||
printf("GraphEngineUninit result = %d\n", GraphEngineUninit(lpenv));
|
||||
return 0;
|
||||
}
|
|
@ -13,6 +13,7 @@ INCLUDE_DIRECTORIES(
|
|||
# TODO handle coreclr vs netfx
|
||||
# Now we just go with Trinity(coreclr)
|
||||
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE)
|
||||
ADD_LIBRARY(GraphEngine.Jit.Native SHARED ${jit_src} ${asmjit_src})
|
||||
TARGET_COMPILE_DEFINITIONS(GraphEngine.Jit.Native PRIVATE -DASMJIT_EMBED -DASMJIT_RELEASE -DGRAPHENGINEJITNATIVE_EXPORTS)
|
||||
TARGET_LINK_LIBRARIES(GraphEngine.Jit.Native Trinity)
|
||||
|
|
|
@ -394,6 +394,8 @@ namespace Mixin
|
|||
cc.mov(ret, imm(plan[0]));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void seek(X86Compiler& cc, FuncCtx& ctx, Label& l_outofrange, Label& l_resize, X86Gp& idx, X86Gp& ptr, TypeCode tc, TypeId::Id tid, std::vector<int32_t> &plan)
|
||||
|
|
|
@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES(
|
|||
)
|
||||
|
||||
FILE(GLOB SRCS *.cpp)
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE)
|
||||
ADD_LIBRARY(trinity_ffi SHARED ${SRCS})
|
||||
TARGET_COMPILE_DEFINITIONS(trinity_ffi PRIVATE -DTRINITYFFINATIVE_EXPORTS)
|
||||
TARGET_LINK_LIBRARIES(trinity_ffi Trinity)
|
||||
|
|
|
@ -26,10 +26,10 @@ SET(DEPS ${pysrc} ${swigi} ${typesys} ${swigh} Trinity GraphEng
|
|||
|
||||
IF (PYTHON AND SWIG)
|
||||
IF(WIN32)
|
||||
SET(ext_cxx_flags "['/Zi']")
|
||||
SET(ext_cxx_flags "['/Zi', '/D_CRT_SECURE_NO_WARNINGS', '/DUNICODE', '/D_UNICODE']")
|
||||
SET(ext_linker_flags "['/DEBUG']")
|
||||
ELSE()
|
||||
SET(ext_cxx_flags "['--std=c++14', '-fpermissive']")
|
||||
SET(ext_cxx_flags "['--std=c++14', '-fpermissive', '-D_CRT_SECURE_NO_WARNINGS', '-DUNICODE', '-D_UNICODE']")
|
||||
SET(ext_linker_flags "[]")
|
||||
ENDIF()
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.1.33
|
||||
0.2.8
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1e9312fc7eba8e78719f68d2d6743cf8ecce0e85
|
|
@ -6,6 +6,7 @@
|
|||
#include "String.h"
|
||||
#include <cstdint>
|
||||
#include <os/os.h>
|
||||
#include <Trinity/Collections/List.h>
|
||||
|
||||
#if !defined(TRINITY_PLATFORM_WINDOWS)
|
||||
#include <thread>
|
||||
|
@ -65,5 +66,26 @@ namespace Trinity
|
|||
return std::thread::hardware_concurrency();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline List<String> Run(const char* command)
|
||||
{
|
||||
List<String> ret;
|
||||
Array<char> lplinebuf(1024);
|
||||
FILE* pspipe = _popen(command, "r");
|
||||
|
||||
if (nullptr == pspipe)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (fgets(lplinebuf, lplinebuf.Length(), pspipe))
|
||||
{
|
||||
ret.push_back(String(lplinebuf));
|
||||
}
|
||||
|
||||
_pclose(pspipe);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ namespace Trinity
|
|||
{
|
||||
String GetFullPath(const String&);
|
||||
String GetDirectoryName(const String&);
|
||||
template<typename ...Args> String Combine(const Args& ...paths);
|
||||
}
|
||||
namespace Directory
|
||||
{
|
||||
|
@ -25,7 +26,7 @@ namespace Trinity
|
|||
if (-1 != access(path.c_str(), F_OK))
|
||||
{
|
||||
DIR* pdir;
|
||||
if((pdir = opendir(path.c_str())) != NULL)
|
||||
if ((pdir = opendir(path.c_str())) != NULL)
|
||||
{
|
||||
closedir(pdir);
|
||||
return true;
|
||||
|
@ -52,6 +53,37 @@ namespace Trinity
|
|||
return false;
|
||||
return Create(path);
|
||||
}
|
||||
inline List<String> GetDirectories(const String& path)
|
||||
{
|
||||
List<String> ret;
|
||||
|
||||
#if defined(TRINITY_PLATFORM_WINDOWS)
|
||||
|
||||
WIN32_FIND_DATA find_data;
|
||||
HANDLE hfind = FindFirstFile(Path::Combine(path, "*").ToWcharArray(),
|
||||
&find_data);
|
||||
|
||||
if (hfind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
ret.push_back(Path::Combine(path, String::FromWcharArray(find_data.cFileName, String::npos)));
|
||||
}
|
||||
} while (FindNextFile(hfind, &find_data) != 0);
|
||||
FindClose(hfind);
|
||||
|
||||
#else
|
||||
|
||||
//TODO(
|
||||
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -113,6 +113,16 @@ namespace Trinity
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline String GetParent(const String& path)
|
||||
{
|
||||
String ret(path);
|
||||
if (ret.Length() > 0 && *ret.rbegin() == DirectorySeparator)
|
||||
{
|
||||
ret.PopBack();
|
||||
}
|
||||
return Path::GetDirectoryName(ret);
|
||||
}
|
||||
|
||||
inline String GetFileName(const String& path)
|
||||
{
|
||||
size_t len = path.Length();
|
||||
|
|
|
@ -54,3 +54,5 @@ int GetLastError();
|
|||
#define DLL_IMPORT extern "C" __attribute__ ((visibility ("default")))
|
||||
#define THREAD_LOCAL thread_local
|
||||
#define _strdup strdup
|
||||
#define _popen popen
|
||||
#define _pclose pclose
|
||||
|
|
|
@ -4,6 +4,7 @@ PROJECT(Trinity.TSL)
|
|||
|
||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/../Trinity.C/include/)
|
||||
|
||||
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE)
|
||||
ADD_SUBDIRECTORY(Trinity.TSL.Parser)
|
||||
ADD_SUBDIRECTORY(Trinity.TSL.CodeGen)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче