From 1bff6154e6916d6fca0115dad88cd1c1821df4ab Mon Sep 17 00:00:00 2001 From: Pelanyo Kamara Date: Mon, 8 Nov 2021 16:47:21 +0000 Subject: [PATCH] Remove Luau.REPL.Web target. --- CLI/Repl.cpp | 76 ++++++++++++++++++++++++++------------------------ CMakeLists.txt | 70 ++++++++++++++++++---------------------------- Sources.cmake | 10 ------- 3 files changed, 67 insertions(+), 89 deletions(-) diff --git a/CLI/Repl.cpp b/CLI/Repl.cpp index 44217243..a0c74016 100644 --- a/CLI/Repl.cpp +++ b/CLI/Repl.cpp @@ -194,6 +194,46 @@ static std::string runCode(lua_State* L, const std::string& source) return std::string(); } +#ifdef __EMSCRIPTEN__ +extern "C" +{ + // Luau errors are exceptions (see luaD_throw) which cannot be directly + // handled by emscripten. However we can recieve the pointer in JS and + // pass it through to this method to get the string content of the + // exception. + const char* getExceptionFromPtr(int ptr) + { + return reinterpret_cast(ptr)->what(); + } + + void executeScript(const char* source) + { + // setup flags + for (Luau::FValue* flag = Luau::FValue::list; flag; flag = flag->next) + if (strncmp(flag->name, "Luau", 4) == 0) + flag->value = true; + + // create new state + std::unique_ptr globalState(luaL_newstate(), lua_close); + lua_State* L = globalState.get(); + + // setup state + setupState(L); + + // run code + collect error + std::string error = runCode(L, source); + + // output error(s) + if (error.length()) + { + fprintf(stdout, "%s\n", error.c_str()); + } + } +} +#endif + +// Excluded from emscripten compilation to avoid -Wunused-function errors. +#ifndef __EMSCRIPTEN__ static void completeIndexer(lua_State* L, const char* editBuffer, size_t start, std::vector& completions) { std::string_view lookup = editBuffer + start; @@ -253,41 +293,6 @@ static void completeRepl(lua_State* L, const char* editBuffer, std::vector(ptr)->what(); - } - - void executeScript(const char* source) - { - std::unique_ptr globalState(luaL_newstate(), lua_close); - lua_State* L = globalState.get(); - - setupState(L); - - luaL_sandboxthread(L); - - linenoise::SetCompletionCallback([L](const char* editBuffer, std::vector& completions) { - completeRepl(L, editBuffer, completions); - }); - - std::string error = runCode(L, source); - - if (error.length()) - { - fprintf(stdout, "%s\n", error.c_str()); - } - } -} -#endif - static void runRepl() { std::unique_ptr globalState(luaL_newstate(), lua_close); @@ -459,7 +464,6 @@ static int assertionHandler(const char* expr, const char* file, int line) return 1; } -#ifndef LUAU_WEB_REPL int main(int argc, char** argv) { Luau::assertHandler() = assertionHandler; diff --git a/CMakeLists.txt b/CMakeLists.txt index b72c630b..79c7ee31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,10 +6,8 @@ endif() cmake_minimum_required(VERSION 3.0) project(Luau LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) option(LUAU_BUILD_CLI "Build CLI" ON) -option(LUAU_BUILD_WEB_REPL "Build Web CLI" ON) option(LUAU_BUILD_TESTS "Build tests" ON) add_library(Luau.Ast STATIC) @@ -17,45 +15,23 @@ add_library(Luau.Compiler STATIC) add_library(Luau.Analysis STATIC) add_library(Luau.VM STATIC) -if(LUAU_BUILD_WEB_REPL AND EMSCRIPTEN) - # this is a hack, disable cli and tests since we're compiling using emscripten - set(LUAU_BUILD_CLI OFF) - set(LUAU_BUILD_TESTS OFF) - - add_definitions(-DLUAU_WEB_REPL) - - # luau web repl - add_executable(Luau.Repl.Web) - - # configuration below - target_compile_options(Luau.Repl.Web PRIVATE ${LUAU_OPTIONS}) - - target_include_directories(Luau.Repl.Web PRIVATE extern) - target_link_libraries(Luau.Repl.Web PRIVATE Luau.Compiler Luau.VM) - - if(UNIX) - target_link_libraries(Luau.Repl.Web PRIVATE pthread) +if(LUAU_BUILD_CLI) + add_executable(Luau.Repl.CLI) + if(NOT EMSCRIPTEN) + add_executable(Luau.Analyze.CLI) endif() - # declare exported functions to emscripten - target_link_options(Luau.Repl.Web PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING) + # This also adds target `name` on Linux/macOS and `name.exe` on Windows + set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau) - # custom output directory for webm + js file - set_target_properties(Luau.Repl.Web PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau) -else() - if(LUAU_BUILD_CLI) - add_executable(Luau.Repl.CLI) - add_executable(Luau.Analyze.CLI) - - # This also adds target `name` on Linux/macOS and `name.exe` on Windows - set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME luau) + if(NOT EMSCRIPTEN) set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME luau-analyze) endif() +endif() - if(LUAU_BUILD_TESTS) - add_executable(Luau.UnitTest) - add_executable(Luau.Conformance) - endif() +if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN) + add_executable(Luau.UnitTest) + add_executable(Luau.Conformance) endif() include(Sources.cmake) @@ -83,11 +59,6 @@ if(MSVC) else() list(APPEND LUAU_OPTIONS -Wall) # All warnings list(APPEND LUAU_OPTIONS -Werror) # Warnings are errors - - # temporary hot fix (removes need for commenting out line above when compiling with Clang) - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - list(APPEND LUAU_OPTIONS -Wno-unused) # GCC considers variables declared/checked in if() as unused - endif() endif() target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS}) @@ -96,7 +67,10 @@ target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS}) if(LUAU_BUILD_CLI) target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS}) - target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS}) + + if(NOT EMSCRIPTEN) + target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS}) + endif() target_include_directories(Luau.Repl.CLI PRIVATE extern) target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.VM) @@ -105,10 +79,20 @@ if(LUAU_BUILD_CLI) target_link_libraries(Luau.Repl.CLI PRIVATE pthread) endif() - target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis) + if(NOT EMSCRIPTEN) + target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis) + endif() + + if(EMSCRIPTEN) + # declare exported functions to emscripten + target_link_options(Luau.Repl.CLI PRIVATE -sEXPORTED_FUNCTIONS=['_getExceptionFromPtr','_executeScript'] -sEXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -sNO_DISABLE_EXCEPTION_CATCHING) + + # custom output directory for wasm + js file + set_target_properties(Luau.Repl.CLI PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/docs/assets/luau) + endif() endif() -if(LUAU_BUILD_TESTS) +if(LUAU_BUILD_TESTS AND NOT EMSCRIPTEN) target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS}) target_include_directories(Luau.UnitTest PRIVATE extern) target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Compiler) diff --git a/Sources.cmake b/Sources.cmake index a7f56aef..c30cf77d 100644 --- a/Sources.cmake +++ b/Sources.cmake @@ -160,16 +160,6 @@ if(TARGET Luau.Repl.CLI) CLI/Repl.cpp) endif() -if (TARGET Luau.Repl.Web) - # Luau.Repl.Web Sources - target_sources(Luau.Repl.Web PRIVATE - CLI/FileUtils.h - CLI/FileUtils.cpp - CLI/Profiler.h - CLI/Profiler.cpp - CLI/Repl.cpp) -endif() - if(TARGET Luau.Analyze.CLI) # Luau.Analyze.CLI Sources target_sources(Luau.Analyze.CLI PRIVATE