Skip to content

Commit 26666df

Browse files
wesmkou
authored andcommitted
ARROW-6237: [R] Allow compilation flags to be passed for R package with ARROW_R_CXXFLAGS
For example: ``` export ARROW_R_CXXFLAGS="-fno-omit-frame-pointer" ``` (this flag is needed to record performance data on Linux with `perf`) I also amended the README.Rmd to say to use `$R_LD_LIBRARY_PATH` instead of `$LD_LIBRARY_PATH` for custom install location Closes #5088 from wesm/r-cxxflags and squashes the following commits: e25de5e <Wes McKinney> Add ARROW_R_CXXFLAGS to documentation 8718aaf <Wes McKinney> Change R package README to indicate to use R_LD_LIBRARY_PATH 3a919df <Wes McKinney> Allow compilation flags to be passed for R package with ARROW_R_CXXFLAGS Authored-by: Wes McKinney <wesm+git@apache.org> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent c7b9379 commit 26666df

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

r/README.Rmd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ arrow::install_arrow()
4646

4747
for version- and platform-specific guidance on installing the Arrow C++ library.
4848

49-
When installing from source, if the R and C++ library versions do not match, installation may fail. If you've previously installed the libraries and want to upgrade the R package, you'll need to update the Arrow C++ library first.
49+
When installing from source, if the R and C++ library versions do not match, installation may fail. If you've previously installed the libraries and want to upgrade the R package, you'll need to update the Arrow C++ library first.
5050

5151
## Example
5252

@@ -112,6 +112,14 @@ R -e 'install.packages("devtools"); devtools::install_dev_deps()'
112112
R CMD INSTALL .
113113
```
114114

115+
If you need to set any compilation flags while building the Rcpp extensions,
116+
you can use the `ARROW_R_CXXFLAGS` environment variable. For example, if you
117+
are using `perf` to profile the R extensions, you may need to set
118+
119+
```shell
120+
export ARROW_R_CXXFLAGS=-fno-omit-frame-pointer
121+
```
122+
115123
If the package fails to install/load with an error like this:
116124

117125
```
@@ -121,9 +129,9 @@ unable to load shared object '/Users/you/R/00LOCK-r/00new/arrow/libs/arrow.so':
121129
dlopen(/Users/you/R/00LOCK-r/00new/arrow/libs/arrow.so, 6): Library not loaded: @rpath/libarrow.14.dylib
122130
```
123131

124-
try setting the environment variable `LD_LIBRARY_PATH` (or `DYLD_LIBRARY_PATH`
125-
on macOS) to wherever Arrow C++ was put in `make install`, e.g. `export
126-
LD_LIBRARY_PATH=/usr/local/lib`, and retry installing the R package.
132+
try setting the environment variable `R_LD_LIBRARY_PATH` to wherever Arrow C++
133+
was put in `make install`, e.g. `export R_LD_LIBRARY_PATH=/usr/local/lib`, and
134+
retry installing the R package.
127135

128136
For any other build/configuration challenges, see the [C++ developer
129137
guide](https://arrow.apache.org/docs/developers/cpp.html#building).

r/README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ page](https://arrow.apache.org/install/) to find pre-compiled binary
4040
packages for some common Linux distributions, including Debian, Ubuntu,
4141
and CentOS. You’ll need to install `libparquet-dev` on Debian and
4242
Ubuntu, or `parquet-devel` on CentOS. This will also automatically
43-
install the Arrow C++ library as a dependency.
43+
install the Arrow C++ library as a dependency. Other Linux distributions
44+
must install the C++ library from source.
4445

4546
If you install the `arrow` package from source and the C++ library is
4647
not found, the R package functions will notify you that Arrow is not
@@ -161,17 +162,25 @@ R -e 'install.packages("devtools"); devtools::install_dev_deps()'
161162
R CMD INSTALL .
162163
```
163164

165+
If you need to set any compilation flags while building the Rcpp
166+
extensions, you can use the `ARROW_R_CXXFLAGS` environment variable. For
167+
example, if you are using `perf` to profile the R extensions, you may
168+
need to set
169+
170+
``` shell
171+
export ARROW_R_CXXFLAGS=-fno-omit-frame-pointer
172+
```
173+
164174
If the package fails to install/load with an error like this:
165175

166176
** testing if installed package can be loaded from temporary location
167177
Error: package or namespace load failed for 'arrow' in dyn.load(file, DLLpath = DLLpath, ...):
168178
unable to load shared object '/Users/you/R/00LOCK-r/00new/arrow/libs/arrow.so':
169179
dlopen(/Users/you/R/00LOCK-r/00new/arrow/libs/arrow.so, 6): Library not loaded: @rpath/libarrow.14.dylib
170180

171-
try setting the environment variable `LD_LIBRARY_PATH` (or
172-
`DYLD_LIBRARY_PATH` on macOS) to wherever Arrow C++ was put in `make
173-
install`, e.g. `export LD_LIBRARY_PATH=/usr/local/lib`, and retry
174-
installing the R package.
181+
try setting the environment variable `R_LD_LIBRARY_PATH` to wherever
182+
Arrow C++ was put in `make install`, e.g. `export
183+
R_LD_LIBRARY_PATH=/usr/local/lib`, and retry installing the R package.
175184

176185
For any other build/configuration challenges, see the [C++ developer
177186
guide](https://arrow.apache.org/docs/developers/cpp.html#building).

r/configure

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CPPFLAGS=$("${R_HOME}"/bin/R CMD config CPPFLAGS)
8686

8787
# If libarrow uses the old GLIBCXX ABI, so we have to use it too
8888
if [ "$ARROW_USE_OLD_CXXABI" ]; then
89-
$PKG_CFLAGS="$PKG_CFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
89+
PKG_CFLAGS="$PKG_CFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
9090
fi
9191

9292
# Test configuration
@@ -112,6 +112,11 @@ else
112112
PKG_CFLAGS=""
113113
fi
114114

115+
# Set any user-defined CXXFLAGS
116+
if [ "$ARROW_R_CXXFLAGS" ]; then
117+
PKG_CFLAGS="$PKG_CFLAGS $ARROW_R_CXXFLAGS"
118+
fi
119+
115120
# Write to Makevars
116121
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
117122

0 commit comments

Comments
 (0)