Skip to content

Commit

Permalink
Fix an issue in R/rdeephaven/src/Makevars regarding pkg-config; simpl…
Browse files Browse the repository at this point in the history
…ify README.md instructions (#4376)
  • Loading branch information
jcferretti authored Aug 25, 2023
1 parent df504fc commit d8cb9e3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 52 deletions.
87 changes: 36 additions & 51 deletions R/rdeephaven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ Currently, the R client is only supported on Ubuntu 20.04 or 22.04 and must be b
https://github.com/deephaven/deephaven-core/blob/main/cpp-client/README.md.
Follow the instructions at least to the point for "Build and install Deephaven C++ client".
At that point you would have both the Deephaven C++ client and any C++ libraries it depends on,
all installed in a particular directory of your choosing.
Define an environment variable `DHCPP` and assign it an absolute path to that directory.
all installed in a particular directory of your choosing. In what follows we assume that
directory is `/path/to/dhcpp`. Independently of where that directory is in your
chosen installation, a file called `env.sh` should exist on it, and a `local` subdirectory
as well.

2. Choose a directory where the Deephaven R client source code will live.
Here, the source code will be downloaded into a new directory called `rdeephaven`.
Expand All @@ -73,20 +75,26 @@ Currently, the R client is only supported on Ubuntu 20.04 or 22.04 and must be b
git pull origin main
```

3. Ensure that the environment variables from the C++ client installation are set. Print them out with
these commands:
3. Set environment variables from the C++ client installation required for building the package.
Use:
```
echo $DHCPP
echo $DHCPP_LOCAL
echo $CMAKE_PREFIX_PATH
echo $NCPUS
echo $LD_LIBRARY_PATH
source /path/to/dhcpp/env.sh
```
If any or all of these are empty, set them as follows:
where `/path/to/dhcpp` is the directory you created in step (1) above.
You can ensure the environment variables that are necessary for the steps
that follow are set by checking their values by running the commands:

```
export DHCPP=/path/to/dhcpp
source $DHCPP/env.sh
echo $DHCPP
echo $LD_LIBRARY_PATH
```

Both environment libraries need to be defined for installing the package in the
instructions below. Once the package is installed, you will only need
`LD_LIBRARY_PATH` to be set in the R session where you intend to use the `rdeephaven` library.
If you are starting R from the command line, you can set the environment variable as explained
above. If you are using RStudio, see the note in the following point.

Refer to the instructions on the C++ client installation for more details on the `dhcpp` directory.

4. Start an R console inside the rdeephaven directory. In that console, install the dephaven client dependencies
Expand All @@ -103,45 +111,22 @@ Currently, the R client is only supported on Ubuntu 20.04 or 22.04 and must be b
---
**NOTE**

If using RStudio for this step, the environment variables that were set in step 3 may not persist into the RStudio environment,
if it is not a child process of the process where the environment variables were set. Suppose that we have the following values
for the environment variables:
```bash
> echo $DHCPP
ABC
> echo $DHCPP_LOCAL
123
> echo $CMAKE_PREFIX_PATH
XYZ
> echo $NCPUS
4
> echo $LD_LIBRARY_PATH
libpath
```
Now, to resolve this issue, add the following file called `.Renviron` to the `deephaven-core` directory:
```bash
DHCPP=ABC
DHCPP_LOCAL=123
CMAKE_PREFIX_PATH=XYZ
NCPUS=4
LD_LIBRARY_PATH=libpath
```
Setting these to the _exact_ values of the environment variables is critical, as compilation will fail otherwise.

Then, create a new R project from the existing `deephaven-core` directory using RStudio, and the corresponding R session will inherit
all of the necessary environment variables for successful compilation.

If RStudio Server is being used, all of the above must be followed for successful compilation. _In addition_, the following line should
be added to `rserver.conf`:
```
rsession-ld-library-path=libpath
```
where `libpath` is the actual value of the `LD_LIBRARY_PATH` environment variable.

If using RStudio for this step, the environment variables that were set in step 3 may not persist into the RStudio
R environment if RStudio is not a child process of the shell where the environment variables were set
(ie, if RStudio is not started from that same shell and after the environment variables are set in that shell).
R supports using a `.Renviron` file for settings like this. You can generate the right content to add
to your .Renviron file (or for creating a new one) using the script under `etc/generate-dotRenviron-lines.sh`

You can create a new `.Renviron` file under the `deephave-core` directory with the lines producing by running
the `etc/generate-dotRenviron-lines.sh` in the same shell where you set the environment variables;
the script will give you the right content for the `.Renviron` file.
Then, create a new R project from the existing `deephaven-core` directory using RStudio, and the corresponding
R session will inherit all of the necessary environment variables for successful compilation.

If RStudio Server is being used, all of the above must be followed for successful compilation. _In addition_,
use the output from the script `etc/generate-rserverdotconf-lines.sh` and add them to the `rserver.conf` file
for the RStudio Server installation (the location of that file may depend on your particular RStudio server
installation, but a common location is `/etc/rstudio/rserver.conf`).
---

6. Now, run
Expand Down
4 changes: 4 additions & 0 deletions R/rdeephaven/etc/generate-dotRenviron-lines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "DHCPP=$DHCPP"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
3 changes: 3 additions & 0 deletions R/rdeephaven/etc/generate-rserverdotconf-lines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

echo "rsession-ld-library-path=$LD_LIBRARY_PATH"
2 changes: 1 addition & 1 deletion R/rdeephaven/src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DEPENDENCY_DIRS = -L$(DHCPP)/local/lib
DEPENDENCY_LIBS = \
-lprotobufd \
-larrow_flight -larrow -larrow_bundled_dependencies \
`PKG_CONFIG_PATH=$DHCPP/local/lib/pkgconfig --libs grpc`
`PKG_CONFIG_PATH=\${DHCPP}/local/lib/pkgconfig pkg-config --libs grpc++`


# tells the compiler where to look for additional include directories
Expand Down

0 comments on commit d8cb9e3

Please sign in to comment.