Skip to content

Commit 21a21c3

Browse files
Search loader env paths for external libraries
1 parent fdf9dd4 commit 21a21c3

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

R/ffi.R

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,44 @@ recompile_into <- function(target) {
19231923
# Helper for %||%
19241924
`%||%` <- function(x, y) if (is.null(x)) y else x
19251925

1926+
tcc_library_search_paths <- function(
1927+
sysname = as.character(unname(Sys.info()[["sysname"]]))
1928+
) {
1929+
platform_paths <- tcc_platform_lib_paths(sysname)
1930+
1931+
env_vars <- unique(c(
1932+
tcc_loader_env_key(sysname),
1933+
"LIBRARY_PATH",
1934+
if (identical(sysname, "Darwin")) {
1935+
"DYLD_FALLBACK_LIBRARY_PATH"
1936+
} else {
1937+
character(0)
1938+
}
1939+
))
1940+
1941+
env_paths <- unlist(
1942+
lapply(env_vars, function(key) {
1943+
value <- Sys.getenv(key, unset = "")
1944+
if (!nzchar(value)) {
1945+
return(character(0))
1946+
}
1947+
strsplit(value, .Platform$path.sep, fixed = TRUE)[[1]]
1948+
}),
1949+
use.names = FALSE
1950+
)
1951+
1952+
unique(c(env_paths[nzchar(env_paths)], platform_paths))
1953+
}
1954+
19261955
# Search for library in platform-dependent paths
19271956
tcc_find_library <- function(name) {
19281957
if (file.exists(name)) {
19291958
return(name)
19301959
}
19311960

1932-
# Try platform-specific paths
1961+
# Try platform-specific paths plus relevant loader/linker env paths.
19331962
sysname <- as.character(unname(Sys.info()[["sysname"]]))
1934-
paths <- tcc_platform_lib_paths(sysname)
1963+
paths <- tcc_library_search_paths(sysname)
19351964

19361965
suffix_pattern <- c(
19371966
Windows = "\\.dll$",

inst/tinytest/test_fork_serialize.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ find_system_math_library <- function() {
229229
}
230230

231231
sysname <- as.character(unname(Sys.info()[["sysname"]]))
232-
paths <- unique(Rtinycc:::tcc_platform_lib_paths(sysname))
232+
paths <- unique(Rtinycc:::tcc_library_search_paths(sysname))
233233
patterns <- switch(
234234
sysname,
235235
Linux = c("^libm\\.so(\\.[0-9]+)+$"),

vignettes/linking-external-libraries.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ find_system_math_library <- function() {
2020
}
2121
2222
sysname <- as.character(unname(Sys.info()[["sysname"]]))
23-
paths <- unique(Rtinycc:::tcc_platform_lib_paths(sysname))
23+
paths <- unique(Rtinycc:::tcc_library_search_paths(sysname))
2424
patterns <- switch(
2525
sysname,
2626
Linux = c("^libm\\.so(\\.[0-9]+)+$"),

0 commit comments

Comments
 (0)