diff --git a/README.md b/README.md index 0751079..0521f7c 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,51 @@ This repository orchestrates builds using a variety of tools. The instructions below outline the components in the stack and describe how to add a new platform or inspect an existing platform. +## Building from source + +To build the R binaries from source, you will need to have [Git](https://git-scm.com/), +[Docker](https://docs.docker.com/get-docker/), and `make` installed. + +First, clone the Git repository locally and navigate to it. + +```bash +git clone https://github.com/rstudio/R-builds +cd R-builds +``` + +Then, run the `build-r-$PLATFORM` Make target with the `R_VERSION` environment variable +set to your desired R version, where `$PLATFORM` is one of the supported platform +identifiers, such as `ubuntu-2204` or `rhel-9`. + +```bash +export PLATFORM=ubuntu-2204 +export R_VERSION=4.1.3 + +make build-r-$PLATFORM +``` + +The built DEB or RPM package will be available in the `builder/integration/tmp/$PLATFORM` +directory. + +```bash +$ ls builder/integration/tmp/$PLATFORM +r-4.1.3_1_amd64.deb +``` + +### Custom installation path + +R is installed to `/opt/R/${R_VERSION}` by default. If you want to customize the +installation path, set the optional `R_INSTALL_PATH` environment variable to a +custom location such as `/opt/custom/R-4.1.3`. + +```bash +export PLATFORM=rhel-9 +export R_VERSION=4.1.3 +export R_INSTALL_PATH=/opt/custom/R-4.1.3 + +make build-r-$PLATFORM +``` + ## Adding a new platform. ### Dockerfile diff --git a/builder/build.sh b/builder/build.sh index 565a677..7445846 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -5,6 +5,7 @@ export CRAN=${CRAN-"https://cran.rstudio.com"} export S3_BUCKET_PREFIX=${S3_BUCKET_PREFIX-""} export OS_IDENTIFIER=${OS_IDENTIFIER-"unknown"} export TARBALL_NAME="R-${R_VERSION}-${OS_IDENTIFIER}.tar.gz" +export R_INSTALL_PATH=${R_INSTALL_PATH:-"/opt/R/${R_VERSION}"} # Some Dockerfiles may copy a `/env.sh` to set up environment variables # that require command substitution. If this file exists, source it. @@ -33,9 +34,11 @@ upload_r() { fi } -# archive_r() - $1 as r version +# archive_r() archive_r() { - tar czf /tmp/${TARBALL_NAME} --directory=/opt/R ${1} --owner=0 --group=0 + dir=$(dirname "$R_INSTALL_PATH") + base=$(basename "$R_INSTALL_PATH") + tar czf "/tmp/${TARBALL_NAME}" --directory="$dir" "$base" --owner=0 --group=0 } fetch_r_source() { @@ -130,7 +133,7 @@ compile_r() { R_UNZIPCMD=/usr/bin/unzip \ R_ZIPCMD=/usr/bin/zip \ ./configure \ - --prefix=/opt/R/${1} \ + --prefix="${R_INSTALL_PATH}" \ ${CONFIGURE_OPTIONS} \ ${build_flag} make clean @@ -139,7 +142,7 @@ compile_r() { # Add OS identifier to the default HTTP user agent. # Set this in the system Rprofile so it works when R is run with --vanilla. - cat <> /opt/R/${1}/lib/R/library/base/R/Rprofile + cat <> "${R_INSTALL_PATH}"/lib/R/library/base/R/Rprofile ## Set the default HTTP user agent local({ os_identifier <- if (file.exists("/etc/os-release")) { @@ -167,7 +170,7 @@ package_r() { } set_up_environment() { - mkdir -p /opt/R + mkdir -p "$R_INSTALL_PATH" } _version_is_greater_than() { @@ -183,5 +186,5 @@ set_up_environment fetch_r_source $R_VERSION compile_r $R_VERSION package_r $R_VERSION -archive_r $R_VERSION +archive_r upload_r $R_VERSION diff --git a/builder/docker-compose.yml b/builder/docker-compose.yml index 0740b46..889cb28 100644 --- a/builder/docker-compose.yml +++ b/builder/docker-compose.yml @@ -3,6 +3,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -14,6 +15,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -25,6 +27,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -36,6 +39,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -47,6 +51,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -58,6 +63,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -69,6 +75,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -80,6 +87,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -91,6 +99,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . @@ -102,6 +111,7 @@ services: command: ./build.sh environment: - R_VERSION=${R_VERSION} + - R_INSTALL_PATH=${R_INSTALL_PATH} - LOCAL_STORE=/tmp/output build: context: . diff --git a/builder/package.centos-7 b/builder/package.centos-7 index 3eda5f4..77b5632 100644 --- a/builder/package.centos-7 +++ b/builder/package.centos-7 @@ -12,14 +12,14 @@ fi # create post-install script required for openblas cat <> /post-install.sh -mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep -ln -s /usr/lib64/libopenblasp.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so +mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep +ln -s /usr/lib64/libopenblasp.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so EOF # create after-remove script to remove internal blas cat <> /after-remove.sh -if [ -d /opt/R/${R_VERSION} ]; then - rm -r /opt/R/${R_VERSION} +if [ -d ${R_INSTALL_PATH} ]; then + rm -r ${R_INSTALL_PATH} fi EOF @@ -57,8 +57,8 @@ depends: - zip - zlib-devel contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} scripts: postinstall: /post-install.sh postremove: /after-remove.sh diff --git a/builder/package.centos-8 b/builder/package.centos-8 index 78933d6..3b2cdb4 100644 --- a/builder/package.centos-8 +++ b/builder/package.centos-8 @@ -12,14 +12,14 @@ fi # create post-install script required for openblas cat <> /post-install.sh -mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep -ln -s /usr/lib64/libopenblasp.so.0 /opt/R/${R_VERSION}/lib/R/lib/libRblas.so +mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep +ln -s /usr/lib64/libopenblasp.so.0 ${R_INSTALL_PATH}/lib/R/lib/libRblas.so EOF # create after-remove script to remove internal blas cat <> /after-remove.sh -if [ -d /opt/R/${R_VERSION} ]; then - rm -r /opt/R/${R_VERSION} +if [ -d ${R_INSTALL_PATH} ]; then + rm -r ${R_INSTALL_PATH} fi EOF @@ -57,8 +57,8 @@ depends: - zip - zlib-devel contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} scripts: postinstall: /post-install.sh postremove: /after-remove.sh diff --git a/builder/package.debian-10 b/builder/package.debian-10 index c4dbc5e..42f8b9d 100644 --- a/builder/package.debian-10 +++ b/builder/package.debian-10 @@ -56,8 +56,8 @@ depends: - zip - zlib1g-dev contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} EOF nfpm package \ diff --git a/builder/package.debian-11 b/builder/package.debian-11 index a14c265..5c9dd91 100644 --- a/builder/package.debian-11 +++ b/builder/package.debian-11 @@ -57,8 +57,8 @@ ${pcre_libs} - zip - zlib1g-dev contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} EOF nfpm package \ diff --git a/builder/package.opensuse-153 b/builder/package.opensuse-153 index 5df79cd..6a1517e 100644 --- a/builder/package.opensuse-153 +++ b/builder/package.opensuse-153 @@ -12,14 +12,14 @@ fi # create post-install script required for openblas cat <> /post-install.sh -mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep -ln -s /usr/lib64/libopenblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so +mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep +ln -s /usr/lib64/libopenblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so EOF # create after-remove script to remove internal blas cat <> /after-remove.sh -if [ -d /opt/R/${R_VERSION} ]; then - rm -r /opt/R/${R_VERSION} +if [ -d ${R_INSTALL_PATH} ]; then + rm -r ${R_INSTALL_PATH} fi EOF @@ -66,8 +66,8 @@ depends: - zip - zlib-devel contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} scripts: postinstall: /post-install.sh postremove: /after-remove.sh diff --git a/builder/package.opensuse-154 b/builder/package.opensuse-154 index 1fbb819..733acff 100644 --- a/builder/package.opensuse-154 +++ b/builder/package.opensuse-154 @@ -28,14 +28,14 @@ fi # # https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Shared-BLAS cat <> /post-install.sh -mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep -ln -s /usr/lib64/libopenblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so +mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep +ln -s /usr/lib64/libopenblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so EOF # Create after-remove script to remove internal BLAS, which won't be cleaned up automatically. cat <> /after-remove.sh -if [ -d /opt/R/${R_VERSION} ]; then - rm -r /opt/R/${R_VERSION} +if [ -d ${R_INSTALL_PATH} ]; then + rm -r ${R_INSTALL_PATH} fi EOF @@ -82,8 +82,8 @@ depends: - zip - zlib-devel contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} scripts: postinstall: /post-install.sh postremove: /after-remove.sh diff --git a/builder/package.rhel-9 b/builder/package.rhel-9 index ee1a376..8428069 100644 --- a/builder/package.rhel-9 +++ b/builder/package.rhel-9 @@ -29,14 +29,14 @@ fi # # https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Shared-BLAS cat <> /post-install.sh -mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep -ln -s /usr/lib64/libopenblasp.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so +mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep +ln -s /usr/lib64/libopenblasp.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so EOF # Create after-remove script to remove internal BLAS, which won't be cleaned up automatically. cat <> /after-remove.sh -if [ -d /opt/R/${R_VERSION} ]; then - rm -r /opt/R/${R_VERSION} +if [ -d ${R_INSTALL_PATH} ]; then + rm -r ${R_INSTALL_PATH} fi EOF @@ -74,8 +74,8 @@ ${pcre_libs} - zip - zlib-devel contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} scripts: postinstall: /post-install.sh postremove: /after-remove.sh diff --git a/builder/package.ubuntu-1804 b/builder/package.ubuntu-1804 index a696b9f..9d448f3 100644 --- a/builder/package.ubuntu-1804 +++ b/builder/package.ubuntu-1804 @@ -56,8 +56,8 @@ depends: - zip - zlib1g-dev contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} EOF nfpm package \ diff --git a/builder/package.ubuntu-2004 b/builder/package.ubuntu-2004 index e6648bd..a1b0eb4 100644 --- a/builder/package.ubuntu-2004 +++ b/builder/package.ubuntu-2004 @@ -57,8 +57,8 @@ depends: - zip - zlib1g-dev contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} EOF nfpm package \ diff --git a/builder/package.ubuntu-2204 b/builder/package.ubuntu-2204 index b3d5302..eea65fb 100644 --- a/builder/package.ubuntu-2204 +++ b/builder/package.ubuntu-2204 @@ -57,8 +57,8 @@ ${pcre_libs} - zip - zlib1g-dev contents: -- src: /opt/R/${R_VERSION} - dst: /opt/R/${R_VERSION} +- src: ${R_INSTALL_PATH} + dst: ${R_INSTALL_PATH} EOF nfpm package \