libcef: refactor (#397452)

This commit is contained in:
Pol Dellaiera
2025-04-28 05:47:35 +00:00
committed by GitHub
6 changed files with 172 additions and 282 deletions
+16 -41
View File
@@ -6,7 +6,6 @@
ninja,
nv-codec-headers-12,
fetchFromGitHub,
fetchpatch,
addDriverRunpath,
autoAddDriverRunpath,
cudaSupport ? config.cudaSupport,
@@ -40,7 +39,7 @@
pulseaudioSupport ? config.pulseaudio or stdenv.hostPlatform.isLinux,
libpulseaudio,
browserSupport ? true,
libcef,
cef-binary,
pciutils,
pipewireSupport ? stdenv.hostPlatform.isLinux,
withFdk ? true,
@@ -66,6 +65,18 @@
let
inherit (lib) optional optionals;
cef = cef-binary.overrideAttrs (oldAttrs: {
version = "127.3.5";
gitRevision = "114ea2a";
chromiumVersion = "127.0.6533.120";
srcHash =
{
aarch64-linux = "sha256-s8dR97rAO0mCUwbpYnPWyY3t8movq05HhZZKllhZdBs=";
x86_64-linux = "sha256-57E7bZKpViWno9W4AaaSjL9B4uxq+rDXAou1tsiODUg=";
}
.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
});
in
stdenv.mkDerivation (finalAttrs: {
pname = "obs-studio";
@@ -85,33 +96,6 @@ stdenv.mkDerivation (finalAttrs: {
# Lets obs-browser build against CEF 90.1.0+
./Enable-file-access-and-universal-access-for-file-URL.patch
./fix-nix-plugin-path.patch
# TODO: remove when CHROME_VERSION_BUILD(libcef) >= 6367
(fetchpatch {
name = "Check-source-validity-before-attempting-to-log-rende.patch";
url = "https://github.com/obsproject/obs-browser/pull/478.patch";
revert = true;
stripLen = 1;
extraPrefix = "plugins/obs-browser/";
hash = "sha256-mQVhK4r8LlK2F9/jlDHA1V6M29mAfxWAU/VsMXYNrhU=";
})
# TODO: remove when CHROME_VERSION_BUILD(libcef) >= 6367
(fetchpatch {
name = "Print-browser-source-renderer-crashes-to-OBS-log.patch";
url = "https://github.com/obsproject/obs-browser/pull/475.patch";
revert = true;
stripLen = 1;
extraPrefix = "plugins/obs-browser/";
hash = "sha256-ha77OYpWn57JovPNE+izyDOB/2KlF3qWVv/PGEgyu84=";
})
# TODO: remove when CHROME_VERSION_BUILD(libcef) >= 6367
(fetchpatch {
name = "Log-error-if-CefInitialize-fails.patch.patch";
url = "https://github.com/obsproject/obs-browser/pull/477.patch";
revert = true;
stripLen = 1;
extraPrefix = "plugins/obs-browser/";
hash = "sha256-MMLFQtpWjfpti/38qEcOuXr1L3s1MPRHjuaZCjNmvt0=";
})
];
nativeBuildInputs =
@@ -168,20 +152,12 @@ stdenv.mkDerivation (finalAttrs: {
pipewire
libdrm
]
++ optional browserSupport libcef
++ optional browserSupport cef
++ optional withFdk fdk_aac;
# Copied from the obs-linuxbrowser
postUnpack = lib.optionalString browserSupport ''
mkdir -p cef/Release cef/Resources cef/libcef_dll_wrapper/
for i in ${libcef}/share/cef/*; do
ln -s $i cef/Release/
ln -s $i cef/Resources/
done
ln -s ${libcef}/lib/*.so* cef/Release/
ln -s ${libcef}/libexec/cef/chrome-sandbox cef/Release/
ln -s ${libcef}/lib/libcef_dll_wrapper.a cef/libcef_dll_wrapper/
ln -s ${libcef}/include cef/
ln -s ${cef} cef
'';
postPatch = ''
@@ -243,8 +219,7 @@ stdenv.mkDerivation (finalAttrs: {
(lib.optionalString browserSupport ''
# Link cef components again after patchelfing other libs
ln -s ${libcef}/lib/* $out/lib/obs-plugins/
ln -s ${libcef}/libexec/cef/* $out/lib/obs-plugins/
ln -sf ${cef}/${cef.buildType}/* $out/lib/obs-plugins/
'')
];
+14 -75
View File
@@ -7,81 +7,31 @@
ninja,
libarchive,
libz,
libcef,
cef-binary,
luajit,
xorg,
libgbm,
glib,
nss,
nspr,
atk,
at-spi2-atk,
libdrm,
expat,
libxkbcommon,
gtk3,
jdk17,
pango,
cairo,
alsa-lib,
dbus,
at-spi2-core,
cups,
systemd,
buildFHSEnv,
makeDesktopItem,
copyDesktopItems,
enableRS3 ? false,
}:
let
cef = libcef.overrideAttrs (oldAttrs: {
installPhase =
let
gl_rpath = lib.makeLibraryPath [
stdenv.cc.cc.lib
];
rpath = lib.makeLibraryPath [
glib
nss
nspr
atk
at-spi2-atk
libdrm
expat
xorg.libxcb
libxkbcommon
xorg.libX11
xorg.libXcomposite
xorg.libXdamage
xorg.libXext
xorg.libXfixes
xorg.libXrandr
libgbm
gtk3
pango
cairo
alsa-lib
dbus
at-spi2-core
cups
xorg.libxshmfence
systemd
];
in
''
mkdir -p $out/lib/ $out/share/cef/
cp libcef_dll_wrapper/libcef_dll_wrapper.a $out/lib/
cp -r ../Resources/* $out/lib/
cp -r ../Release/* $out/lib/
patchelf --set-rpath "${rpath}" $out/lib/libcef.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libEGL.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libGLESv2.so
cp ../Release/*.bin $out/share/cef/
cp -r ../Resources/* $out/share/cef/
cp -r ../include $out
cp -r ../libcef_dll $out
cp -r ../cmake $out
'';
cef = cef-binary.overrideAttrs (oldAttrs: {
version = "126.2.18";
gitRevision = "3647d39";
chromiumVersion = "126.0.6478.183";
srcHash =
{
aarch64-linux = "sha256-Ni5aEbI+WuMnbT8gPWMONN5NkTySw7xJvnM6U44Njao=";
x86_64-linux = "sha256-YwND4zsndvmygJxwmrCvaFuxjJO704b6aDVSJqpEOKc=";
}
.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
});
in
let
@@ -122,19 +72,8 @@ let
];
preConfigure = ''
mkdir -p cef/dist/Release cef/dist/Resources cef/dist/include
ln -s ${cef}/lib/* cef/dist/Release
ln -s ${cef}/share/cef/*.pak cef/dist/Resources
ln -s ${cef}/share/cef/icudtl.dat cef/dist/Resources
ln -s ${cef}/share/cef/locales cef/dist/Resources
ln -s ${cef}/include/* cef/dist/include
ln -s ${cef}/libcef_dll cef/dist/libcef_dll
ln -s ${cef}/cmake cef/dist/cmake
ln -s ${cef}/CMakeLists.txt cef/dist
mkdir -p cef
ln -s ${cef} cef/dist
'';
postFixup = ''
+15
View File
@@ -0,0 +1,15 @@
{
libcef,
}:
libcef.overrideAttrs (oldAttrs: {
pname = "cef-binary";
installPhase = ''
runHook preInstall
cp -r .. $out
runHook postInstall
'';
})
+16 -105
View File
@@ -8,12 +8,9 @@
glew,
glfw,
glm,
libGL,
libpulseaudio,
libX11,
libXau,
libXdmcp,
libXext,
libXpm,
libXrandr,
libXxf86vm,
@@ -23,115 +20,29 @@
SDL2,
SDL2_mixer,
zlib,
fetchzip,
wayland,
wayland-protocols,
egl-wayland,
libffi,
wayland-scanner,
glib,
nss,
nspr,
atk,
at-spi2-atk,
libdrm,
expat,
libxcb,
libxkbcommon,
libXcomposite,
libXdamage,
libXfixes,
libgbm,
gtk3,
pango,
cairo,
alsa-lib,
dbus,
at-spi2-core,
cups,
libxshmfence,
udev,
systemd,
cef-binary,
libdecor,
autoPatchelfHook,
}:
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
systemd
];
buildType = "Release";
selectSystem =
attrs:
attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
arch = selectSystem {
aarch64-linux = "arm64";
x86_64-linux = "x64";
};
cef-bin-name = "cef_binary_120.1.10+g3ce3184+chromium-120.0.6099.129_linux${arch}";
cef-bin = stdenv.mkDerivation {
pname = "cef-bin";
version = "120.0.6099.129";
cef = cef-binary.overrideAttrs (oldAttrs: {
version = "120.1.10";
gitRevision = "3ce3184";
chromiumVersion = "120.0.6099.129";
src = fetchzip {
url = "https://cef-builds.spotifycdn.com/${
builtins.replaceStrings [ "+" ] [ "%2B" ] cef-bin-name
}.tar.bz2";
hash = selectSystem {
aarch64-linux = "sha256-2mOh3GWdx0qxsLRKVYXOJnVY0eqz6B3z9/B9A9Xfs/A=";
x86_64-linux = "sha256-FFkFMMkTSseLZIDzESFl8+h7wRhv5QGi1Uy5MViYpX8=";
};
};
installPhase = ''
runHook preInstall
cp --recursive --no-preserve=mode . $out
patchelf $out/${buildType}/libcef.so --set-rpath "${rpath}" --add-needed libudev.so
patchelf $out/${buildType}/libGLESv2.so --set-rpath "${rpath}" --add-needed libGL.so.1
patchelf $out/${buildType}/chrome-sandbox --set-interpreter $(cat $NIX_BINTOOLS/nix-support/dynamic-linker)
sed 's/-O0/-O2/' -i $out/cmake/cef_variables.cmake
runHook postInstall
'';
meta = {
description = "Simple framework for embedding Chromium-based browsers in other applications";
homepage = "https://cef-builds.spotifycdn.com/index.html";
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
license = lib.licenses.bsd3;
platforms = [
"x86_64-linux"
"aarch64-linux"
];
hydraPlatforms = [ "x86_64-linux" ]; # Hydra "aarch64-linux" fails with "Output limit exceeded"
};
};
srcHash =
{
aarch64-linux = "sha256-l0PSW4ZeLhfEauf1bez1GoLfu9cwXZzEocDlGI9yFsQ=";
x86_64-linux = "sha256-OdIVEy77tiYRfDWXgyceSstFqCNeZHswzkpw06LSnP0=";
}
.${stdenv.hostPlatform.system} or (throw "unsupported system ${stdenv.hostPlatform.system}");
});
in
stdenv.mkDerivation rec {
pname = "linux-wallpaperengine";
@@ -176,13 +87,13 @@ stdenv.mkDerivation rec {
];
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=${buildType}"
"-DCEF_ROOT=${cef-bin}"
"-DCMAKE_BUILD_TYPE=${cef.buildType}"
"-DCEF_ROOT=${cef}"
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}/app/linux-wallpaperengine"
];
preFixup = ''
patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:${cef-bin}" $out/app/linux-wallpaperengine/linux-wallpaperengine
patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:${cef}" $out/app/linux-wallpaperengine/linux-wallpaperengine
chmod 755 $out/app/linux-wallpaperengine/linux-wallpaperengine
mkdir $out/bin
ln -s $out/app/linux-wallpaperengine/linux-wallpaperengine $out/bin/linux-wallpaperengine
+77 -45
View File
@@ -27,13 +27,15 @@
at-spi2-core,
cups,
libxshmfence,
libGL,
udev,
systemd,
obs-studio,
xorg,
}:
let
gl_rpath = lib.makeLibraryPath [
stdenv.cc.cc
];
gl_rpath = lib.makeLibraryPath [ stdenv.cc.cc ];
rpath = lib.makeLibraryPath [
glib
@@ -60,77 +62,107 @@ let
at-spi2-core
cups
libxshmfence
libGL
udev
systemd
xorg.libxcb
xorg.libX11
xorg.libXcomposite
xorg.libXdamage
xorg.libXext
xorg.libXfixes
xorg.libXrandr
xorg.libxshmfence
];
platforms = {
"aarch64-linux" = {
selectSystem =
attrs:
attrs.${stdenv.hostPlatform.system} or (throw "Unsupported system ${stdenv.hostPlatform.system}");
platformInfo = selectSystem {
aarch64-linux = {
platformStr = "linuxarm64";
projectArch = "arm64";
};
"x86_64-linux" = {
x86_64-linux = {
platformStr = "linux64";
projectArch = "x86_64";
};
};
platforms."aarch64-linux".sha256 = "16sbfk599h96wcsmpbxlwsvq0n1pssmm8dpwmjsqfrn1464dvs68";
platforms."x86_64-linux".sha256 = "1wa4nv28saz96kar9svdarfz6c4rnbcqz0rqxzl9zclnhfzhqdiw";
platformInfo =
platforms.${stdenv.hostPlatform.system}
or (throw "unsupported system ${stdenv.hostPlatform.system}");
in
stdenv.mkDerivation rec {
pname = "cef-binary";
version = "121.3.13";
gitRevision = "5c4a81b";
chromiumVersion = "121.0.6167.184";
stdenv.mkDerivation (finalAttrs: {
pname = "libcef";
version = "135.0.21";
gitRevision = "d008a99";
chromiumVersion = "135.0.7049.96";
buildType = "Release";
srcHash = selectSystem {
aarch64-linux = "sha256-+rQKfNTlRGdkDuxn72vTwZ/13UNDbqF6I5bzHjMuCsE=";
x86_64-linux = "sha256-bnyZfgw6h/mkOfnwCUBKbZrwlKVcQ/i3lYoHp2Rw6To=";
};
src = fetchurl {
url = "https://cef-builds.spotifycdn.com/cef_binary_${version}+g${gitRevision}+chromium-${chromiumVersion}_${platformInfo.platformStr}_minimal.tar.bz2";
inherit (platformInfo) sha256;
url = "https://cef-builds.spotifycdn.com/cef_binary_${finalAttrs.version}+g${finalAttrs.gitRevision}+chromium-${finalAttrs.chromiumVersion}_${platformInfo.platformStr}_minimal.tar.bz2";
hash = finalAttrs.srcHash;
};
nativeBuildInputs = [ cmake ];
cmakeFlags = [ "-DPROJECT_ARCH=${platformInfo.projectArch}" ];
makeFlags = [ "libcef_dll_wrapper" ];
dontStrip = true;
dontPatchELF = true;
installPhase = ''
mkdir -p $out/lib/ $out/share/cef/ $out/libexec/cef/
cp libcef_dll_wrapper/libcef_dll_wrapper.a $out/lib/
cp ../Release/libcef.so $out/lib/
cp ../Release/libEGL.so $out/lib/
cp ../Release/libGLESv2.so $out/lib/
cp ../Release/libvk_swiftshader.so $out/lib/
cp ../Release/libvulkan.so.1 $out/lib/
cp ../Release/chrome-sandbox $out/libexec/cef/
patchelf --set-rpath "${rpath}" $out/lib/libcef.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libEGL.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libGLESv2.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libvk_swiftshader.so
patchelf --set-rpath "${gl_rpath}" $out/lib/libvulkan.so.1
cp ../Release/*.bin ../Release/*.json $out/share/cef/
cp -r ../Resources/* $out/share/cef/
cp -r ../include $out/
preInstall = ''
patchelf --set-rpath "${rpath}" --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" ../${finalAttrs.buildType}/chrome-sandbox
patchelf --add-needed libudev.so --set-rpath "${rpath}" ../${finalAttrs.buildType}/libcef.so
patchelf --set-rpath "${gl_rpath}" ../${finalAttrs.buildType}/libEGL.so
patchelf --add-needed libGL.so.1 --set-rpath "${gl_rpath}" ../${finalAttrs.buildType}/libGLESv2.so
patchelf --set-rpath "${gl_rpath}" ../${finalAttrs.buildType}/libvk_swiftshader.so
patchelf --set-rpath "${gl_rpath}" ../${finalAttrs.buildType}/libvulkan.so.1
'';
passthru.tests = {
inherit obs-studio; # frequently breaks on CEF updates
};
passthru.updateScript = ./update.sh;
installPhase = ''
runHook preInstall
meta = with lib; {
mkdir -p $out/lib/ $out/share/cef/ $out/libexec/cef/
cp libcef_dll_wrapper/libcef_dll_wrapper.a $out/lib/
cp ../${finalAttrs.buildType}/libcef.so $out/lib/
cp ../${finalAttrs.buildType}/libEGL.so $out/lib/
cp ../${finalAttrs.buildType}/libGLESv2.so $out/lib/
cp ../${finalAttrs.buildType}/libvk_swiftshader.so $out/lib/
cp ../${finalAttrs.buildType}/libvulkan.so.1 $out/lib/
cp ../${finalAttrs.buildType}/chrome-sandbox $out/libexec/cef/
cp ../${finalAttrs.buildType}/*.bin ../${finalAttrs.buildType}/*.json $out/share/cef/
cp -r ../Resources/* $out/share/cef/
cp -r ../include $out/
runHook postInstall
'';
passthru = {
updateScript = ./update.sh;
tests = {
inherit obs-studio; # frequently breaks on CEF updates
};
};
meta = {
description = "Simple framework for embedding Chromium-based browsers in other applications";
homepage = "https://cef-builds.spotifycdn.com/index.html";
maintainers = with maintainers; [ puffnfresh ];
sourceProvenance = with sourceTypes; [
maintainers = with lib.maintainers; [ puffnfresh ];
sourceProvenance = with lib.sourceTypes; [
fromSource
binaryNativeCode
];
license = licenses.bsd3;
license = lib.licenses.bsd3;
platforms = [
"x86_64-linux"
"aarch64-linux"
];
};
}
})
+34 -16
View File
@@ -1,25 +1,43 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused jq
#!nix-shell -i bash -p curl gnused jq common-updater-scripts
set -x -eu -o pipefail
set -euo pipefail
cd $(dirname "${BASH_SOURCE[0]}")
current_version=$(nix-instantiate --eval -E "with import ./. {}; libcef.version or (lib.getVersion libcef)" | tr -d '"')
VERSION_JSON=$(curl --silent https://cef-builds.spotifycdn.com/index.json | jq '[.linux64.versions[] | select (.channel == "stable")][0]')
ROOT="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
CEF_VERSION=$(echo ${VERSION_JSON} | jq -r '.cef_version' | cut -d'+' -f1)
GIT_REVISION=$(echo ${VERSION_JSON} | jq -r '.cef_version' | cut -d'+' -f2 | cut -c 2-)
CHROMIUM_VERSION=$(echo ${VERSION_JSON} | jq -r '.chromium_version')
version_json=$(curl --silent https://cef-builds.spotifycdn.com/index.json | jq '[.linux64.versions[] | select (.channel == "stable")][0]')
cef_version=$(echo "$version_json" | jq -r '.cef_version' | cut -d'+' -f1)
git_revision=$(echo "$version_json" | jq -r '.cef_version' | cut -d'+' -f2 | cut -c 2-)
chromium_version=$(echo "$version_json" | jq -r '.chromium_version')
SHA256_LINUX64=$(nix-prefetch-url --quiet https://cef-builds.spotifycdn.com/cef_binary_${CEF_VERSION}+g${GIT_REVISION}+chromium-${CHROMIUM_VERSION}_linux64_minimal.tar.bz2)
SHA256_LINUXARM64=$(nix-prefetch-url --quiet https://cef-builds.spotifycdn.com/cef_binary_${CEF_VERSION}+g${GIT_REVISION}+chromium-${CHROMIUM_VERSION}_linuxarm64_minimal.tar.bz2)
echo "Latest version: $cef_version"
echo "Current version: $current_version"
setKV () {
sed -i "s|$1 = \".*\"|$1 = \"${2:-}\"|" ./default.nix
if [[ "$cef_version" == "$current_version" ]]; then
echo "Package is up-to-date"
exit 0
fi
update_nix_value() {
local key="$1"
local value="${2:-}"
sed -i "s|$key = \".*\"|$key = \"$value\"|" $ROOT/default.nix
}
setKV version ${CEF_VERSION}
setKV gitRevision ${GIT_REVISION}
setKV chromiumVersion ${CHROMIUM_VERSION}
setKV 'platforms."aarch64-linux".sha256' ${SHA256_LINUXARM64}
setKV 'platforms."x86_64-linux".sha256' ${SHA256_LINUX64}
update_nix_value version "$cef_version"
update_nix_value gitRevision "$git_revision"
update_nix_value chromiumVersion "$chromium_version"
declare -a platforms=(
"x86_64-linux 64"
"aarch64-linux arm64"
)
for platform in "${platforms[@]}"; do
read -r system arch <<< "$platform"
url="https://cef-builds.spotifycdn.com/cef_binary_${cef_version}+g${git_revision}+chromium-${chromium_version}_linux${arch}_minimal.tar.bz2"
hash=$(nix hash convert --to sri --hash-algo sha256 "$(nix-prefetch-url --quiet "$url")")
update-source-version libcef "$cef_version" "$hash" --system="$system" --ignore-same-version
done