Unverified Commit f4d10f1a authored by Toma's avatar Toma Committed by GitHub
Browse files

rstudio: clean up and refactor (#357034)

parents 80893e00 3ce431ad
Loading
Loading
Loading
Loading
+16 −36
Original line number Diff line number Diff line
diff --git a/src/cpp/core/libclang/LibClang.cpp b/src/cpp/core/libclang/LibClang.cpp
index f166a43b37..d8024b2ce7 100644
--- a/src/cpp/core/libclang/LibClang.cpp
+++ b/src/cpp/core/libclang/LibClang.cpp
@@ -62,7 +62,7 @@
 
    // we need to add in the associated libclang headers as
    // they are not discovered / used by default during compilation
-   FilePath llvmPath = s_libraryPath.getParent().getParent();
+   FilePath llvmPath("@libclang@");
    boost::format fmt("%1%/lib/clang/%2%/include");
    fmt % llvmPath.getAbsolutePath() % version.asString();
    std::string includePath = fmt.str();
@@ -74,47 +74,7 @@
 
 std::vector<std::string> systemClangVersions()
 {
-   std::vector<std::string> clangVersions;
-   
-#if defined(__APPLE__)
-   // NOTE: the version of libclang.dylib bundled with Xcode
-   // doesn't seem to work well when loaded as a library
-   // (there seems to be extra orchestration required to get
-   // include paths set up; easier to just depend on command
-   // line tools since we request their installation in other
-   // contexts as well)
-   clangVersions = {
@@ -84,34 +84,13 @@ std::vector<std::string> systemClangVersions()
    // line tools since we request their installation in other
    // contexts as well)
    clangVersions = {
-      "/Library/Developer/CommandLineTools/usr/lib/libclang.dylib"
-   };
-#elif defined(__unix__)
-   // default set of versions
-   clangVersions = {
+      "@libclang@/lib/libclang.dylib"
    };
 #elif defined(__unix__)
    // default set of versions
    clangVersions = {
-      "/usr/lib/libclang.so",
-      "/usr/lib/llvm/libclang.so",
-      "/usr/lib64/libclang.so",
-      "/usr/lib64/llvm/libclang.so",
-   };
+      "@libclang@/lib/libclang.so",
    };
-   
-   // iterate through the set of available 'llvm' directories
-   for (const char* prefix : {"/usr/lib", "/usr/lib64"})
@@ -51,11 +36,6 @@
-         if (path.getFilename().find("llvm") == 0)
-            clangVersions.push_back(path.completePath("lib/libclang.so.1").getAbsolutePath());
-   }
-#endif
-   
-   return clangVersions;
+    return std::vector<std::string> { "@libclang.so@" };
 }
 
 
 #endif
    
    return clangVersions;
+173 −202
Original line number Diff line number Diff line
{ lib
, stdenv
, mkDerivation
, fetchurl
, fetchFromGitHub
, makeDesktopItem
, copyDesktopItems
, cmake
, boost183
, zlib
, openssl
, R
, qtbase
, qtxmlpatterns
, qtsensors
, qtwebengine
, qtwebchannel
, quarto
, libuuid
, hunspellDicts
, unzip
, ant
, jdk
, gnumake
, pandoc
, llvmPackages
, yaml-cpp
, soci
, postgresql
, nodejs
, qmake
, server ? false # build server version
, sqlite
, pam
, nixosTests
{
  lib,
  stdenv,
  fetchzip,
  fetchFromGitHub,
  replaceVars,
  cmake,
  boost183,
  zlib,
  openssl,
  R,
  libsForQt5,
  quarto,
  libuuid,
  hunspellDicts,
  ant,
  jdk,
  gnumake,
  pandoc,
  llvmPackages,
  yaml-cpp,
  soci,
  sqlite,
  nodejs,
  yarn,
  yarnConfigHook,
  fetchYarnDeps,
  server ? false, # build server version
  pam,
  nixosTests,
}:

let
  pname = "RStudio";
  version = "2024.04.2+764";
  RSTUDIO_VERSION_MAJOR = lib.versions.major version;
  RSTUDIO_VERSION_MINOR = lib.versions.minor version;
  RSTUDIO_VERSION_PATCH = lib.versions.patch version;
  RSTUDIO_VERSION_SUFFIX = "+" + toString (
    lib.tail (lib.splitString "+" version)
  );

  src = fetchFromGitHub {
    owner = "rstudio";
    repo = "rstudio";
    rev = "v" + version;
    hash = "sha256-j258eW1MYQrB6kkpjyolXdNuwQ3zSWv9so4q0QLsZuw=";
  };

  mathJaxSrc = fetchurl {
  mathJaxSrc = fetchzip {
    url = "https://s3.amazonaws.com/rstudio-buildtools/mathjax-27.zip";
    hash = "sha256-xWy6psTOA8H8uusrXqPDEtL7diajYCVHcMvLiPsgQXY=";
  };

  rsconnectSrc = fetchFromGitHub {
    owner = "rstudio";
    repo = "rsconnect";
    rev = "v1.2.2";
    hash = "sha256-wvM9Bm7Nb6yU9z0o+uF5lB2kdgjOW5wZSk6y48NPF2U=";
    hash = "sha256-J7SZK/9q3HcXTD7WFHxvh++ttuCd89Vc4SEBrUEU0AI=";
  };

  # Ideally, rev should match the rstudio release name.
@@ -73,24 +45,46 @@ let
    hash = "sha256-lZnZvioztbBWWa6H177X6rRrrgACx2gMjVFDgNup93g=";
  };

  description = "Set of integrated tools for the R language";
  hunspellDictionaries = lib.filter lib.isDerivation (lib.unique (lib.attrValues hunspellDicts));
  # These dicts contain identically-named dict files, so we only keep the
  # -large versions in case of clashes
  largeDicts = lib.filter (d: lib.hasInfix "-large-wordlist" d.name) hunspellDictionaries;
  otherDicts = lib.filter (
    d: !(lib.hasAttr "dictFileName" d && lib.elem d.dictFileName (map (d: d.dictFileName) largeDicts))
  ) hunspellDictionaries;
  dictionaries = largeDicts ++ otherDicts;
in
(if server then stdenv.mkDerivation else mkDerivation)
  (rec {
    inherit pname version src RSTUDIO_VERSION_MAJOR RSTUDIO_VERSION_MINOR RSTUDIO_VERSION_PATCH RSTUDIO_VERSION_SUFFIX;
stdenv.mkDerivation rec {
  pname = "RStudio";
  version = "2024.04.2+764";

  RSTUDIO_VERSION_MAJOR = lib.versions.major version;
  RSTUDIO_VERSION_MINOR = lib.versions.minor version;
  RSTUDIO_VERSION_PATCH = lib.versions.patch version;
  RSTUDIO_VERSION_SUFFIX = "+" + toString (lib.tail (lib.splitString "+" version));

    nativeBuildInputs = [
  src = fetchFromGitHub {
    owner = "rstudio";
    repo = "rstudio";
    rev = "refs/tags/v${version}";
    hash = "sha256-j258eW1MYQrB6kkpjyolXdNuwQ3zSWv9so4q0QLsZuw=";
  };

  nativeBuildInputs =
    [
      cmake
      unzip
      ant
      jdk
      pandoc
      nodejs
    ] ++ lib.optionals (!server) [
      copyDesktopItems
      yarn
      yarnConfigHook
    ]
    ++ lib.optionals (!server) [
      libsForQt5.wrapQtAppsHook
    ];

    buildInputs = [
  buildInputs =
    [
      boost183
      zlib
      openssl
@@ -98,77 +92,76 @@ in
      libuuid
      yaml-cpp
      soci
      postgresql
      quarto
    ] ++ (if server then [
      sqlite.dev
      pam
    ] else [
      qtbase
      qtxmlpatterns
      qtsensors
      qtwebengine
      qtwebchannel
    ]);

    cmakeFlags = [
      "-DRSTUDIO_TARGET=${if server then "Server" else "Desktop"}"
      "-DRSTUDIO_USE_SYSTEM_SOCI=ON"
      "-DRSTUDIO_USE_SYSTEM_BOOST=ON"
      "-DRSTUDIO_USE_SYSTEM_YAML_CPP=ON"
      "-DRSTUDIO_DISABLE_CHECK_FOR_UPDATES=ON"
      "-DQUARTO_ENABLED=TRUE"
      "-DPANDOC_VERSION=${pandoc.version}"
      "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}/lib/rstudio"
    ] ++ lib.optionals (!server) [
      "-DQT_QMAKE_EXECUTABLE=${qmake}/bin/qmake"
    ]
    ++ lib.optionals server [ pam ]
    ++ lib.optionals (!server) [
      libsForQt5.qtbase
      libsForQt5.qtxmlpatterns
      libsForQt5.qtsensors
      libsForQt5.qtwebengine
      libsForQt5.qtwebchannel
    ];

  cmakeFlags =
    [
      (lib.cmakeFeature "RSTUDIO_TARGET" (if server then "Server" else "Desktop"))
      (lib.cmakeBool "RSTUDIO_USE_SYSTEM_SOCI" true)
      (lib.cmakeBool "RSTUDIO_USE_SYSTEM_BOOST" true)
      (lib.cmakeBool "RSTUDIO_USE_SYSTEM_YAML_CPP" true)
      (lib.cmakeBool "RSTUDIO_DISABLE_CHECK_FOR_UPDATES" true)
      (lib.cmakeBool "QUARTO_ENABLED" true)
      (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/lib/rstudio")
    ]
    ++ lib.optionals (!server) [
      (lib.cmakeFeature "QT_QMAKE_EXECUTABLE" "${libsForQt5.qmake}/bin/qmake")
      (lib.cmakeBool "RSTUDIO_INSTALL_FREEDESKTOP" true)
    ];

    # Hack RStudio to only use the input R and provided libclang.
  patches = [
      ./r-location.patch
      ./clang-location.patch
      ./use-system-node.patch
    # Hack RStudio to only use the input R and provided libclang.
    (replaceVars ./r-location.patch {
      R = lib.getBin R;
    })
    (replaceVars ./clang-location.patch {
      libclang = lib.getLib llvmPackages.libclang;
    })

    ./fix-resources-path.patch
      ./pandoc-nix-path.patch
      ./use-system-quarto.patch
    ./ignore-etc-os-release.patch
    ./dont-yarn-install.patch
    ./dont-assume-pandoc-in-quarto.patch
  ];

  postPatch = ''
      substituteInPlace src/cpp/core/r_util/REnvironmentPosix.cpp --replace-fail '@R@' ${R}
    # fix .desktop Exec field
    substituteInPlace src/node/desktop/resources/freedesktop/rstudio.desktop.in \
      --replace-fail "''${CMAKE_INSTALL_PREFIX}/rstudio" "rstudio"

      substituteInPlace src/gwt/build.xml \
        --replace-fail '@node@' ${nodejs} \
        --replace-fail './lib/quarto' ${quartoSrc}
    # set install path of freedesktop files
    substituteInPlace src/{cpp,node}/desktop/CMakeLists.txt \
      --replace-fail "/usr/share" "$out/share"
  '';

      substituteInPlace src/cpp/conf/rsession-dev.conf \
        --replace-fail '@node@' ${nodejs}
  yarnOfflineCache = fetchYarnDeps {
    yarnLock = quartoSrc + "/yarn.lock";
    hash = "sha256-Qw8O1Jzl2EO0DEF3Jrw/cIT9t22zs3jyKgDA5XZbuGA=";
  };

      substituteInPlace src/cpp/core/libclang/LibClang.cpp \
        --replace-fail '@libclang@' ${lib.getLib llvmPackages.libclang} \
        --replace-fail '@libclang.so@' ${lib.getLib llvmPackages.libclang}/lib/libclang.so
  dontYarnInstallDeps = true; # will call manually in preConfigure

      substituteInPlace src/cpp/session/CMakeLists.txt \
        --replace-fail '@pandoc@' ${pandoc} \
        --replace-fail '@quarto@' ${quarto}
  preConfigure = ''
    # set up node_modules directory inside quarto so that panmirror can be built
    mkdir src/gwt/lib/quarto
    cp -r --no-preserve=all ${quartoSrc}/* src/gwt/lib/quarto
    pushd src/gwt/lib/quarto
    yarnConfigHook
    popd

      substituteInPlace src/cpp/session/include/session/SessionConstants.hpp \
        --replace-fail '@pandoc@' ${pandoc}/bin \
        --replace-fail '@quarto@' ${quarto}
    '';
    ### set up dependencies that will be copied into the result
    # note: only the directory names have to match upstream, the actual versions don't
    # note: symlinks are preserved

    hunspellDictionaries = lib.filter lib.isDerivation (lib.unique (lib.attrValues hunspellDicts));
    # These dicts contain identically-named dict files, so we only keep the
    # -large versions in case of clashes
    largeDicts = lib.filter (d: lib.hasInfix "-large-wordlist" d.name) hunspellDictionaries;
    otherDicts = lib.filter
      (d: !(lib.hasAttr "dictFileName" d &&
        lib.elem d.dictFileName (map (d: d.dictFileName) largeDicts)))
      hunspellDictionaries;
    dictionaries = largeDicts ++ otherDicts;

    preConfigure = ''
    mkdir dependencies/dictionaries
    for dict in ${builtins.concatStringsSep " " dictionaries}; do
      for i in "$dict/share/hunspell/"*; do
@@ -176,75 +169,53 @@ in
      done
    done

      unzip -q ${mathJaxSrc} -d dependencies/mathjax-27
    ln -s ${quarto} dependencies/quarto

     # As of Chocolate Cosmos, node 18.20.3 is used for runtime
     # 18.18.2 is still used for build
     # see https://github.com/rstudio/rstudio/commit/facb5cf1ab38fe77813aaf36590804e4f865d780
     mkdir -p dependencies/common/node/18.20.3
    # version in dependencies/common/install-mathjax
    ln -s ${mathJaxSrc} dependencies/mathjax-27

      mkdir -p dependencies/pandoc/${pandoc.version}
      cp ${pandoc}/bin/pandoc dependencies/pandoc/${pandoc.version}/pandoc
    # version in CMakeGlobals.txt (PANDOC_VERSION)
    mkdir -p dependencies/pandoc/2.18
    ln -s ${lib.getBin pandoc}/bin/* dependencies/pandoc/2.18

      cp -r ${rsconnectSrc} dependencies/rsconnect
      ( cd dependencies && ${R}/bin/R CMD build -d --no-build-vignettes rsconnect )
    # version in CMakeGlobals.txt (RSTUDIO_INSTALLED_NODE_VERSION)
    mkdir -p dependencies/common/node
    ln -s ${nodejs} dependencies/common/node/18.20.3
  '';

  postInstall = ''
      mkdir -p $out/bin $out/share
    mkdir -p $out/bin

      ${lib.optionalString (!server) ''
        mkdir -p $out/share/icons/hicolor/48x48/apps
        ln $out/lib/rstudio/rstudio.png $out/share/icons/hicolor/48x48/apps
    ${lib.optionalString server ''
      ln -s $out/lib/rstudio/bin/{crash-handler-proxy,postback,r-ldpath,rpostback,rserver,rserver-pam,rsession,rstudio-server} $out/bin
    ''}

      for f in {${if server
        then "crash-handler-proxy,postback,r-ldpath,rpostback,rserver,rserver-pam,rsession,rstudio-server"
        else "diagnostics,rpostback,rstudio"}}; do
        ln -s $out/lib/rstudio/bin/$f $out/bin
      done
    ${lib.optionalString (!server) ''
      ln -s $out/lib/rstudio/bin/{diagnostics,rpostback,rstudio} $out/bin
    ''}
  '';

      for f in .gitignore .Rbuildignore LICENSE README; do
        find . -name $f -delete
      done
  qtWrapperArgs = lib.optionals (!server) [
    "--suffix PATH : ${lib.makeBinPath [ gnumake ]}"
  ];

      rm -r $out/lib/rstudio/{INSTALL,COPYING,NOTICE,README.md,SOURCE,VERSION}
    '';
  passthru = {
    inherit server;
    tests = {
      inherit (nixosTests) rstudio-server;
    };
  };

  meta = {
    broken = (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
      inherit description;
    description = "Set of integrated tools for the R language";
    homepage = "https://www.rstudio.com/";
    license = lib.licenses.agpl3Only;
      maintainers = with lib.maintainers; [ ciil cfhammill ];
    maintainers = with lib.maintainers; [
      ciil
      cfhammill
    ];
    mainProgram = "rstudio" + lib.optionalString server "-server";
    platforms = lib.platforms.linux;
  };

    passthru = {
      inherit server;
      tests = { inherit (nixosTests) rstudio-server; };
    };
  } // lib.optionalAttrs (!server) {
    qtWrapperArgs = [
      "--suffix PATH : ${lib.makeBinPath [ gnumake ]}"
    ];

    desktopItems = [
      (makeDesktopItem {
        name = pname;
        exec = "rstudio %F";
        icon = "rstudio";
        desktopName = "RStudio";
        genericName = "IDE";
        comment = description;
        categories = [ "Development" ];
        mimeTypes = [
          "text/x-r-source" "text/x-r" "text/x-R" "text/x-r-doc" "text/x-r-sweave" "text/x-r-markdown"
          "text/x-r-html" "text/x-r-presentation" "application/x-r-data" "application/x-r-project"
          "text/x-r-history" "text/x-r-profile" "text/x-tex" "text/x-markdown" "text/html"
          "text/css" "text/javascript" "text/x-chdr" "text/x-csrc" "text/x-c++hdr" "text/x-c++src"
        ];
      })
    ];
  })
}
+48 −0
Original line number Diff line number Diff line
diff --git a/src/cpp/session/CMakeLists.txt b/src/cpp/session/CMakeLists.txt
index 0202e84..596b9f8 100644
--- a/src/cpp/session/CMakeLists.txt
+++ b/src/cpp/session/CMakeLists.txt
@@ -59,11 +59,7 @@ endif()
 
 
 # install pandoc
-# - by default, we use quarto + quarto's bundled pandoc
-# - if quarto is not enabled, use pandoc fallback
-if(QUARTO_ENABLED)
-   set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_DEPENDENCIES_QUARTO_DIR}/bin/tools")
-elseif(EXISTS "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
+if(EXISTS "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
    set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
 else()
    set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_DEPENDENCIES_DIR}/pandoc/${PANDOC_VERSION}")
@@ -733,11 +729,10 @@ if(NOT RSTUDIO_SESSION_WIN32 AND NOT RSESSION_ALTERNATE_BUILD)
                PATTERN ".gitignore"
                EXCLUDE)
       endif()
-   else()
-      install(DIRECTORY "${RSTUDIO_DEPENDENCIES_PANDOC_DIR}/"
-              DESTINATION "${RSTUDIO_INSTALL_BIN}/pandoc"
-              USE_SOURCE_PERMISSIONS)
    endif()
+   install(DIRECTORY "${RSTUDIO_DEPENDENCIES_PANDOC_DIR}/"
+           DESTINATION "${RSTUDIO_INSTALL_BIN}/pandoc"
+           USE_SOURCE_PERMISSIONS)
 
    # install embedded packages
    foreach(PKG ${RSTUDIO_EMBEDDED_PACKAGES})
diff --git a/src/cpp/session/include/session/SessionConstants.hpp b/src/cpp/session/include/session/SessionConstants.hpp
index e6aef22..57491ec 100644
--- a/src/cpp/session/include/session/SessionConstants.hpp
+++ b/src/cpp/session/include/session/SessionConstants.hpp
@@ -147,11 +147,7 @@
 #define kSessionTmpDirEnvVar       "RS_SESSION_TMP_DIR"
 #define kSessionTmpDir             "rstudio-rsession"
 
-#ifdef QUARTO_ENABLED
-# define kDefaultPandocPath        "bin/quarto/bin/tools"
-#else
 # define kDefaultPandocPath        "bin/pandoc"
-#endif
 
 #define kDefaultNodePath           "bin/node"
 #define kDefaultQuartoPath         "bin/quarto"
+16 −0
Original line number Diff line number Diff line
diff --git a/src/gwt/build.xml b/src/gwt/build.xml
index 27ffe33..4218678 100644
--- a/src/gwt/build.xml
+++ b/src/gwt/build.xml
@@ -139,11 +139,6 @@
       <echo message="panmirror minify: ${panmirror.minify}"/>
 
       <mkdir dir="${panmirror.build.dir}"/>
-      <exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
-         <arg value="install"/>
-         <arg value="--network-timeout"/>
-         <arg value="240000"/>
-      </exec>
       <exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
          <arg value="build"/>
          <arg value="--minify"/>
+0 −18
Original line number Diff line number Diff line
--- a/src/cpp/session/include/session/SessionConstants.hpp
+++ b/src/cpp/session/include/session/SessionConstants.hpp
@@ -142,13 +142,13 @@
 #define kSessionTmpDir             "rstudio-rsession"
 
 #ifdef QUARTO_ENABLED
-# define kDefaultPandocPath        "bin/quarto/bin/tools"
+# define kDefaultPandocPath        "@pandoc@"
 #else
 # define kDefaultPandocPath        "bin/pandoc"
 #endif
 
 #define kDefaultNodePath           "bin/node"
-#define kDefaultQuartoPath         "bin/quarto"
+#define kDefaultQuartoPath         "@quarto@"
 #define kDefaultRsclangPath        "bin/rsclang"
 
 #ifdef _WIN32
Loading