r-universe-org / help

Support and bug tracker for R-universe
https://docs.r-universe.dev/
9 stars 2 forks source link

Mac binary may fail to load #494

Closed jwokaty closed 4 hours ago

jwokaty commented 4 hours ago

Mac binaries may fail to load due to expecting libraries to exists in certain paths. Vince installed the Bioconductor impute package built by r-universe on a new mac. When attempting to load impute with library, it fails because it expects to find libraries along paths that don't exist, like /opt/gfortran.

# https://gist.github.com/vjcitn/4924254d0bf26cb2b336bfb17ba394b3
> options(repos=c(BioCsoft="https://bioc.r-universe.dev", CRAN="https://cloud.r-project.org"))

> getOption("repos")
                     BioCsoft                          CRAN 
"https://bioc.r-universe.dev" "https://cloud.r-project.org" 

> install.packages("impute")
Installing package into ‘/Users/papa/Library/R/arm64/4.4/library’
(as ‘lib’ is unspecified)
trying URL 'https://bioc.r-universe.dev/bin/macosx/big-sur-arm64/contrib/4.4/impute_1.79.0.tgz'
Content type 'application/x-gzip' length 661436 bytes (645 KB)
==================================================
downloaded 645 KB

The downloaded binary packages are in
    /var/folders/x3/y47x73xn0s3cd4hh22jpl4440000gp/T//RtmpPYveh1/downloaded_packages

> library(impute)
Error: package or namespace load failed for ‘impute’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/papa/Library/R/arm64/4.4/library/impute/libs/impute.so':
  dlopen(/Users/papa/Library/R/arm64/4.4/library/impute/libs/impute.so, 0x0006): Library not loaded: /opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0/libgfortran.5.dylib
  Referenced from: <A86FE63B-0C87-3374-B7F7-CCEBCE31F747> /Users/papa/Library/R/arm64/4.4/library/impute/libs/impute.so
  Reason: tried: '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0/libgfortran.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0/libgfortran.5.dylib' (no such file), '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file, not in dyld cache)

Enter a frame number, or 0 to exit   

1: library(impute)
2: tryCatch({
    attr(package, "LibPath") <- which.lib.loc
    ns <- loadNames
3: tryCatchList(expr, classes, parentenv, handlers)
4: tryCatchOne(expr, names, parentenv, handlers[[1]])
5: value[[3]](cond)

For Bioconductor mac binaries, we change these paths to point to files in the R installation using the install_name_tool, which you can see at the bottom of impute's report https://bioconductor.org/checkResults/3.20/bioc-LATEST/impute/kjohnson3-buildbin.html with fix_dylibs_links in https://github.com/Bioconductor/BBS/blob/59c72d94036eba81da0db0abbad894cb787a464a/utils/macosx-inst-pkg.sh#L104.

jeroen commented 4 hours ago

Thanks for reporting! I did not notice this because the problem does not show if you have a local gcc or gfortran installed.

This should be fixed now in https://github.com/r-universe-org/actions/commit/b13cbfa315d141c3aa5dbb8a0363e3db375d9867: we can use a simpler method Suggested here by BDR by linking to the R location in the first place, so that we don't have to do any fixups after the build.

I'm about to rebuild a bunch of R fortran packages and see if this works well. You can go ahead and try it for impute.