Skip to content
Open
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: 18 additions & 4 deletions nCompiler/R/Rcpp_nCompiler_plugin.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inlineCxxPlugin <- function(...) {
uses_nC_inter <- !isFALSE(inlineCxxPlugin_env$uses_nC_inter)
uses_nList <- !isFALSE(inlineCxxPlugin_env$uses_nList)
uses_cereal <- !isFALSE(inlineCxxPlugin_env$uses_cereal)
uses_TBB <- FALSE # !isFALSE(inlineCxxPlugin_env$uses_TBB) # including here causes error due to #defining FALSE
uses_TBB <- !isFALSE(inlineCxxPlugin_env$uses_TBB)
include.before <- character()
if(uses_eigen) include.before <- paste0(include.before, "#define NCOMPILER_USES_EIGEN\n")
if(uses_nC_inter) include.before <- paste0(include.before, "#define NCOMPILER_USES_NCLASS_INTERFACE\n")
Expand All @@ -37,9 +37,9 @@ nCompiler_pluginEnv <- new.env()
make_nCompiler_plugin <- function(nCompiler_pluginEnv) {
RcppDefaultPlugin <- Rcpp:::Rcpp.plugin.maker()
force(nCompiler_pluginEnv)
ans <- function(...) {
ans <- function(...) {
result <- RcppDefaultPlugin(...)
result$env$PKG_CPPFLAGS <- c(result$env$PKG_CPPFLAGS,
result$env$PKG_CPPFLAGS <- paste(result$env$PKG_CPPFLAGS,
if(length(nCompiler_pluginEnv$includePaths) > 0)
paste0(
"-I",
Expand All @@ -50,6 +50,8 @@ make_nCompiler_plugin <- function(nCompiler_pluginEnv) {
result$env$PKG_LIBS <- get_nCompLocal_PKG_LIBS_entry()
## Makevars doesn't work
## result$Makevars <- "CXX_STD=CXX11" does not seem to work
if(!isFALSE(inlineCxxPlugin_env$uses_TBB))
result$env <- setEnvTBB(result$env)
result
}
ans
Expand All @@ -74,13 +76,15 @@ make_nCompiler_Eigen_plugin <- function(nCompiler_pluginEnv) {
"")
# result$env$PKG_CXXFLAGS <- "-std=c++11"
result$env$PKG_LIBS <- get_nCompLocal_PKG_LIBS_entry()
if(!isFALSE(inlineCxxPlugin_env$uses_TBB))
result$env <- setEnvTBB(result$env)
if(isTRUE(get_nOption('compilerOptions')$throwEigenErrors)) {
# replace include directives to enable Eigen errors
#preamble = system.file(file.path('include', 'nCompiler',
# 'nCompiler_Eigen_EnableErrors.h'),
# package = 'nCompiler')
#result$includes = readChar(preamble, file.info(preamble)$size)
result$includes = "#define NCOMPILER_HANDLE_EIGEN_ERRORS"
result$includes = c("#define NCOMPILER_HANDLE_EIGEN_ERRORS")
}
if(isTRUE(get_nOption('compilerOptions')$cppStacktrace)) {
# add include directives to add stack basic traces
Expand All @@ -95,3 +99,13 @@ make_nCompiler_Eigen_plugin <- function(nCompiler_pluginEnv) {
}

nCompiler_Eigen_plugin <- make_nCompiler_Eigen_plugin(nCompiler_pluginEnv)

setEnvTBB <- function(env) {
if(.Platform$OS.type == "windows") {
env$PKG_CPPFLAGS <- paste(env$PKG_CPPFLAGS, '-DRCPP_PARALLEL_USE_TBB=1')
env$PKG_LIBS <- paste(env$PKG_LIBS,
'$(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe"-e "RcppParallel::RcppParallelLibs()")')
} else env$PKG_LIBS <- paste(env$PKG_LIBS,
'$(shell ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()")')
return(env)
}
4 changes: 2 additions & 2 deletions nCompiler/R/cppDefs_nClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ nClassBaseClass_init_impl <- function(cppDef) {
cppDef$Hpreamble <- pluginIncludes
cppDef$Hpreamble <- c(cppDef$Hpreamble,
"#define NCOMPILER_USES_EIGEN",
"// #define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_NLIST",
"#define USES_NCOMPILER")
cppDef$CPPpreamble <- pluginIncludes
cppDef$CPPpreamble <- c(cppDef$CPPpreamble,
"#define NCOMPILER_USES_EIGEN",
"// #define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_NLIST",
"#define USES_NCOMPILER")

Expand Down
4 changes: 2 additions & 2 deletions nCompiler/R/cppDefs_nFunction.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cpp_nFunctionClass_init_impl <- function(cppDef) {
cppDef$Hpreamble <- pluginIncludes
cppDef$Hpreamble <- c(cppDef$Hpreamble,
"#define NCOMPILER_USES_EIGEN",
"// #define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_NLIST",
"#define USES_NCOMPILER")
## handler nList in labelAbstractTypes does record in auxEnv if an
Expand All @@ -19,7 +19,7 @@ cpp_nFunctionClass_init_impl <- function(cppDef) {
cppDef$CPPpreamble <- pluginIncludes
cppDef$CPPpreamble <- c(cppDef$CPPpreamble,
"#define NCOMPILER_USES_EIGEN",
"// #define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_TBB",
"#define NCOMPILER_USES_NLIST",
"#define USES_NCOMPILER")
cppDef$Hincludes <- c(cppDef$Hincludes)#,
Expand Down
4 changes: 3 additions & 1 deletion nCompiler/R/nCompile.R
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,9 @@ WP_write_DESCRIPTION_NAMESPACE <- function(units, unitTypes, interfaces, createF
# DESCRIPTION[1, "Collate"] <- paste(Rfilepath, collapse = ", ")
write.dcf(DESCRIPTION, DESCfile)
NAMESPACE <- c(paste0("useDynLib(", pkgName, ", .registration=TRUE)"),
"importFrom(Rcpp, evalCpp)"# , # required at package loading
"importFrom(Rcpp, evalCpp)", # required at package loading
if(!isFALSE(inlineCxxPlugin_env$uses_TBB))
"importFrom(RcppParallel, RcppParallelLibs)" else NULL
# "export(nComp_serialize_)",
# "export(nComp_deserialize_)",
# "export(call_method)",
Expand Down