[R-pkg-devel] Best practices for PKG_LIBS and PKG_CPPFLAGS

Siddhartha Bagaria b@g@r|@@@|ddh@rth@ @end|ng |rom gm@||@com
Thu Apr 1 17:07:54 CEST 2021


Hello,

I have an atypical use case in which I have a build system
<https://github.com/grailbio/rules_r/> that can build C shared libraries
that will be used by the native code in an R package, and build both C
libraries and R packages in one user command. As these shared libraries are
specified by the build system itself, I do not want to assume their names
and locations in the R package src/Makevars. Going through the configure
script mechanism is not straightforward for arbitrary R packages that can
be used in the build system, because all user input is pre-specified before
the build steps are run, and so the shared library names and locations may
not be available when the user is specifying the build, or the configure
script may not be flexible enough to take such input from the user.

My question is if there is any guidance on what is the best way to set
PKG_LIBS and PKG_CPPFLAGS variables from the command line rather than
expecting them in the package src/Makevars? As part of my build system,
even if I create or edit the package src/Makevars, it could be replaced or
changed in arbitrary ways by the configure script.

So far, I have been exporting PKG_LIBS and PKG_CPPFLAGS as environment
variables before running R CMD INSTALL (my build script
<https://github.com/grailbio/rules_r/blob/d4b3a80bba49c5b540e72ca3a9fcc9ef1e5af93c/R/scripts/build.sh#L191>),
and then assuming that if the user has these variables in the package
src/Makevars, then they are appending to an existing list (e.g. by using
`+=`), rather than replacing it (by using `=`). But I am not sure if this
is the best way.

It could be that I am thinking about this all wrong, so would appreciate
some guidance.

There has been some discussion on how to do this best on Github
<https://github.com/RcppCore/RcppArmadillo/pull/331>, but we thought it
would be best if we started a discussion here.

Thank you.

Siddhartha

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list