Skip to content

Commit

Permalink
make rapidjson and lsp optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitaS11 committed Jul 7, 2022
1 parent 423bed3 commit acfec94
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ if (WITH_XEUS)
PATTERN "*.in" EXCLUDE)
endif()

# JSON
# JSON OR LSP (`conda install rapidjson`)
set(WITH_JSON no CACHE BOOL "Build with JSON support")
if (WITH_JSON)
set(WITH_LSP no CACHE BOOL "Build with LSP support")
if (WITH_JSON OR WITH_LSP)
find_package(RapidJSON REQUIRED)
set(HAVE_LFORTRAN_RAPIDJSON yes)
endif()

set(HAVE_LFORTRAN_DEMANGLE yes
Expand Down Expand Up @@ -262,6 +264,7 @@ message("HAVE_LFORTRAN_DEMANGLE: ${HAVE_LFORTRAN_DEMANGLE}")
message("WITH_LLVM: ${WITH_LLVM}")
message("WITH_XEUS: ${WITH_XEUS}")
message("WITH_JSON: ${WITH_JSON}")
message("WITH_LSP: ${WITH_LSP}")
message("WITH_FMT: ${WITH_FMT}")
message("WITH_LFORTRAN_BINARY_MODFILES: ${WITH_LFORTRAN_BINARY_MODFILES}")
message("WITH_RUNTIME_LIBRARY: ${WITH_RUNTIME_LIBRARY}")
Expand Down
13 changes: 10 additions & 3 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
#include <lpython/python_serialization.h>
#include <lpython/parser/tokenizer.h>
#include <lpython/parser/parser.h>
#include <libasr/lsp/LPythonServer.hpp>

#ifdef HAVE_LFORTRAN_RAPIDJSON
#include <libasr/lsp/LPythonServer.hpp>
#endif

#include <cpp-terminal/terminal.h>
#include <cpp-terminal/prompt0.h>
Expand Down Expand Up @@ -762,8 +765,12 @@ int main(int argc, char *argv[])
}

if (lsp) {
LPythonServer().run(arg_lsp_filename);
return 0;
#ifdef HAVE_LFORTRAN_RAPIDJSON
LPythonServer().run(arg_lsp_filename);
return 0;
#endif
} else {
std::cerr << "Compiler was not built with LSP support (-DWITH_LSP), please build it again.\n";
}

if (arg_backend == "llvm") {
Expand Down
14 changes: 11 additions & 3 deletions src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ set(SRC
pass/loop_unroll.cpp
pass/dead_code_removal.cpp

lsp/JSONRPC2Connection.cpp
lsp/LPythonServer.cpp

asr_verify.cpp
asr_utils.cpp
diagnostics.cpp
Expand Down Expand Up @@ -79,6 +76,14 @@ if (WITH_LLVM)
COMPILE_FLAGS -Wno-deprecated-declarations)
endif()
endif()

if (WITH_LSP)
set (SRC ${SRC}
lsp/JSONRPC2Connection.cpp
lsp/LPythonServer.cpp
)
endif()

add_library(asr ${SRC})
target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
Expand All @@ -94,3 +99,6 @@ endif()
if (WITH_LLVM)
target_link_libraries(asr p::llvm)
endif()
if (WITH_LSP)
add_subdirectory(lsp)
endif()
3 changes: 3 additions & 0 deletions src/libasr/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
/* Define if LLVM is enabled */
#cmakedefine HAVE_LFORTRAN_LLVM

/* Define if RAPIDJSON is found */
#cmakedefine HAVE_LFORTRAN_RAPIDJSON

/* Define if stacktrace is enabled */
#cmakedefine HAVE_LFORTRAN_STACKTRACE
#cmakedefine HAVE_LFORTRAN_BFD
Expand Down
65 changes: 65 additions & 0 deletions src/libasr/lsp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
project(lsp)
add_library(lsp ${lsp_SOURCE_DIR})

if (NOT HAVE_LFORTRAN_RAPIDJSON)
message(FATAL_ERROR "Expected RapidJSON to be found, but couldn't find it in the path.")
endif()
# TODO: Removing all the following commented out code for now, @certik - can you please confirm if none of this is required?
# target_include_directories(lsp PRIVATE "tpl")
# target_link_libraries(lsp lpython_lib)
# find_package(RapidJSON REQUIRED)
# # message(STATUS "Found RapidJSON version: ${RapidJSON_PACKAGE_VERSION}")

# if (lsp_STATIC_BIN)
# if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# # Link statically on Linux with gcc or clang
# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
# CMAKE_CXX_COMPILER_ID MATCHES Clang)
# target_link_options(lsp PRIVATE -static)
# endif()
# endif()
# endif()

# if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# target_link_options(lsp PRIVATE "LINKER:--export-dynamic")
# endif()

# set_target_properties(lsp PROPERTIES RUNTIME_OUTPUT_DIRECTORY $<0:>)

# set_target_properties(lsp PROPERTIES
# INSTALL_RPATH_USE_LINK_PATH TRUE
# )

# install(TARGETS lsp
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# ARCHIVE DESTINATION share/lpython_lib/lib
# LIBRARY DESTINATION share/lpython_lib/lib
# )

# set_target_properties(lsp PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
# ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>)

# target_link_libraries(lsp asr lpython_runtime_static ZLIB::ZLIB)
# target_include_directories(lsp PRIVATE ${lsp_SOURCE_DIR}/src/bin/tpl)
# target_include_directories(lsp BEFORE PUBLIC ${lsp_SOURCE_DIR}/src)
# target_include_directories(lsp BEFORE PUBLIC ${lsp_BINARY_DIR}/src)

# target_link_libraries(lsp p::rapidjson)

if (WITH_XEUS)
target_link_libraries(lsp xeus)
endif()
if (WITH_BFD)
target_link_libraries(lsp p::bfd)
endif()
if (WITH_LINK)
target_link_libraries(lsp p::link)
endif()
if (WITH_EXECINFO)
target_link_libraries(lsp p::execinfo)
endif()
if (WITH_LLVM)
target_link_libraries(lsp p::llvm)
endif()

0 comments on commit acfec94

Please sign in to comment.