diff --git a/CMakeLists.txt b/CMakeLists.txt index 4255c7c2..19c29ae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,13 @@ endif() cmake_minimum_required(VERSION 3.0) -option(LUAU_BUILD_CLI "Build CLI" ON) -option(LUAU_BUILD_TESTS "Build tests" ON) +option(LUAU_BUILD_CLI "Build CLI" OFF) +option(LUAU_BUILD_TESTS "Build tests" OFF) option(LUAU_BUILD_WEB "Build Web module" OFF) option(LUAU_WERROR "Warnings as errors" OFF) option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF) -option(LUAU_EXTERN_C "Use extern C for all APIs" OFF) +option(LUAU_EXTERN_C "Use extern C for all APIs" ON) +option(LUAU_EXPORT_DLL "Exports to DLL with C linkage" ON) option(LUAU_NATIVE "Enable support for native code generation" OFF) if(LUAU_STATIC_CRT) @@ -23,11 +24,20 @@ endif() project(Luau LANGUAGES CXX C) add_library(Luau.Common INTERFACE) add_library(Luau.Ast STATIC) -add_library(Luau.Compiler STATIC) -add_library(Luau.Analysis STATIC) -add_library(Luau.CodeGen STATIC) -add_library(Luau.VM STATIC) -add_library(isocline STATIC) + +if(LUAU_EXPORT_DLL) + add_library(Luau.Compiler SHARED) + add_library(Luau.Analysis SHARED) + add_library(Luau.CodeGen SHARED) + add_library(Luau.VM SHARED) + add_library(isocline SHARED) +else() + add_library(Luau.Compiler STATIC) + add_library(Luau.Analysis STATIC) + add_library(Luau.CodeGen STATIC) + add_library(Luau.VM STATIC) + add_library(isocline STATIC) +endif() if(LUAU_BUILD_CLI) add_executable(Luau.Repl.CLI) @@ -128,9 +138,20 @@ target_compile_options(isocline PRIVATE ${LUAU_OPTIONS} ${ISOCLINE_OPTIONS}) if(LUAU_EXTERN_C) # enable extern "C" for VM (lua.h, lualib.h) and Compiler (luacode.h) to make Luau friendlier to use from non-C++ languages # note that we enable LUA_USE_LONGJMP=1 as well; otherwise functions like luaL_error will throw C++ exceptions, which can't be done from extern "C" functions + # LUAU_EXPORT_DLL exists to make Luau useable from non-C++ languages properly that cant rely on `extern` target_compile_definitions(Luau.VM PUBLIC LUA_USE_LONGJMP=1) - target_compile_definitions(Luau.VM PUBLIC LUA_API=extern\"C\") - target_compile_definitions(Luau.Compiler PUBLIC LUACODE_API=extern\"C\") + if(LUAU_EXPORT_DLL) + target_compile_definitions(Luau.VM PUBLIC LUA_API_C_EXPORT) + target_compile_definitions(Luau.Compiler PUBLIC LUACOPDE_API_C_EXPORT) + else() + target_compile_definitions(Luau.VM PUBLIC LUA_API=extern\"C\") + target_compile_definitions(Luau.Compiler PUBLIC LUACODE_API=extern\"C\") + endif() +else() + if(LUAU_EXPORT_DLL) + target_compile_definitions(Luau.VM PUBLIC LUA_API_EXPORT) + target_compile_definitions(Luau.Compiler PUBLIC LUACOPDE_API_EXPORT) + endif() endif() if(LUAU_NATIVE) diff --git a/Compiler/include/luacode.h b/Compiler/include/luacode.h index 5f69f69e..a542ada0 100644 --- a/Compiler/include/luacode.h +++ b/Compiler/include/luacode.h @@ -3,6 +3,15 @@ #include +// Can be used to export public APIs to DLL +#ifdef LUA_API_C_EXPORT +#define LUACODE_API extern "C" __declspec(dllexport) +#endif + +#ifdef LUA_API_EXPORT +#define LUACODE_API extern __declspec(dllexport) +#endif + // Can be used to reconfigure visibility/exports for public APIs #ifndef LUACODE_API #define LUACODE_API extern diff --git a/VM/include/luaconf.h b/VM/include/luaconf.h index dcf56923..fba920e9 100644 --- a/VM/include/luaconf.h +++ b/VM/include/luaconf.h @@ -33,6 +33,15 @@ #define LUA_NORETURN __attribute__((__noreturn__)) #endif +// Can be used to export public APIs to DLL +#ifdef LUA_API_C_EXPORT +#define LUA_API extern "C" __declspec(dllexport) +#endif + +#ifdef LUA_API_EXPORT +#define LUA_API extern __declspec(dllexport) +#endif + // Can be used to reconfigure visibility/exports for public APIs #ifndef LUA_API #define LUA_API extern