Fix build errors on Linux

This commit is contained in:
2022-11-26 23:20:13 +02:00
parent 89ac54520a
commit 3b80a01813
6 changed files with 25 additions and 28 deletions

View File

@@ -32,6 +32,8 @@
#pragma clang diagnostic ignored "-Wnull-dereference"
#pragma clang diagnostic ignored "-Winvalid-noreturn"
#define SCRIPTING_EXPORT(name)
#elif defined(__GNUC__)
#define DLLEXPORT __attribute__ ((__visibility__ ("default")))
@@ -86,6 +88,8 @@
#pragma warning(disable: 4251)
#define SCRIPTING_EXPORT(name) __pragma(comment(linker, "/EXPORT:" #name "=" __FUNCDNAME__))
#else
#pragma error "Unknown compiler."
@@ -93,14 +97,3 @@
#endif
#define PACK_STRUCT(__Declaration__) PACK_BEGIN() __Declaration__ PACK_END()
#define SCRIPTING_EXPORT(name) __pragma(comment(linker, "/EXPORT:" #name "=" __FUNCDNAME__))
#define SCRIPTING_EXPORT_DEBUG(name) __pragma(message("/EXPORT:" #name "=" __FUNCDNAME__)) \
__pragma(comment(linker, "/EXPORT:" #name "=" __FUNCDNAME__))
// TODO: try this one with clang:
//#ifdef _MSC_VER
//#define SCRIPTING_EXPORT(name) __pragma(comment(linker, "/EXPORT:" #name "=" __FUNCDNAME__))
//#endif
//#ifdef __GNUC__
//#define SCRIPTING_EXPORT(name) asm(".section .drectve\n\t.ascii \" -export:" #name "=" __FUNCDNAME__ "\"");
//#endif

View File

@@ -20,13 +20,13 @@
#if COMPILE_WITH_PROFILER
#endif
namespace CoreCLRPrivate
{
}
static Dictionary<String, void*> cachedFunctions;
static String assemblyName = TEXT("FlaxEngine.CSharp");
static Char* typeName = TEXT("FlaxEngine.NativeInterop, FlaxEngine.CSharp");
#if PLATFORM_WINDOWS
static const char_t* typeName = TEXT("FlaxEngine.NativeInterop, FlaxEngine.CSharp");
#else
static const char_t* typeName = "FlaxEngine.NativeInterop, FlaxEngine.CSharp";
#endif
hostfxr_initialize_for_runtime_config_fn hostfxr_initialize_for_runtime_config;
hostfxr_initialize_for_dotnet_command_line_fn hostfxr_initialize_for_dotnet_command_line;
@@ -38,9 +38,9 @@ hostfxr_set_error_writer_fn hostfxr_set_error_writer;
hostfxr_get_dotnet_environment_info_result_fn hostfxr_get_dotnet_environment_info_result;
hostfxr_run_app_fn hostfxr_run_app;
bool CoreCLR::LoadHostfxr(const String& library_path)
bool CoreCLR::LoadHostfxr(const String& library_path_)
{
Platform::SetEnvironmentVariable(TEXT("DOTNET_MULTILEVEL_LOOKUP"), TEXT("0")); // FIXME: not needed with .NET 7
const FLAX_CORECLR_STRING& library_path = FLAX_CORECLR_STRING(library_path_);
Platform::SetEnvironmentVariable(TEXT("DOTNET_TieredPGO"), TEXT("1"));
Platform::SetEnvironmentVariable(TEXT("DOTNET_TC_QuickJitForLoops"), TEXT("1"));
@@ -60,9 +60,10 @@ bool CoreCLR::LoadHostfxr(const String& library_path)
LOG(Error, "Failed to find hostfxr: {0:x}", (unsigned int)rc);
return false;
}
LOG(Info, "Found hostfxr in {0}", hostfxrPath);
String path(hostfxrPath);
LOG(Info, "Found hostfxr in {0}", path);
void *hostfxr = Platform::LoadLibrary(hostfxrPath);
void *hostfxr = Platform::LoadLibrary(path.Get());
hostfxr_initialize_for_runtime_config = (hostfxr_initialize_for_runtime_config_fn)Platform::GetProcAddress(hostfxr, "hostfxr_initialize_for_runtime_config");
hostfxr_initialize_for_dotnet_command_line = (hostfxr_initialize_for_dotnet_command_line_fn)Platform::GetProcAddress(hostfxr, "hostfxr_initialize_for_dotnet_command_line");
hostfxr_get_runtime_delegate = (hostfxr_get_runtime_delegate_fn)Platform::GetProcAddress(hostfxr, "hostfxr_get_runtime_delegate");
@@ -74,9 +75,10 @@ bool CoreCLR::LoadHostfxr(const String& library_path)
return true;
}
bool CoreCLR::InitHostfxr(const String& config_path, const String& library_path)
bool CoreCLR::InitHostfxr(const String& config_path, const String& library_path_)
{
const wchar_t* argv[1] = { library_path.Get() };
const FLAX_CORECLR_STRING& library_path = FLAX_CORECLR_STRING(library_path_);
const char_t* argv[1] = { library_path.Get() };
hostfxr_initialize_parameters params;
params.size = sizeof(hostfxr_initialize_parameters);
@@ -115,7 +117,7 @@ void* CoreCLR::GetFunctionPointerFromDelegate(const String& methodName)
String delegateTypeName = String::Format(TEXT("{0}+{1}Delegate, {2}"), TEXT("FlaxEngine.NativeInterop"), methodName, assemblyName);
int rc = get_function_pointer(typeName, methodName.Get(), delegateTypeName.Get(), nullptr, nullptr, &fun);
int rc = get_function_pointer(typeName, FLAX_CORECLR_STRING(methodName).Get(), FLAX_CORECLR_STRING(delegateTypeName).Get(), nullptr, nullptr, &fun);
if (rc != 0)
LOG(Fatal, "Failed to get unmanaged function pointer for method {0}: 0x{1:x}", methodName.Get(), (unsigned int)rc);
@@ -130,7 +132,7 @@ void* CoreCLR::GetStaticMethodPointer(const String& methodName)
if (cachedFunctions.TryGet(methodName, fun))
return fun;
int rc = get_function_pointer(typeName, methodName.Get(), UNMANAGEDCALLERSONLY_METHOD, nullptr, nullptr, &fun);
int rc = get_function_pointer(typeName, FLAX_CORECLR_STRING(methodName).Get(), UNMANAGEDCALLERSONLY_METHOD, nullptr, nullptr, &fun);
if (rc != 0)
LOG(Fatal, "Failed to get unmanaged function pointer for method {0}: 0x{1:x}", methodName.Get(), (unsigned int)rc);

View File

@@ -8,8 +8,10 @@
#if defined(_WIN32)
#define CORECLR_DELEGATE_CALLTYPE __stdcall
#define FLAX_CORECLR_STRING String
#else
#define CORECLR_DELEGATE_CALLTYPE
#define FLAX_CORECLR_STRING StringAnsi
#endif
class CoreCLR

View File

@@ -658,7 +658,7 @@ MONO_API MonoString* mono_string_empty(MonoDomain* domain)
MONO_API MONO_RT_EXTERNAL_ONLY MonoString* mono_string_new_utf16(MonoDomain* domain, const mono_unichar2* text, int32_t len)
{
return (MonoString*)CoreCLR::CallStaticMethodInternal<void*, const wchar_t*, int>(TEXT("NewStringUTF16"), text, len);
return (MonoString*)CoreCLR::CallStaticMethodInternal<void*, const mono_unichar2*, int>(TEXT("NewStringUTF16"), text, len);
}
MONO_API MONO_RT_EXTERNAL_ONLY MonoString* mono_string_new(MonoDomain* domain, const char* text)
@@ -673,7 +673,7 @@ MONO_API MONO_RT_EXTERNAL_ONLY MonoString* mono_string_new_len(MonoDomain* domai
MONO_API MONO_RT_EXTERNAL_ONLY char* mono_string_to_utf8(MonoString* string_obj)
{
Char* strw = string_obj != nullptr ? mono_string_chars(string_obj) : nullptr;
Char* strw = string_obj != nullptr ? (Char*)mono_string_chars(string_obj) : nullptr;
auto len = string_obj != nullptr ? mono_string_length(string_obj) : 0;
ASSERT(len >= 0)
char* stra = (char*)CoreCLR::Allocate(sizeof(char) * (len + 1));

View File

@@ -135,7 +135,7 @@ bool MCore::LoadEngine()
LOG(Fatal, "LoadAssembly failed");
const String hostExecutable = Platform::GetExecutableFilePath();
CoreCLR::CallStaticMethodInternal<void, const wchar_t*>(TEXT("Init"), hostExecutable.Get());
CoreCLR::CallStaticMethodInternal<void, const Char*>(TEXT("Init"), hostExecutable.Get());
MRootDomain = New<MDomain>("Root");
MDomains.Add(MRootDomain);