help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can I change the Makeconf file of R to not use hardcoded, wrong incl


From: Moritz Lell
Subject: How can I change the Makeconf file of R to not use hardcoded, wrong include paths when compiling a package with Rcpp
Date: Tue, 14 Jan 2020 00:49:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1

Hello!

to reproduce a scientific project, I need a setup with an old R version
(3.4.3), together with other, newer libraries. I created a profile, the
manifest and package definitions are below. However, when loading the
profile I cannot compile R packages with this version:

The last lines of the output of `install.packages("Rcpp_1.0.3.tar.gz",
repos = NULL)` (I have to manually download/use the miniCRAN package
because of SSL errors while downloading via R but that is another question)

--- begin --------------------------------------------------------------

g++ -shared
-L/gnu/store/d64gfblqc5b9gmwj3rbl8nx3zwbf973b-r-minimal-3.4.3/lib/R/lib
-L/usr/local/lib -o Rcpp.so api.o attributes.o barrier.o date.o module.o
rcpp_init.o
-L/gnu/store/d64gfblqc5b9gmwj3rbl8nx3zwbf973b-r-minimal-3.4.3/lib/R/lib -lR
installing to
/home/moritz/IPK/R/code/Unbalanced/renv/library/R-3.4/x86_64-unknown-linux-gnu/Rcpp/libs
** R
** inst
** preparing package for lazy loading
code for methods in class “C++OverloadedMethods” was not checked for
suspicious field assignments (recommended package ‘codetools’ not
available?)
code for methods in class “RcppClass” was not checked for suspicious
field assignments (recommended package ‘codetools’ not available?)
code for methods in class “RcppClass” was not checked for suspicious
field assignments (recommended package ‘codetools’ not available?)
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘Rcpp’ in dyn.load(file,
DLLpath = DLLpath, ...):
 kann shared object
'/home/user/r-test/renv/library/R-3.4/x86_64-unknown-linux-gnu/Rcpp/libs/Rcpp.so'
nicht laden:

/gnu/store/5imx9c2y6bkd27rprrghnaw59x0svyxb-gfortran-7.4.0-lib/lib/libstdc++.so.6:
version `GLIBCXX_3.4.26' not found (required by
/home/user/r-test/renv/library/R-3.4/x86_64-unknown-linux-gnu/Rcpp/libs/Rcpp.so)

--- end ---------------------------------------------------------------

The problem is `-I/usr/local/include` in the g++ call. It refers to a
directory outside of my GUIX installation and hence I get errors because
libraries there mismatch with those inside GUIX. Apparently, GUIX libs
are used for the linker but not for the compiler.

The problem lies in the file
/gnu/store/d64gfblqc5b9gmwj3rbl8nx3zwbf973b-r-minimal-3.4.3/etc/Makeconf

--- begin ------------------------------------------------------------

...
CPPFLAGS = -I/usr/local/include
...
FLIBS =
-L/gnu/store/5imx9c2y6bkd27rprrghnaw59x0svyxb-gfortran-7.4.0-lib/lib/gcc/x86_64-unknown-linux-gnu/7.4.0
-L/gnu/store/5imx9c2y6bkd27rprrghnaw59x0svyxb-gfortran-7.4.0-lib/lib
-lgfortran -lm -lquadmath

--- end --------------------------------------------------------------

CPPFLAGS is set to the wrong, hardcoded value, but for example FLIBS is
set correctly. How can I install R such that CPPFLAGS refers to the
/lib/include directory of my profile or doesn't refer to anything?

I can define the PKG_CXXFLAGS environment variable that can be used to
insert additional header locations for R compilation, but unfortunately
they are inserted after the R default locations. But I can use it if the
R default is set to nothing. I've also tested setting CPLUS_INCLUDE_PATH
and PKG_CPPFLAGS, to no avail.

Cheers,
Moritz

==========================================================================

Appendix: Profile manifests and other files

manifest.scm            --- manifest file for guix package
packages/               --- include in GUIX_PACKAGE_PATH
packages/statistics.scm --- Checked out from the guix repo with
    `git show cbe1314a7e:gnu/packages/statistics.scm` and edited
    to only include r-minimal
packages/old-tzdata.scm --- for the package tzdata-2017b


-----------------------------------------------------------------------
# Commands to create the files needed to reproduce the problem
mkdir packages

cat >manifest.scm <<EOF

(specifications->manifest
  '("r-minimal@3.4.3"
    "glibc-utf8-locales"
    "gcc-toolchain"
    "gfortran-toolchain"))

EOF

# ----------------------------------------------------------------------

cat >packages/old-tzdata.scm <<EOF

(define-module (old-tz-data)
  #:use-module ((guix licenses)
                #:select (gpl3+ lgpl2.0+ lgpl3+ public-domain))
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
)
(define tzdata
  (package
    (name "tzdata")
    (version "2017b")
    (source (origin
             (method url-fetch)
             (uri (string-append

"https://www.iana.org/time-zones/repository/releases/tzdata";
                   version ".tar.gz"))
             (sha256
              (base32
               "11l0s43vx33dcs78p80122i8s5s9l1sjwkzzwh66njd35r92l97q"))))
    (build-system gnu-build-system)
    (arguments
     '(#:tests? #f
       #:make-flags (let ((out (assoc-ref %outputs "out"))
                          (tmp (getenv "TMPDIR")))
                      (list (string-append "TOPDIR=" out)
                            (string-append "TZDIR=" out "/share/zoneinfo")

                            ;; Discard zic, dump, and tzselect, already
                            ;; provided by glibc.
                            (string-append "ETCDIR=" tmp "/etc")

                            ;; Likewise for the C library routines.
                            (string-append "LIBDIR=" tmp "/lib")
                            (string-append "MANDIR=" tmp "/man")

                            "AWK=awk"
                            "CC=gcc"))
       #:modules ((guix build utils)
                  (guix build gnu-build-system)
                  (srfi srfi-1))
       #:phases
       (modify-phases %standard-phases
         (replace 'unpack
           (lambda* (#:key source inputs #:allow-other-keys)
             (and (zero? (system* "tar" "xvf" source))
                  (zero? (system* "tar" "xvf" (assoc-ref inputs
"tzcode"))))))
         (add-after 'install 'post-install
           (lambda* (#:key outputs #:allow-other-keys)
             ;; Move data in the right place.
             (let ((out (assoc-ref outputs "out")))
               (symlink (string-append out "/share/zoneinfo")
                        (string-append out "/share/zoneinfo/posix"))
               (delete-file-recursively
                (string-append out "/share/zoneinfo-posix"))
               (copy-recursively (string-append out "/share/zoneinfo-leaps")
                                 (string-append out
"/share/zoneinfo/right"))
               (delete-file-recursively
                (string-append out "/share/zoneinfo-leaps")))))
         (delete 'configure))))
    (inputs `(("tzcode" ,(origin
                          (method url-fetch)
                          (uri (string-append

"http://www.iana.org/time-zones/repository/releases/tzcode";
                                version ".tar.gz"))
                          (sha256
                           (base32

"0h1d567gn8l3iqgyadcswwdy2yh07nhz3lfl8ds8saz2ajxka5sd"))))))
    (home-page "https://www.iana.org/time-zones";)
    (synopsis "Database of current and historical time zones")
    (description "The Time Zone Database (often called tz or zoneinfo)
contains code and data that represent the history of local time for many
representative locations around the globe.  It is updated periodically to
reflect changes made by political bodies to time zone boundaries, UTC
offsets,
and daylight-saving rules.")
    (license public-domain)))


(define-public tzdata-2017a
  (package
    (inherit tzdata)
    (version "2017a")
    (source
      (origin
        (method url-fetch)
        (uri (string-append "https://www.iana.org/time-zones/repository";
                            "/releases/tzdata" version ".tar.gz"))
        (sha256
         (base32
          "1mmv4rvcs12lrvgghw4fidczvb69yv69cmzknghcvw1c196mqfnz"))))
    (inputs `(("tzcode" ,(origin
                          (method url-fetch)
                          (uri (string-append

"http://www.iana.org/time-zones/repository/releases/tzcode";
                                version ".tar.gz"))
                          (sha256
                           (base32

"1b1q7gnlsh5hjgs5065pvajd37rmbc3k9b8cgzad1vcrifswdwh2"))))))))

EOF

# ----------------------------------------------------------------------

cat >packages/statistics.scm <<EOF

(define-module (statistics)
  #:use-module (old-tz-data)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix hg-download)
  #:use-module (guix utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system r)
  #:use-module (guix build-system python)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cran)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages haskell)
  #:use-module (gnu packages icu4c)
  #:use-module (gnu packages image)
  #:use-module (gnu packages java)
  #:use-module (gnu packages machine-learning)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages python)
  #:use-module (gnu packages readline)
  #:use-module (gnu packages ssh)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages time)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages base)
  #:use-module (gnu packages web)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages xorg)
  #:use-module (srfi srfi-1))

;; Update this package together with the set of recommended packages:
r-boot,
;; r-class, r-cluster, r-codetools, r-foreign, r-kernsmooth, r-lattice,
;; r-mass, r-matrix, r-mgcv, r-nlme, r-nnet, r-rpart, r-spatial, r-survival.

(define-public r-minimal
  (package
    (name "r-minimal")
    (version "3.4.3")
    (source (origin
              (method url-fetch)
              (uri (string-append "mirror://cran/src/base/R-"
                                  (version-prefix version 1) "/R-"
                                  version ".tar.gz"))
              (sha256
               (base32
                "09pl0w01fr09bsrwd7nz2r5psysj0z93w4chz3hm2havvqqvhg3s"))))
    (build-system gnu-build-system)
    (arguments
     `(#:disallowed-references (,tzdata-2017a)
       #:make-flags
       (list (string-append "LDFLAGS=-Wl,-rpath="
                            (assoc-ref %outputs "out")
                            "/lib/R/lib")
             ;; This affects the embedded timestamp of only the core
packages.
             "PKG_BUILT_STAMP=1970-01-01")
       #:phases
       (modify-phases %standard-phases
         (add-before 'configure 'do-not-compress-serialized-files
           (lambda* (#:key inputs #:allow-other-keys)
             ;; This ensures that Guix can detect embedded store references;
             ;; see bug #28157 for details.
             (substitute* "src/library/base/makebasedb.R"
               (("compress = TRUE") "compress = FALSE"))
             #t))
         (add-before 'configure 'patch-uname
           (lambda* (#:key inputs #:allow-other-keys)
             (let ((uname-bin (string-append (assoc-ref inputs "coreutils")
                                             "/bin/uname")))
               (substitute* "src/scripts/R.sh.in"
                 (("uname") uname-bin)))
             #t))
         (add-after 'unpack 'build-reproducibly
           (lambda _
             ;; The documentation contains time stamps to demonstrate
             ;; documentation generation in different phases.
             (substitute* "src/library/tools/man/Rd2HTML.Rd"
               (("\\\\%Y-\\\\%m-\\\\%d at \\\\%H:\\\\%M:\\\\%S")
                "(removed for reproducibility)"))

             ;; Remove timestamp from tracing environment.  This fixes
             ;; reproducibility of "methods.rd{b,x}".
             (substitute* "src/library/methods/R/trace.R"
               (("dateCreated = Sys.time\\(\\)")
                "dateCreated = as.POSIXct(\"1970-1-1 00:00:00\", tz =
\"UTC\")"))

             ;; Ensure that gzipped files are reproducible.
             (substitute* '("src/library/grDevices/Makefile.in"
                            "doc/manual/Makefile.in")
               (("R_GZIPCMD\\)" line)
                (string-append line " -n")))

             ;; The "srcfile" procedure in "src/library/base/R/srcfile.R"
             ;; queries the mtime of a given file and records it in an
object.
             ;; This is acceptable at runtime to detect stale source files,
             ;; but it destroys reproducibility at build time.
             ;;
             ;; Instead of disabling this feature, which may have unexpected
             ;; consequences, we reset the mtime of generated files before
             ;; passing them to the "srcfile" procedure.
             (substitute* "src/library/Makefile.in"
               (("@\\(cd base && \\$\\(MAKE\\) mkdesc\\)" line)
                (string-append line "\n find
$(top_builddir)/library/tools | xargs touch -d '1970-01-01'; \n"))
               (("@\\$\\(MAKE\\) Rdobjects" line)
                (string-append "@find $(srcdir)/tools | xargs touch -d
'1970-01-01'; \n        "
                               line)))
             (substitute* "src/library/tools/Makefile.in"
               (("@\\$\\(INSTALL_DATA\\) all.R
\\$\\(top_builddir\\)/library/\\$\\(pkg\\)/R/\\$\\(pkg\\)" line)
                (string-append
                 line
                 "\n    find $(srcdir)/$(pkg)
$(top_builddir)/library/$(pkg) | xargs touch -d \"1970-01-01\"; \n")))

             ;; This library is installed using
"install_package_description",
             ;; so we need to pass the "builtStamp" argument.
             (substitute* "src/library/tools/Makefile.in"
               (("(install_package_description\\(.*\"')\\)\"" line prefix)
                (string-append prefix ", builtStamp='1970-01-01')\"")))

             ;; R bundles an older version of help2man, which does not
respect
             ;; SOURCE_DATE_EPOCH.  We cannot just use the latest help2man,
             ;; because that breaks a test.
             (with-fluids ((%default-port-encoding "ISO-8859-1"))
               (substitute* "tools/help2man.pl"
                 (("my \\$date = strftime \"%B %Y\", localtime" line)
                  (string-append line " 1"))))
             #t))
         (add-before 'configure 'set-default-pager
          ;; Set default pager to "cat", because otherwise it is "false",
          ;; making "help()" print nothing at all.
          (lambda _ (setenv "PAGER" "cat") #t))
         (add-before 'check 'set-timezone
           ;; Some tests require the timezone to be set.  However, the
           ;; timezone may not just be "UTC", or else a brittle regression
           ;; test in reg-tests-1d will fail.
           (lambda* (#:key inputs #:allow-other-keys)
             (setenv "TZ" "UTC+1")
             (setenv "TZDIR"
                     (string-append (assoc-ref inputs "tzdata")
                                    "/share/zoneinfo"))
             #t))
         (add-after 'build 'make-info
          (lambda _ (zero? (system* "make" "info"))))
         (add-after 'build 'install-info
          (lambda _ (zero? (system* "make" "install-info")))))
       #:configure-flags
       '(;; Do not build the recommended packages.  The build system creates
         ;; random temporary directories and embeds their names in some
         ;; package files.  We build these packages with the r-build-system
         ;; instead.
         "--without-recommended-packages"
         "--with-cairo"
         "--with-blas=-lopenblas"
         "--with-libpng"
         "--with-jpeglib"
         "--with-libtiff"
         "--with-ICU"
         "--enable-R-shlib"
         "--enable-BLAS-shlib"
         "--with-system-tre")))
    ;; R has some support for Java.  When the JDK is available at configure
    ;; time environment variables pointing to the JDK will be recorded under
    ;; $R_HOME/etc and ./tools/getsp.java will be compiled which is used
by "R
    ;; CMD javareconf".  "R CMD javareconf" appears to only be used to
update
    ;; the recorded environment variables in $R_HOME/etc.  Refer to
    ;;
https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Java-support
    ;; for additional information.

    ;; As the JDK is a rather large input with only very limited effects
on R,
    ;; we decided to drop it.
    (native-inputs
     `(("bzip2" ,bzip2)
       ("perl" ,perl)
       ("pkg-config" ,pkg-config)
       ("texinfo" ,texinfo) ; for building HTML manuals
       ("tzdata" ,tzdata-2017a)
       ("xz" ,xz)))
    (inputs
     `(;; We need not only cairo here, but pango to ensure that tests
for the
       ;; "cairo" bitmapType plotting backend succeed.
       ("pango" ,pango)
       ("coreutils" ,coreutils)
       ("curl" ,curl)
       ("openblas" ,openblas)
       ("gfortran" ,gfortran)
       ("icu4c" ,icu4c)
       ("libjpeg" ,libjpeg)
       ("libpng" ,libpng)
       ("libtiff" ,libtiff)
       ("libxt" ,libxt)
       ("pcre" ,pcre)
       ("readline" ,readline)
       ("which" ,which)
       ("zlib" ,zlib)))
    (native-search-paths
     (list (search-path-specification
            (variable "R_LIBS_SITE")
            (files (list "site-library/")))))
    (home-page "http://www.r-project.org/";)
    (synopsis "Environment for statistical computing and graphics")
    (description
     "R is a language and environment for statistical computing and
graphics.
It provides a variety of statistical techniques, such as linear and
nonlinear
modeling, classical statistical tests, time-series analysis, classification
and clustering.  It also provides robust support for producing
publication-quality data plots.  A large amount of 3rd-party packages are
available, greatly increasing its breadth and scope.")
    (license license:gpl3+)))

EOF



reply via email to

[Prev in Thread] Current Thread [Next in Thread]