Skip to content

Instantly share code, notes, and snippets.

@program--
Last active January 31, 2024 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save program--/b1af98bf306d25c32dc19796c611c288 to your computer and use it in GitHub Desktop.
Save program--/b1af98bf306d25c32dc19796c611c288 to your computer and use it in GitHub Desktop.
Building R statically
#!/usr/bin/env bash
R_VERSION="4.3.2"
curl -O "https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz"
tar -xzvf "R-${R_VERSION}.tar.gz"
rm "R-${R_VERSION}.tar.gz"
cd "R-${R_VERSION}" || exit
mkdir build/
CC=clang \
CXX=clang++ \
FC=gfortran \
CFLAGS="-O3" \
CXXFLAGS="-O3" \
LDFLAGS="-Bstatic,-dn,-non_shared,-static" \
PKG_CONFIG="pkg-config --static" \
./configure \
--prefix="$(realpath build)" \
--disable-R-shlib \
--enable-R-static-lib \
--enable-static=yes \
--enable-shared=no \
--enable-long-double \
--disable-rpath \
--without-readline \
--without-tcltk \
--without-cairo \
--without-libpng \
--without-jpeglib \
--without-libtiff \
--with-internal-tzcode \
--with-internal-towlower \
--with-internal-iswxxxxx \
--with-internal-wcwidth \
--without-x
make
make install

Note

This is a work-in-progress.

This is an attempt at creating standalone R executables by embedding and evaluating R code through C via a static R build.

Currently, by using the below script, we receive libR.a and associated BLAS/LAPACK internal shared libraries. libR.A is ~6MiB, but is halved to ~3.3MiB when stripped. However, it's not completely static at this point, as some dependencies like PCRE are still dynamically linked (which, might be due to needing --enable-static=pcre or something?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment