From 82280146b1f68b5ab358fb546787c219ca600133 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Thu, 23 Jul 2026 15:34:33 -0700 Subject: [PATCH] add systemFile() helper for arch-aware package paths Consolidates the four places that constructed paths within the installed package while accounting for the architecture-specific subdirectory used on Windows (e.g. 'lib/x64'). --- R/tbb.R | 17 +++++------------ R/utils.R | 8 ++++++++ R/zzz.R | 4 +--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/R/tbb.R b/R/tbb.R index 3d8fbb32..1c2c221a 100644 --- a/R/tbb.R +++ b/R/tbb.R @@ -41,10 +41,8 @@ tbbLibraryPath <- function(name = NULL) { tbbName <- file.path(tbbRoot, libName) if (file.exists(tbbName)) return(tbbName) - - arch <- if (nzchar(.Platform$r_arch)) .Platform$r_arch - suffix <- paste(c("lib", arch, libName), collapse = "/") - tbbName <- system.file(suffix, package = "RcppParallel") + + tbbName <- systemFile("lib", libName) if (file.exists(tbbName)) return(tbbName) @@ -90,10 +88,8 @@ tbbLdFlags <- function() { # on Windows, we statically link to oneTBB if (is_windows()) { - libPath <- system.file("libs", package = "RcppParallel") - if (nzchar(.Platform$r_arch)) - libPath <- file.path(libPath, .Platform$r_arch) - + libPath <- systemFile("libs") + ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath)) return(ldFlags) @@ -127,9 +123,6 @@ tbbRoot <- function() { if (nzchar(TBB_LIB)) return(TBB_LIB) - rArch <- .Platform$r_arch - parts <- c("lib", if (nzchar(rArch)) rArch) - libDir <- paste(parts, collapse = "/") - system.file(libDir, package = "RcppParallel") + systemFile("lib") } diff --git a/R/utils.R b/R/utils.R index 53ced638..490065b6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,12 @@ +# like system.file(), but injects the architecture-specific subdirectory +# used on Windows when set; e.g. systemFile("lib") resolves 'lib/x64' +systemFile <- function(dir, name = NULL) { + arch <- .Platform$r_arch + parts <- c(dir, if (nzchar(arch)) arch, name) + system.file(paste(parts, collapse = "/"), package = "RcppParallel") +} + # generate paths consumable by the compilers and linkers # in particular, on Windows and Solaris, this means the path _cannot_ be quoted !! asBuildPath <- function(path) { diff --git a/R/zzz.R b/R/zzz.R index e22615a8..77db75e8 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -23,9 +23,7 @@ loadTbbLibrary <- function(name) { # NOTE: resolve against the package's own library directory, where # install.libs.R places the stub; tbbRoot() would prefer TBB_LIB, # which on Windows points at Rtools and holds only static libraries - arch <- .Platform$r_arch - parts <- c("lib", if (nzchar(arch)) arch, paste0(name, ".dll")) - path <- system.file(paste(parts, collapse = "/"), package = "RcppParallel") + path <- systemFile("lib", paste0(name, ".dll")) if (!file.exists(path)) return(NULL)