|
3 | 3 | #' |
4 | 4 | #' Output the compiler or linker flags required to build against RcppParallel. |
5 | 5 | #' |
6 | | -#' These functions are typically called from \code{Makevars} as follows: |
| 6 | +#' These functions are typically called from `Makevars` as follows: |
7 | 7 | #' |
8 | 8 | #' ``` |
9 | 9 | #' PKG_LIBS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::LdFlags()") |
10 | 10 | #' ``` |
11 | 11 | #' |
12 | 12 | #' On Windows, the flags ensure that the package links with the built-in TBB |
13 | 13 | #' library. On Linux and macOS, the output is empty, because TBB is loaded |
14 | | -#' dynamically. |
| 14 | +#' dynamically on load by `RcppParallel`. |
15 | 15 | #' |
16 | | -#' To ensure portability, load \pkg{RcppParallel} before loading |
17 | | -#' your package, e.g. by including \code{importFrom(RcppParallel, |
18 | | -#' RcppParallelLibs)} in your \code{NAMESPACE} file. See |
19 | | -#' \url{https://github.com/RcppCore/RcppParallel/issues/129} for details. |
| 16 | +#' \R packages using RcppParallel should also add the following to their |
| 17 | +#' `NAMESPACE` file: |
| 18 | +#' |
| 19 | +#' ``` |
| 20 | +#' importFrom(RcppParallel, RcppParallelLibs) |
| 21 | +#' ``` |
| 22 | +#' |
| 23 | +#' This is necessary to ensure that \pkg{RcppParallel} (and so, TBB) is loaded |
| 24 | +#' and available. |
20 | 25 | #' |
21 | 26 | #' @name flags |
22 | 27 | #' @rdname flags |
@@ -46,113 +51,3 @@ RcppParallelLibs <- function() { |
46 | 51 | LdFlags() |
47 | 52 | } |
48 | 53 |
|
49 | | - |
50 | | - |
51 | | -tbbCxxFlags <- function() { |
52 | | - |
53 | | - flags <- character() |
54 | | - |
55 | | - # opt-in to TBB on Windows |
56 | | - if (is_windows()) |
57 | | - flags <- c(flags, "-DRCPP_PARALLEL_USE_TBB=1") |
58 | | - |
59 | | - # if TBB_INC is set, apply those library paths |
60 | | - tbbInc <- Sys.getenv("TBB_INC", unset = NA) |
61 | | - if (!is.na(tbbInc)) { |
62 | | - |
63 | | - # add include path |
64 | | - flags <- c(flags, paste0("-I", shQuote(asBuildPath(tbbInc)))) |
65 | | - |
66 | | - # prefer new interface if version.h exists |
67 | | - versionPath <- file.path(tbbInc, "tbb/version.h") |
68 | | - if (file.exists(versionPath)) |
69 | | - flags <- c(flags, "-DTBB_INTERFACE_NEW") |
70 | | - |
71 | | - } |
72 | | - |
73 | | - # return flags as string |
74 | | - paste(flags, collapse = " ") |
75 | | - |
76 | | -} |
77 | | - |
78 | | -# Return the linker flags required for TBB on this platform |
79 | | -tbbLdFlags <- function() { |
80 | | - |
81 | | - # shortcut if TBB_LIB defined |
82 | | - tbbLib <- Sys.getenv("TBB_LIB", unset = NA) |
83 | | - if (!is.na(tbbLib)) { |
84 | | - fmt <- "-L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc" |
85 | | - return(sprintf(fmt, shQuote(asBuildPath(tbbLib)))) |
86 | | - } |
87 | | - |
88 | | - # on Windows and Solaris, we need to explicitly link |
89 | | - needsExplicitFlags <- is_windows() || (is_solaris() && !is_sparc()) |
90 | | - if (needsExplicitFlags) { |
91 | | - libPath <- asBuildPath(dirname(tbbLibPath())) |
92 | | - libFlag <- paste0("-L", shQuote(libPath)) |
93 | | - return(paste(libFlag, "-ltbb", "-ltbbmalloc")) |
94 | | - } |
95 | | - |
96 | | - # nothing required on other platforms |
97 | | - "" |
98 | | - |
99 | | -} |
100 | | - |
101 | | -tbbRoot <- function() { |
102 | | - rArch <- .Platform$r_arch |
103 | | - parts <- c("libs", if (nzchar(rArch)) rArch, "tbb") |
104 | | - libDir <- paste(parts, collapse = "/") |
105 | | - system.file(libDir, package = "RcppParallel") |
106 | | -} |
107 | | - |
108 | | -# Determine the platform-specific path to the TBB library |
109 | | -tbbLibPath <- function(suffix = "") { |
110 | | - |
111 | | - # library paths for different OSes |
112 | | - sysname <- Sys.info()[["sysname"]] |
113 | | - |
114 | | - tbbLibNames <- list( |
115 | | - "Darwin" = paste0("libtbb", suffix, ".dylib"), |
116 | | - "Windows" = paste0("tbb", suffix, ".dll"), |
117 | | - "SunOS" = paste0("libtbb", suffix, ".so"), |
118 | | - "Linux" = paste0("libtbb", suffix, c(".so.2", ".so")) |
119 | | - ) |
120 | | - |
121 | | - # skip systems that we know not to be compatible |
122 | | - isCompatible <- |
123 | | - !is_sparc() && |
124 | | - !is.null(tbbLibNames[[sysname]]) |
125 | | - |
126 | | - if (!isCompatible) |
127 | | - return(NULL) |
128 | | - |
129 | | - # find root for TBB install |
130 | | - tbbRoot <- Sys.getenv("TBB_LIB", unset = tbbRoot()) |
131 | | - libNames <- tbbLibNames[[sysname]] |
132 | | - for (libName in libNames) { |
133 | | - tbbName <- file.path(tbbRoot, libName) |
134 | | - if (file.exists(tbbName)) |
135 | | - return(tbbName) |
136 | | - } |
137 | | - |
138 | | -} |
139 | | - |
140 | | -# Helper function to ape the behavior of the R build system |
141 | | -# when providing paths to libraries |
142 | | -asBuildPath <- function(path) { |
143 | | - |
144 | | - # nothing to do for non-Windows |
145 | | - if (!is_windows()) |
146 | | - return(path) |
147 | | - |
148 | | - # normalize paths using forward slashes |
149 | | - path <- normalizePath(path, winslash = "/", mustWork = FALSE) |
150 | | - |
151 | | - # prefer short path names if the path has spaces |
152 | | - if (grepl(" ", path, fixed = TRUE)) |
153 | | - path <- utils::shortPathName(path) |
154 | | - |
155 | | - # return path |
156 | | - return(path) |
157 | | - |
158 | | -} |
0 commit comments