zed-editor: shrink darwin closure (#369399)

This commit is contained in:
Gaétan Lepage 2024-12-31 09:22:29 +01:00 committed by GitHub
commit 8da05cf315
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 29 deletions

View File

@ -147,6 +147,11 @@ stdenv.mkDerivation {
substituteInPlace build/toolchain/apple/toolchain.gni --replace-fail "/bin/cp -Rc" "cp -a" substituteInPlace build/toolchain/apple/toolchain.gni --replace-fail "/bin/cp -Rc" "cp -a"
''; '';
outputs = [
"dev"
"out"
];
nativeBuildInputs = nativeBuildInputs =
(builtins.concatLists ( (builtins.concatLists (
lib.mapAttrsToList ( lib.mapAttrsToList (
@ -249,24 +254,24 @@ stdenv.mkDerivation {
'' ''
runHook preInstall runHook preInstall
mkdir -p $out/{lib,include} mkdir -p $out/lib
cp obj/webrtc.ninja $out/ mkdir -p $dev/include
cp args.gn $out/
cp LICENSE.md $out/ install -m0644 obj/webrtc.ninja args.gn LICENSE.md $dev
pushd ../..
find . -name "*.h" -print | cpio -pd $dev/include
popd
'' ''
+ lib.optionalString stdenv.hostPlatform.isLinux '' + lib.optionalString stdenv.hostPlatform.isLinux ''
cp libwebrtc.so $out/lib/ install -m0644 libwebrtc.so libthird_party_boringssl.so $out/lib
cp libthird_party_boringssl.so $out/lib/
'' ''
+ lib.optionalString stdenv.hostPlatform.isDarwin '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Library/Frameworks install -m0644 WebRTC.framework/Versions/A/WebRTC $out/lib/libwebrtc.dylib
cp -r WebRTC.framework $out/Library/Frameworks install -m0644 libthird_party_boringssl.dylib $out/lib
cp libwebrtc.dylib $out/lib
cp libthird_party_boringssl.dylib $out/lib/
'' ''
+ '' + ''
cd ../.. ln -s $out/lib $dev/lib
find . -name "*.h" -print | cpio -pd $out/include
runHook postInstall runHook postInstall
''; '';
@ -274,13 +279,10 @@ stdenv.mkDerivation {
postFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
boringssl="$out/lib/libthird_party_boringssl.dylib" boringssl="$out/lib/libthird_party_boringssl.dylib"
webrtc="$out/lib/libwebrtc.dylib" webrtc="$out/lib/libwebrtc.dylib"
framework="$out/Library/Frameworks/WebRTC.framework/Versions/A/WebRTC"
install_name_tool -id "$boringssl" "$boringssl" install_name_tool -id "$boringssl" "$boringssl"
install_name_tool -id "$webrtc" "$webrtc" install_name_tool -id "$webrtc" "$webrtc"
install_name_tool -change @rpath/libthird_party_boringssl.dylib "$boringssl" "$webrtc" install_name_tool -change @rpath/libthird_party_boringssl.dylib "$boringssl" "$webrtc"
install_name_tool -id "$framework" "$framework"
install_name_tool -change @rpath/libthird_party_boringssl.dylib "$boringssl" "$framework"
''; '';
passthru.updateScript = writeShellScript "update-livekit-libwebrtc" '' passthru.updateScript = writeShellScript "update-livekit-libwebrtc" ''

View File

@ -112,20 +112,11 @@ rustPlatform.buildRustPackage rec {
"script/patches/use-cross-platform-livekit.patch" "script/patches/use-cross-platform-livekit.patch"
]; ];
postPatch = # Dynamically link WebRTC instead of static
lib.optionalString stdenv.hostPlatform.isLinux '' postPatch = ''
# Dynamically link WebRTC instead of static substituteInPlace ../${pname}-${version}-vendor/webrtc-sys-*/build.rs \
substituteInPlace ../${pname}-${version}-vendor/webrtc-sys-*/build.rs \ --replace-fail "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc"
--replace-fail "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc" '';
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
# On Darwin, linking against the dylib results in Rust linker errors, while
# linking against the framework works fine.
substituteInPlace ../${pname}-${version}-vendor/webrtc-sys-*/build.rs \
--replace-fail "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=framework=webrtc" \
--replace-fail 'println!("cargo:rustc-link-search=native={}", webrtc_lib.to_str().unwrap());' \
'println!("cargo:rustc-link-search=framework={}/Library/Frameworks", webrtc_dir.to_str().unwrap());'
'';
useFetchCargoVendor = true; useFetchCargoVendor = true;
cargoHash = "sha256-J5vJ/KV94a+9AqGbNZx6sCzWflOZsyUj3NcqnfaexGE="; cargoHash = "sha256-J5vJ/KV94a+9AqGbNZx6sCzWflOZsyUj3NcqnfaexGE=";
@ -297,6 +288,16 @@ rustPlatform.buildRustPackage rec {
versionCheckProgramArg = [ "--version" ]; versionCheckProgramArg = [ "--version" ];
doInstallCheck = true; doInstallCheck = true;
# The darwin Applications directory is not stripped by default, see
# https://github.com/NixOS/nixpkgs/issues/367169
# This setting is not platform-guarded as it doesn't do any harm on Linux,
# where this directory simply does not exist.
stripDebugList = [
"bin"
"libexec"
"Applications"
];
passthru = { passthru = {
updateScript = gitUpdater { updateScript = gitUpdater {
rev-prefix = "v"; rev-prefix = "v";