zed-editor: fix darwin (#329653)

This commit is contained in:
Adam C. Stephens 2024-10-20 21:00:55 -04:00 committed by GitHub
commit 67d8538ef6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 159 additions and 58 deletions

View File

@ -0,0 +1,55 @@
diff --git a/crates/live_kit_client/Cargo.toml b/crates/live_kit_client/Cargo.toml
index e23c63453e..d0142b83d8 100644
--- a/crates/live_kit_client/Cargo.toml
+++ b/crates/live_kit_client/Cargo.toml
@@ -40,10 +40,10 @@ nanoid = { workspace = true, optional = true}
parking_lot.workspace = true
postage.workspace = true
-[target.'cfg(target_os = "macos")'.dependencies]
+[target.'cfg(target_os = "none")'.dependencies]
core-foundation.workspace = true
-[target.'cfg(all(not(target_os = "macos")))'.dependencies]
+[target.'cfg(all(not(target_os = "none")))'.dependencies]
async-trait = { workspace = true }
collections = { workspace = true }
gpui = { workspace = true }
diff --git a/crates/live_kit_client/build.rs b/crates/live_kit_client/build.rs
index 2fdfd982bf..7272614b87 100644
--- a/crates/live_kit_client/build.rs
+++ b/crates/live_kit_client/build.rs
@@ -36,7 +36,7 @@ const MACOS_TARGET_VERSION: &str = "10.15.7";
fn main() {
if cfg!(all(
- target_os = "macos",
+ target_os = "none",
not(any(test, feature = "test-support", feature = "no-webrtc")),
)) {
let swift_target = get_swift_target();
diff --git a/crates/live_kit_client/src/live_kit_client.rs b/crates/live_kit_client/src/live_kit_client.rs
index 4820a4eedb..6179e6c55a 100644
--- a/crates/live_kit_client/src/live_kit_client.rs
+++ b/crates/live_kit_client/src/live_kit_client.rs
@@ -2,16 +2,16 @@
use std::sync::Arc;
-#[cfg(all(target_os = "macos", not(any(test, feature = "test-support"))))]
+#[cfg(all(target_os = "none", not(any(test, feature = "test-support"))))]
pub mod prod;
-#[cfg(all(target_os = "macos", not(any(test, feature = "test-support"))))]
+#[cfg(all(target_os = "none", not(any(test, feature = "test-support"))))]
pub use prod::*;
-#[cfg(any(test, feature = "test-support", not(target_os = "macos")))]
+#[cfg(any(test, feature = "test-support", not(target_os = "none")))]
pub mod test;
-#[cfg(any(test, feature = "test-support", not(target_os = "macos")))]
+#[cfg(any(test, feature = "test-support", not(target_os = "none")))]
pub use test::*;
pub type Sid = String;

View File

@ -9,7 +9,6 @@
perl, perl,
pkg-config, pkg-config,
protobuf, protobuf,
xcbuild,
fontconfig, fontconfig,
freetype, freetype,
libgit2, libgit2,
@ -23,7 +22,6 @@
libglvnd, libglvnd,
xorg, xorg,
stdenv, stdenv,
darwin,
makeFontsConf, makeFontsConf,
vulkan-loader, vulkan-loader,
envsubst, envsubst,
@ -32,6 +30,10 @@
versionCheckHook, versionCheckHook,
zed-editor, zed-editor,
buildFHSEnv, buildFHSEnv,
cargo-bundle,
git,
apple-sdk_15,
darwinMinVersionHook,
withGLES ? false, withGLES ? false,
}: }:
@ -93,14 +95,23 @@ rustPlatform.buildRustPackage rec {
repo = "zed"; repo = "zed";
rev = "refs/tags/v${version}"; rev = "refs/tags/v${version}";
hash = "sha256-xtSdlzj1AxhJN4aXLJ+Oy51LX4QduLwcuCfK42kthvE="; hash = "sha256-xtSdlzj1AxhJN4aXLJ+Oy51LX4QduLwcuCfK42kthvE=";
fetchSubmodules = true;
}; };
patches = [ patches =
# Zed uses cargo-install to install cargo-about during the script execution. [
# We provide cargo-about ourselves and can skip this step. # Zed uses cargo-install to install cargo-about during the script execution.
./0001-generate-licenses.patch # We provide cargo-about ourselves and can skip this step.
]; ./0001-generate-licenses.patch
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# The Swift variant of livekit currently used inside Zed requires
# Swift 6, which is not available in nixpkgs yet:
# https://github.com/NixOS/nixpkgs/issues/343210
# The Rust variant of livekit for Zed is still pending and there is no
# schedule when it will be finished:
# https://github.com/zed-industries/zed/pull/13343
./0002-disable-livekit-darwin.patch
];
cargoLock = { cargoLock = {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
@ -132,7 +143,7 @@ rustPlatform.buildRustPackage rec {
protobuf protobuf
rustPlatform.bindgenHook rustPlatform.bindgenHook
cargo-about cargo-about
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcrun ]; ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
dontUseCmakeConfigure = true; dontUseCmakeConfigure = true;
@ -153,30 +164,23 @@ rustPlatform.buildRustPackage rec {
wayland wayland
xorg.libxcb xorg.libxcb
] ]
++ lib.optionals stdenv.hostPlatform.isDarwin ( ++ lib.optionals stdenv.hostPlatform.isDarwin [
with darwin.apple_sdk.frameworks; apple-sdk_15
[ # This will need to be increased to 12.3 once
AppKit # https://github.com/zed-industries/zed/pull/13343
CoreAudio # is merged and released, as ScreenCaptureKit is only available on 12.3 and up:
CoreFoundation # https://developer.apple.com/documentation/screencapturekit
CoreGraphics (darwinMinVersionHook "10.15")
CoreMedia ];
CoreServices
CoreText
Foundation
IOKit
Metal
Security
SystemConfiguration
VideoToolbox
]
);
cargoBuildFlags = [ cargoBuildFlags = [
"--package=zed" "--package=zed"
"--package=cli" "--package=cli"
]; ];
buildFeatures = [ "gpui/runtime_shaders" ];
# Required on darwin because we don't have access to the
# proprietary Metal shader compiler.
buildFeatures = lib.optionals stdenv.hostPlatform.isDarwin [ "gpui/runtime_shaders" ];
env = { env = {
ZSTD_SYS_USE_PKG_CONFIG = true; ZSTD_SYS_USE_PKG_CONFIG = true;
@ -188,9 +192,12 @@ rustPlatform.buildRustPackage rec {
}; };
# Setting this environment variable allows to disable auto-updates # Setting this environment variable allows to disable auto-updates
# https://zed.dev/docs/development/linux#notes-for-packaging-zed # https://zed.dev/docs/development/linux#notes-for-packaging-zed
ZED_UPDATE_EXPLANATION = "zed has been installed using nix. Auto-updates have thus been disabled."; ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
# Used by `zed --version` # Used by `zed --version`
RELEASE_VERSION = version; RELEASE_VERSION = version;
# Required until `-isysroot` can be used with libclang in nixpkgs on darwin, otherwise
# rust bindgen will not work as expected
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-F${apple-sdk_15.sdkroot}/System/Library/Frameworks";
}; };
RUSTFLAGS = if withGLES then "--cfg gles" else ""; RUSTFLAGS = if withGLES then "--cfg gles" else "";
@ -209,38 +216,79 @@ rustPlatform.buildRustPackage rec {
export HOME=$(mktemp -d); export HOME=$(mktemp -d);
''; '';
checkFlags = lib.optionals stdenv.hostPlatform.isLinux [ checkFlags =
# Fails on certain hosts (including Hydra) for unclear reason [
"--skip=test_open_paths_action" # Flaky: unreliably fails on certain hosts (including Hydra)
"--skip=zed::tests::test_window_edit_state_restoring_enabled"
]
++ lib.optionals stdenv.hostPlatform.isLinux [
# Fails on certain hosts (including Hydra) for unclear reason
"--skip=test_open_paths_action"
];
# Flaky: unreliably fails on certain hosts (including Hydra) installPhase =
"--skip=zed::tests::test_window_edit_state_restoring_enabled" if stdenv.hostPlatform.isDarwin then
]; ''
runHook preInstall
installPhase = '' # cargo-bundle expects the binary in target/release
runHook preInstall mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
mkdir -p $out/bin $out/libexec pushd crates/zed
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zeditor
install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png # Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
export CARGO_BUNDLE_SKIP_BUILD=true
app_path=$(cargo bundle --release | xargs)
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst) # We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions
# and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name) # Remove closing tags from Info.plist (last two lines)
( head -n -2 $app_path/Contents/Info.plist > Info.plist
export DO_STARTUP_NOTIFY="true" # Append extensions
export APP_CLI="zeditor" cat resources/info/*.plist >> Info.plist
export APP_ICON="zed" # Add closing tags
export APP_NAME="Zed" printf "</dict>\n</plist>\n" >> Info.plist
export APP_ARGS="%U" mv Info.plist $app_path/Contents/Info.plist
mkdir -p "$out/share/applications"
${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
)
runHook postInstall popd
'';
mkdir -p $out/Applications $out/bin
# Zed expects git next to its own binary
ln -s ${git}/bin/git $app_path/Contents/MacOS/git
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli
mv $app_path $out/Applications/
# Physical location of the CLI must be inside the app bundle as this is used
# to determine which app to start
ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor
runHook postInstall
''
else
''
runHook preInstall
mkdir -p $out/bin $out/libexec
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zeditor
install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
# and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
(
export DO_STARTUP_NOTIFY="true"
export APP_CLI="zeditor"
export APP_ICON="zed"
export APP_NAME="Zed"
export APP_ARGS="%U"
mkdir -p "$out/share/applications"
${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
)
runHook postInstall
'';
nativeInstallCheckInputs = [ nativeInstallCheckInputs = [
versionCheckHook versionCheckHook
@ -268,8 +316,6 @@ rustPlatform.buildRustPackage rec {
niklaskorz niklaskorz
]; ];
mainProgram = "zeditor"; mainProgram = "zeditor";
platforms = lib.platforms.all; platforms = lib.platforms.linux ++ lib.platforms.darwin;
# Currently broken on darwin: https://github.com/NixOS/nixpkgs/pull/303233#issuecomment-2048650618
broken = stdenv.hostPlatform.isDarwin;
}; };
} }