diff --git a/pkgs/development/compilers/jetbrains-jdk/default.nix b/pkgs/development/compilers/jetbrains-jdk/default.nix index 49182468edd8a..51843b63f5ba7 100644 --- a/pkgs/development/compilers/jetbrains-jdk/default.nix +++ b/pkgs/development/compilers/jetbrains-jdk/default.nix @@ -6,6 +6,7 @@ jdk, git, autoconf, + zip, unzip, rsync, debugBuild ? false, @@ -26,6 +27,7 @@ libgbm, wayland, udev, + darwin, }: assert debugBuild -> withJcef; @@ -35,9 +37,12 @@ let { "aarch64-linux" = "aarch64"; "x86_64-linux" = "x64"; + "aarch64-darwin" = "aarch64"; + "x86_64-darwin" = "x64"; } - .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + .${stdenv.hostPlatform.system}; cpu = stdenv.hostPlatform.parsed.cpu.name; + os = if stdenv.isDarwin then "macosx" else "linux"; in jdk.overrideAttrs (oldAttrs: rec { pname = "jetbrains-jdk" + lib.optionalString withJcef "-jcef"; @@ -66,49 +71,104 @@ jdk.overrideAttrs (oldAttrs: rec { dontConfigure = true; - buildPhase = '' - runHook preBuild - - ${lib.optionalString withJcef "cp -r ${jetbrains.jcef} jcef_linux_${arch}"} - - sed \ - -e "s/OPENJDK_TAG=.*/OPENJDK_TAG=${openjdkTag}/" \ - -e "s/SOURCE_DATE_EPOCH=.*//" \ - -e "s/export SOURCE_DATE_EPOCH//" \ - -i jb/project/tools/common/scripts/common.sh - configureFlags=$(echo $configureFlags | sed 's/--host=[^ ]*//') - sed -i "s|STATIC_CONF_ARGS|STATIC_CONF_ARGS \$configureFlags|" jb/project/tools/linux/scripts/mkimages_${arch}.sh - sed \ - -e "s/create_image_bundle \"jb/#/" \ - -e "s/echo Creating /exit 0 #/" \ - -i jb/project/tools/linux/scripts/mkimages_${arch}.sh - - patchShebangs . - ./jb/project/tools/linux/scripts/mkimages_${arch}.sh ${build} ${ - if debugBuild then "fd" else (if withJcef then "jcef" else "nomod") - } + jcefDestName = if stdenv.isDarwin then "jcef_mac" else "jcef_linux_${arch}"; - runHook postBuild - ''; + mkimagesSh = + if stdenv.isDarwin then + "./jb/project/tools/mac/scripts/mkimages.sh" + else + "./jb/project/tools/linux/scripts/mkimages_${arch}.sh"; + + osSpecificPatch = + if stdenv.isDarwin then + '' + sed -i '40i\--with-xcode-path="${darwin.xcode_16_1}" \\' ./jb/project/tools/mac/scripts/mkimages.sh + # See https://github.com/JetBrains/JetBrainsRuntime/issues/461 + sed \ + -e 's/C_O_FLAG_HIGHEST_JVM="-O3"/C_O_FLAG_HIGHEST_JVM="-O1"/g' \ + -e 's/C_O_FLAG_HIGHEST="-O3"/C_O_FLAG_HIGHEST="-O1"/g' \ + -e 's/C_O_FLAG_HI="-O3"/C_O_FLAG_HI="-O1"/g' \ + -i make/autoconf/flags-cflags.m4 + '' + else + ""; + + buildPhase = + '' + runHook preBuild + + ${lib.optionalString withJcef "cp -r ${jetbrains.jcef} ${jcefDestName}"} + + ${osSpecificPatch} + + configureFlags=$(echo $configureFlags | sed 's/--host=[^ ]*//') + sed -i "s|STATIC_CONF_ARGS|STATIC_CONF_ARGS \$configureFlags|" ${mkimagesSh} + sed \ + -e "s/create_image_bundle \"jb/#/" \ + -e "s/echo Creating /exit 0 #/" \ + -i ${mkimagesSh} + sed \ + -e "s/OPENJDK_TAG=.*/OPENJDK_TAG=${openjdkTag}/" \ + -e "s/SOURCE_DATE_EPOCH=.*//" \ + -e "s/export SOURCE_DATE_EPOCH//" \ + -e "s/date -u -r /date --utc --date=@/" \ + -i jb/project/tools/common/scripts/common.sh + + patchShebangs . + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + export PATH=${darwin.xcode_16_1}/Contents/Developer/usr/bin/:${darwin.xcode_16_1}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH + export MIGCC=${darwin.xcode_16_1}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc + unset SDKROOT + '' + + '' + ${mkimagesSh} ${build} ${ + if debugBuild then "fd" else (if withJcef then "jcef" else "nomod") + } ${arch} + + runHook postBuild + ''; installPhase = let buildType = if debugBuild then "fastdebug" else "release"; debugSuffix = if debugBuild then "-fastdebug" else ""; jcefSuffix = if debugBuild || !withJcef then "" else "_jcef"; - jbrsdkDir = "jbrsdk${jcefSuffix}-${javaVersion}-linux-${arch}${debugSuffix}-b${build}"; + jbrsdkDir = "jbrsdk${jcefSuffix}-${javaVersion}-${os}-${arch}${debugSuffix}-b${build}"; in - '' - runHook preInstall + ( + if stdenv.isLinux then + '' + runHook preInstall - mv build/linux-${cpu}-server-${buildType}/images/jdk/man build/linux-${cpu}-server-${buildType}/images/${jbrsdkDir} - rm -rf build/linux-${cpu}-server-${buildType}/images/jdk - mv build/linux-${cpu}-server-${buildType}/images/${jbrsdkDir} build/linux-${cpu}-server-${buildType}/images/jdk - '' - + oldAttrs.installPhase + mv build/${os}-${cpu}-server-${buildType}/images/jdk/man build/${os}-${cpu}-server-${buildType}/images/${jbrsdkDir} + rm -rf build/${os}-${cpu}-server-${buildType}/images/jdk + mv build/${os}-${cpu}-server-${buildType}/images/${jbrsdkDir} build/${os}-${cpu}-server-${buildType}/images/jdk + '' + + oldAttrs.installPhase + else + '' + # We need to implement the install phase manually because the default jdk is zulu instead of OpenJDK. + mkdir -p $out/lib + + cp -r build/${os}-${cpu}-server-${buildType}/images/jdk $out/lib/openjdk + + # Remove some broken manpages. + rm -rf $out/lib/openjdk/man/ja* + + # Mirror some stuff in top-level. + mkdir -p $out/share + ln -s $out/lib/openjdk/include $out/include + ln -s $out/lib/openjdk/man $out/share/man + ln -s $out/lib/openjdk/lib/src.zip $out/lib/src.zip + ln -s $out/include/linux/*_md.h $out/include/ + ln -s $out/lib/openjdk/bin $out/bin + '' + ) + "runHook postInstall"; - postInstall = lib.optionalString withJcef '' + # This is only available on Linux https://github.com/JetBrains/JetBrainsRuntime/releases/tag/jbr-release-21.0.6b631.42 + postInstall = lib.optionalString (withJcef && stdenv.isLinux) '' chmod +x $out/lib/openjdk/lib/chrome-sandbox ''; @@ -117,23 +177,27 @@ jdk.overrideAttrs (oldAttrs: rec { postFixup = '' # Build the set of output library directories to rpath against LIBDIRS="${ - lib.makeLibraryPath [ - libXdamage - libXxf86vm - libXrandr - libXi - libXcursor - libXrender - libX11 - libXext - libxcb - nss - nspr - libdrm - libgbm - wayland - udev - ] + lib.makeLibraryPath ( + [ + libXdamage + libXxf86vm + libXrandr + libXi + libXcursor + libXrender + libX11 + libXext + libxcb + nss + nspr + wayland + ] + ++ lib.optionals stdenv.isLinux [ + libgbm + libdrm + udev + ] + ) }" for output in $outputs; do if [ "$output" = debug ]; then continue; fi @@ -151,12 +215,21 @@ jdk.overrideAttrs (oldAttrs: rec { done ''; - nativeBuildInputs = [ - git - autoconf - unzip - rsync - ] ++ oldAttrs.nativeBuildInputs; + nativeBuildInputs = + [ + git + autoconf + zip + unzip + rsync + ] + ++ oldAttrs.nativeBuildInputs + ++ lib.optionals stdenv.isDarwin [ + darwin.bootstrap_cmds + darwin.xattr + darwin.stubs.setfile + darwin.xcode_16_1 + ]; meta = with lib; { description = "OpenJDK fork to better support Jetbrains's products"; @@ -176,8 +249,6 @@ jdk.overrideAttrs (oldAttrs: rec { edwtjo aoli-al ]; - - broken = stdenv.hostPlatform.isDarwin; }; passthru = oldAttrs.passthru // { diff --git a/pkgs/development/compilers/jetbrains-jdk/jcef.nix b/pkgs/development/compilers/jetbrains-jdk/jcef.nix index 7a7b98e510dde..d52d3ab9d295e 100644 --- a/pkgs/development/compilers/jetbrains-jdk/jcef.nix +++ b/pkgs/development/compilers/jetbrains-jdk/jcef.nix @@ -44,46 +44,51 @@ udev, boost, thrift, + darwin, + apple-sdk_15, }: -assert !stdenv.hostPlatform.isDarwin; -# I can't test darwin - let - rpath = lib.makeLibraryPath [ - glib - nss - nspr - atk - at-spi2-atk - libdrm - libGL - expat - libxcb - libxkbcommon - libX11 - libXcomposite - libXdamage - libXext - libXfixes - libXrandr - libgbm - gtk3 - pango - cairo - alsa-lib - dbus - at-spi2-core - cups - libxshmfence - udev - ]; + rpath = lib.makeLibraryPath ( + [ + glib + nss + nspr + atk + at-spi2-atk + expat + libxcb + libxkbcommon + libX11 + libXcomposite + libXdamage + libXext + libXfixes + libXrandr + gtk3 + pango + cairo + dbus + at-spi2-core + cups + libxshmfence + ] + ++ lib.optionals stdenv.isLinux [ + libdrm + libGL + libgbm + alsa-lib + udev + ] + ); buildType = if debugBuild then "Debug" else "Release"; platform = { "aarch64-linux" = "linuxarm64"; "x86_64-linux" = "linux64"; + "aarch64-darwin" = "macosarm64"; + "x86_64-darwin" = "macosx64"; } .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); arches = @@ -93,11 +98,21 @@ let projectArch = "arm64"; targetArch = "arm64"; }; + "macosarm64" = { + depsArch = "universal"; + projectArch = "arm64"; + targetArch = "arm64"; + }; "linux64" = { depsArch = "amd64"; projectArch = "x86_64"; targetArch = "x86_64"; }; + "macosx64" = { + depsArch = "universal"; + projectArch = "x86_64"; + targetArch = "x86_64"; + }; } .${platform}; inherit (arches) depsArch projectArch targetArch; @@ -111,25 +126,33 @@ stdenv.mkDerivation rec { # Run `git rev-list --count HEAD` version = "867"; - nativeBuildInputs = [ - cmake - python3 - jdk - git - rsync - ant - ninja - strip-nondeterminism - stripJavaArchivesHook - ]; - buildInputs = [ - boost - libX11 - libXdamage - nss - nspr - thrift - ]; + nativeBuildInputs = + [ + cmake + python3 + jdk + git + rsync + ant + ninja + strip-nondeterminism + stripJavaArchivesHook + ] + ++ lib.optionals stdenv.isDarwin [ + darwin.xcode_16_1 + ]; + buildInputs = + [ + boost + libX11 + libXdamage + nss + nspr + thrift + ] + ++ lib.optionals stdenv.isDarwin [ + apple-sdk_15 + ]; src = fetchFromGitHub { owner = "jetbrains"; @@ -145,6 +168,8 @@ stdenv.mkDerivation rec { { "linuxarm64" = "sha256-wABtvz0JHitlkkB748I7yr02Oxs5lXvqDfrBAQiKWHU="; "linux64" = "sha256-qlutM0IsE1emcMe/3p7kwMIK7ou1rZGvpUkrSMVPnCc="; + "macosx64" = "sha256-BkG/duc49skqOLSgkKSNlsm4H6egUgNqBt8snJrc7MU="; + "macosarm64" = "sha256-5WKGRDOrZqcVIWuPw4TIsoGwvSkyiOUzwHXXIDQnITs="; } .${platform}; urlName = builtins.replaceStrings [ "+" ] [ "%2B" ] name; @@ -153,11 +178,49 @@ stdenv.mkDerivation rec { url = "https://cef-builds.spotifycdn.com/${urlName}.tar.bz2"; inherit name hash; }; - # Find the hash in tools/buildtools/linux64/clang-format.sha1 - clang-fmt = fetchurl { - url = "https://storage.googleapis.com/chromium-clang-format/dd736afb28430c9782750fc0fd5f0ed497399263"; - hash = "sha256-4H6FVO9jdZtxH40CSfS+4VESAHgYgYxfCBFSMHdT0hE="; - }; + # Find the hash in tools/buildtools/${platform}/clang-format.sha1 + clang-fmt = + let + platformInfo = + { + "linuxarm64" = { + key = "dd736afb28430c9782750fc0fd5f0ed497399263"; + hash = "sha256-4H6FVO9jdZtxH40CSfS+4VESAHgYgYxfCBFSMHdT0hE="; + }; + "linux64" = { + key = "dd736afb28430c9782750fc0fd5f0ed497399263"; + hash = "sha256-4H6FVO9jdZtxH40CSfS+4VESAHgYgYxfCBFSMHdT0hE="; + }; + "macosx64" = { + key = "a1b33be85faf2578f3101d7806e443e1c0949498"; + hash = "sha256-RscqWe309rwQe1vEoefAP+fHxx5KAtvQA0Zh3lj62pc="; + }; + "macosarm64" = { + key = "f1424c44ee758922823d6b37de43705955c99d7e"; + hash = "sha256-m+qCYEZUmCgU37JTlEVdyYml4T/rA3Lt/vJh7/ToSlo="; + }; + } + .${platform}; + in + fetchurl { + url = "https://storage.googleapis.com/chromium-clang-format/${platformInfo.key}"; + hash = platformInfo.hash; + }; + clangFmtFolder = if stdenv.isDarwin then "mac" else "linux64"; + + os = if stdenv.isDarwin then "macosx" else "linux"; + + toolFolder = if stdenv.isDarwin then "mac" else "linux"; + + patchLibs = + if stdenv.isDarwin then + '''' + else + '' + patchelf third_party/cef/${cef-bin.name}/${buildType}/libcef.so --set-rpath "${rpath}" --add-needed libudev.so + patchelf third_party/cef/${cef-bin.name}/${buildType}/libGLESv2.so --set-rpath "${rpath}" --add-needed libGL.so.1 + patchelf third_party/cef/${cef-bin.name}/${buildType}/chrome-sandbox --set-interpreter $(cat $NIX_BINTOOLS/nix-support/dynamic-linker) + ''; configurePhase = '' runHook preConfigure @@ -166,10 +229,7 @@ stdenv.mkDerivation rec { cp -r ${cef-bin} third_party/cef/${cef-bin.name} chmod +w -R third_party/cef/${cef-bin.name} - patchelf third_party/cef/${cef-bin.name}/${buildType}/libcef.so --set-rpath "${rpath}" --add-needed libudev.so - patchelf third_party/cef/${cef-bin.name}/${buildType}/libGLESv2.so --set-rpath "${rpath}" --add-needed libGL.so.1 - patchelf third_party/cef/${cef-bin.name}/${buildType}/chrome-sandbox --set-interpreter $(cat $NIX_BINTOOLS/nix-support/dynamic-linker) - sed 's/-O0/-O2/' -i third_party/cef/${cef-bin.name}/cmake/cef_variables.cmake + ${patchLibs} sed \ -e 's|os.path.isdir(os.path.join(path, \x27.git\x27))|True|' \ @@ -178,8 +238,8 @@ stdenv.mkDerivation rec { -e 's|"%s rev-list --count %s" % (git_exe, branch)|"echo '${version}'"|' \ -i tools/git_util.py - cp ${clang-fmt} tools/buildtools/linux64/clang-format - chmod +w tools/buildtools/linux64/clang-format + cp ${clang-fmt} tools/buildtools/${clangFmtFolder}/clang-format + chmod +w tools/buildtools/${clangFmtFolder}/clang-format sed \ -e 's|include(cmake/vcpkg.cmake)||' \ @@ -189,6 +249,10 @@ stdenv.mkDerivation rec { sed -e 's|vcpkg_bring_host_thrift()|set(THRIFT_COMPILER_HOST ${thrift}/bin/thrift)|' -i remote/CMakeLists.txt + # Remove runtime for appbundler because it only recognizes MacOS style Java home paths + # https://github.com/ome/appbundler/blob/6f153a3706960e3568a6815c27f5cd02cb36f654/appbundler/src/com/oracle/appbundler/AppBundlerTask.java#L629 + sed -e 's|||' -i build.xml + mkdir jcef_build cd jcef_build @@ -219,10 +283,10 @@ stdenv.mkDerivation rec { export THRIFT_JAR=libthrift-0.19.0.jar export OUT_NATIVE_DIR=$JCEF_ROOT_DIR/jcef_build/native/${buildType} export JB_TOOLS_DIR=$(realpath ../jb/tools) - export JB_TOOLS_OS_DIR=$JB_TOOLS_DIR/linux + export JB_TOOLS_OS_DIR=$JB_TOOLS_DIR/${toolFolder} export OUT_CLS_DIR=$(realpath ../out/${platform}) export TARGET_ARCH=${targetArch} DEPS_ARCH=${depsArch} - export OS=linux + export OS=${os} export JOGAMP_DIR="$JCEF_ROOT_DIR"/third_party/jogamp/jar mkdir -p $unpacked/{jogl,gluegen,jcef}