Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*[don't merge]* use Rcpp and RInside #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ if (NOT TARGET xeus AND NOT TARGET xeus-static)
endif ()
find_package(R REQUIRED)

message(STATUS "R_INCLUDE_DIR = ${R_INCLUDE_DIR}")
message(STATUS "R_LDFLAGS = ${R_LDFLAGS}")
message(STATUS "R_LIBRARY_BLAS = ${R_LIBRARY_BLAS}")
message(STATUS "R_LIBRARY_LAPACK = ${R_LIBRARY_LAPACK}")
message(STATUS "R_INCLUDE_DIR = ${R_INCLUDE_DIR}")
message(STATUS "R_LDFLAGS = ${R_LDFLAGS}")
message(STATUS "R_LIBRARY_BLAS = ${R_LIBRARY_BLAS}")
message(STATUS "R_LIBRARY_LAPACK = ${R_LIBRARY_LAPACK}")
message(STATUS "R_RCPP_INCLUDE_DIR = ${R_RCPP_INCLUDE_DIR}")
message(STATUS "R_RCPP_LDFLAGS = ${R_RCPP_LDFLAGS}")
message(STATUS "R_RINSIDE_INCLUDE_DIR = ${R_RINSIDE_INCLUDE_DIR}")
message(STATUS "R_RINSIDE_LDFLAGS = ${R_RINSIDE_LDFLAGS}")

# Flags
# =====
Expand All @@ -85,7 +89,6 @@ endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder")


CHECK_CXX_COMPILER_FLAG("-std=c++17" HAS_CPP_17_FLAG)
if (HAS_CPP_17_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
Expand Down Expand Up @@ -199,7 +202,10 @@ macro(xeus_r_create_target target_name linkage output_name)
PUBLIC
$<BUILD_INTERFACE:${XEUS_R_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
${R_INCLUDE_DIR})
${R_INCLUDE_DIR}
${R_RCPP_INCLUDE_DIR}
${R_RINSIDE_INCLUDE_DIR}
)

if (XEUS_R_USE_SHARED_XEUS)
set(XEUS_R_XEUS_TARGET xeus)
Expand All @@ -215,7 +221,7 @@ macro(xeus_r_create_target target_name linkage output_name)
endif ()
find_package(Threads) # TODO: add Threads as a dependence of xeus-static?

target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${R_LDFLAGS} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK})
target_link_libraries(${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${R_LDFLAGS} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK} ${R_RCPP_LDFLAGS} ${R_RINSIDE_LDFLAGS})

endmacro()

Expand Down Expand Up @@ -249,7 +255,7 @@ if (XEUS_R_BUILD_EXECUTABLE)
target_compile_features(xr PRIVATE cxx_std_17)
xeus_r_set_common_options(xr)
xeus_r_set_kernel_options(xr)
target_link_libraries(xr PRIVATE xeus-zmq ${R_LDFLAGS} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK})
target_link_libraries(xr PRIVATE xeus-zmq ${R_LDFLAGS} ${R_LIBRARY_BLAS} ${R_LIBRARY_LAPACK} ${R_RCPP_LDFLAGS} ${R_RINSIDE_LDFLAGS})
endif()


Expand Down
28 changes: 28 additions & 0 deletions cmake/FindR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# R_LIBRARY_READLINE - Path to readline library
# R_LIBRARIES - Array of: R_LIBRARY_BASE, R_LIBRARY_BLAS, R_LIBRARY_LAPACK, R_LIBRARY_BASE [, R_LIBRARY_READLINE]
# R_LDFLAGS - R CMD config --ldflags
# R_RCPP_INCLUDE_DIR - Path to Rcpp include directory
# R_RCPP_LDFLAGS - Rscript -e "Rcpp:::LdFlags()"
# R_RINSIDE_INCLUDE_DIR - Rscript -e "RInside:::CxxFlags()"
# R_RINSIDE_LDFLAGS - Rscript -e "RInside:::LdFlags()"
#
# Variable search order:
# 1. Attempt to locate and set R_COMMAND
Expand Down Expand Up @@ -59,6 +63,30 @@ if(R_COMMAND)
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(R_LDFLAGS ${R_LDFLAGS} CACHE PATH "R CMD config --ldflags")

execute_process(WORKING_DIRECTORY .
COMMAND ${R_SCRIPT_COMMAND} -e "cat(tools::file_path_as_absolute(base::system.file('include', package = 'Rcpp')))"
OUTPUT_VARIABLE R_RCPP_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(R_RCPP_INCLUDE_DIR ${R_RCPP_INCLUDE_DIR} CACHE PATH "Rcpp include directory")

execute_process(WORKING_DIRECTORY .
COMMAND ${R_SCRIPT_COMMAND} -e "Rcpp:::LdFlags()"
OUTPUT_VARIABLE R_RCPP_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(R_RCPP_LDFLAGS ${R_RCPP_LDFLAGS} CACHE PATH "Rcpp:::LdFlags()")

execute_process(WORKING_DIRECTORY .
COMMAND ${R_SCRIPT_COMMAND} -e "cat(tools::file_path_as_absolute(base::system.file('include', package = 'RInside')))"
OUTPUT_VARIABLE R_RINSIDE_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(R_RINSIDE_INCLUDE_DIR ${R_RINSIDE_INCLUDE_DIR} CACHE PATH "RInside include directory")

execute_process(WORKING_DIRECTORY .
COMMAND ${R_SCRIPT_COMMAND} -e "RInside:::LdFlags()"
OUTPUT_VARIABLE R_RINSIDE_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(R_RINSIDE_LDFLAGS ${R_RINSIDE_LDFLAGS} CACHE PATH "RInside:::LdFlags()")

find_path(R_INCLUDE_DIR R.h
HINTS ${R_ROOT_DIR} ${R_ROOT_DIR}/bin/${R_LIB_ARCH}
PATHS /usr/local/lib /usr/local/lib64 /usr/share
Expand Down
2 changes: 2 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies:
- cppzmq
- xtl
- r-base
- r-rcpp
- r-rinside
# Test dependencies
- pytest
- jupyter_kernel_test>=0.4.3
Expand Down
3 changes: 3 additions & 0 deletions include/xeus-r/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "xeus_r_config.hpp"
#include "xeus/xinterpreter.hpp"

#include "RInside.h"

namespace nl = nlohmann;

Expand Down Expand Up @@ -58,6 +59,8 @@ namespace xeus_r

void shutdown_request_impl() override;

private:
RInside R;
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "xeus-r/xinterpreter.hpp"

#include "RInside.h"

#define R_NO_REMAP
#include "R.h"
#include "Rinternals.h"
Expand Down Expand Up @@ -64,9 +66,8 @@ SEXP try_parse(const std::string& code, int execution_counter) {

}

interpreter::interpreter(int argc, char* argv[])
interpreter::interpreter(int argc, char* argv[]) : R(argc, argv)
{
Rf_initEmbeddedR(argc, argv);
xeus::register_interpreter(this);
}

Expand All @@ -90,7 +91,7 @@ SEXP try_parse(const std::string& code, int execution_counter) {
}

UNPROTECT(1); // parsed

// echo the code for now
nl::json pub_data;
pub_data["text/plain"] = code;
Expand Down Expand Up @@ -159,7 +160,6 @@ SEXP try_parse(const std::string& code, int execution_counter) {
}

void interpreter::shutdown_request_impl() {
Rf_endEmbeddedR(0);
std::cout << "Bye!!" << std::endl;
}

Expand Down
Loading