nix: Clean up build (#27881)

- bump our livekit version to include a fix for a crane bug (TODO: add
link when an issue is filed on crane)
- switch to a clang stdenv for both linux and macos
- manually unify versions of our notify crate
- remove old linker flags which were only needed for livekit
- fix an issue where RUSTFLAGS shadowed the rustflags from cargo configs

Release Notes:

- N/A
This commit is contained in:
Julia Ryan 2025-04-01 15:35:15 -07:00 committed by GitHub
parent a1b53e91e7
commit 4110928314
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 92 additions and 102 deletions

View File

@ -14,10 +14,10 @@ linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"] rustflags = ["-C", "link-arg=-fuse-ld=mold"]
[target.aarch64-apple-darwin] [target.aarch64-apple-darwin]
rustflags = ["-C", "link-args=-Objc -all_load"] rustflags = ["-C", "link-args=-all_load"]
[target.x86_64-apple-darwin] [target.x86_64-apple-darwin]
rustflags = ["-C", "link-args=-Objc -all_load"] rustflags = ["-C", "link-args=-all_load"]
[target.'cfg(target_os = "windows")'] [target.'cfg(target_os = "windows")']
rustflags = [ rustflags = [

View File

@ -184,9 +184,6 @@ jobs:
- os: arm Mac - os: arm Mac
runner: [macOS, ARM64, test] runner: [macOS, ARM64, test]
install_nix: false install_nix: false
- os: arm Linux
runner: buildjet-16vcpu-ubuntu-2204-arm
install_nix: true
if: github.repository_owner == 'zed-industries' if: github.repository_owner == 'zed-industries'
runs-on: ${{ matrix.system.runner }} runs-on: ${{ matrix.system.runner }}
needs: tests needs: tests

52
Cargo.lock generated
View File

@ -5309,7 +5309,7 @@ dependencies = [
"ignore", "ignore",
"libc", "libc",
"log", "log",
"notify 8.0.0 (git+https://github.com/zed-industries/notify.git?rev=bbb9ea5ae52b253e095737847e367c30653a2e96)", "notify",
"objc", "objc",
"parking_lot", "parking_lot",
"paths", "paths",
@ -7717,7 +7717,7 @@ dependencies = [
[[package]] [[package]]
name = "libwebrtc" name = "libwebrtc"
version = "0.3.10" version = "0.3.10"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"cxx", "cxx",
"jni", "jni",
@ -7802,7 +7802,7 @@ checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
[[package]] [[package]]
name = "livekit" name = "livekit"
version = "0.7.8" version = "0.7.8"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"chrono", "chrono",
"futures-util", "futures-util",
@ -7825,12 +7825,10 @@ dependencies = [
[[package]] [[package]]
name = "livekit-api" name = "livekit-api"
version = "0.4.2" version = "0.4.2"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"base64 0.21.7",
"futures-util", "futures-util",
"http 0.2.12", "http 0.2.12",
"jsonwebtoken",
"livekit-protocol", "livekit-protocol",
"livekit-runtime", "livekit-runtime",
"log", "log",
@ -7841,7 +7839,6 @@ dependencies = [
"reqwest 0.11.27", "reqwest 0.11.27",
"scopeguard", "scopeguard",
"serde", "serde",
"serde_json",
"sha2", "sha2",
"thiserror 1.0.69", "thiserror 1.0.69",
"tokio", "tokio",
@ -7852,7 +7849,7 @@ dependencies = [
[[package]] [[package]]
name = "livekit-protocol" name = "livekit-protocol"
version = "0.3.9" version = "0.3.9"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"livekit-runtime", "livekit-runtime",
@ -7869,7 +7866,7 @@ dependencies = [
[[package]] [[package]]
name = "livekit-runtime" name = "livekit-runtime"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"tokio", "tokio",
"tokio-stream", "tokio-stream",
@ -8239,7 +8236,7 @@ dependencies = [
"ignore", "ignore",
"log", "log",
"memchr", "memchr",
"notify 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "notify",
"notify-debouncer-mini", "notify-debouncer-mini",
"once_cell", "once_cell",
"opener", "opener",
@ -8666,25 +8663,6 @@ dependencies = [
"workspace", "workspace",
] ]
[[package]]
name = "notify"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943"
dependencies = [
"bitflags 2.9.0",
"filetime",
"fsevent-sys 4.1.0",
"inotify",
"kqueue",
"libc",
"log",
"mio",
"notify-types 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "notify" name = "notify"
version = "8.0.0" version = "8.0.0"
@ -8698,7 +8676,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"mio", "mio",
"notify-types 2.0.0 (git+https://github.com/zed-industries/notify.git?rev=bbb9ea5ae52b253e095737847e367c30653a2e96)", "notify-types",
"walkdir", "walkdir",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
@ -8710,17 +8688,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a689eb4262184d9a1727f9087cd03883ea716682ab03ed24efec57d7716dccb8" checksum = "a689eb4262184d9a1727f9087cd03883ea716682ab03ed24efec57d7716dccb8"
dependencies = [ dependencies = [
"log", "log",
"notify 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "notify",
"notify-types 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "notify-types",
"tempfile", "tempfile",
] ]
[[package]]
name = "notify-types"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
[[package]] [[package]]
name = "notify-types" name = "notify-types"
version = "2.0.0" version = "2.0.0"
@ -16191,7 +16163,7 @@ dependencies = [
[[package]] [[package]]
name = "webrtc-sys" name = "webrtc-sys"
version = "0.3.7" version = "0.3.7"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"cc", "cc",
"cxx", "cxx",
@ -16204,7 +16176,7 @@ dependencies = [
[[package]] [[package]]
name = "webrtc-sys-build" name = "webrtc-sys-build"
version = "0.3.6" version = "0.3.6"
source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8#102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8" source = "git+https://github.com/zed-industries/livekit-rust-sdks?rev=ffc215666621cd903a689d1c56cce0a706ffe022#ffc215666621cd903a689d1c56cce0a706ffe022"
dependencies = [ dependencies = [
"fs2", "fs2",
"regex", "regex",

View File

@ -657,6 +657,8 @@ features = [
[patch.crates-io] [patch.crates-io]
cpal = { git = "https://github.com/zed-industries/cpal", rev = "fd8bc2fd39f1f5fdee5a0690656caff9a26d9d50" } cpal = { git = "https://github.com/zed-industries/cpal", rev = "fd8bc2fd39f1f5fdee5a0690656caff9a26d9d50" }
real-async-tls = { git = "https://github.com/zed-industries/async-tls", rev = "1e759a4b5e370f87dc15e40756ac4f8815b61d9d", package = "async-tls" } real-async-tls = { git = "https://github.com/zed-industries/async-tls", rev = "1e759a4b5e370f87dc15e40756ac4f8815b61d9d", package = "async-tls" }
notify = { git = "https://github.com/zed-industries/notify.git", rev = "bbb9ea5ae52b253e095737847e367c30653a2e96" }
notify-types = { git = "https://github.com/zed-industries/notify.git", rev = "bbb9ea5ae52b253e095737847e367c30653a2e96" }
[profile.dev] [profile.dev]
split-debuginfo = "unpacked" split-debuginfo = "unpacked"

View File

@ -40,7 +40,7 @@ objc = "0.2"
cocoa = "0.26" cocoa = "0.26"
[target.'cfg(not(target_os = "macos"))'.dependencies] [target.'cfg(not(target_os = "macos"))'.dependencies]
notify = { git = "https://github.com/zed-industries/notify.git", rev = "bbb9ea5ae52b253e095737847e367c30653a2e96" } notify = "8.0.0"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
windows.workspace = true windows.workspace = true

View File

@ -1,2 +0,0 @@
[livekit_client_test]
rustflags = ["-C", "link-args=-ObjC"]

View File

@ -39,8 +39,8 @@ tokio-tungstenite.workspace = true
util.workspace = true util.workspace = true
[target.'cfg(not(all(target_os = "windows", target_env = "gnu")))'.dependencies] [target.'cfg(not(all(target_os = "windows", target_env = "gnu")))'.dependencies]
libwebrtc = { rev = "102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8", git = "https://github.com/zed-industries/livekit-rust-sdks" } libwebrtc = { rev = "ffc215666621cd903a689d1c56cce0a706ffe022", git = "https://github.com/zed-industries/livekit-rust-sdks" }
livekit = { rev = "102ebbb1ccfbdbcb7332d86dc30b1b1c8c01e4f8", git = "https://github.com/zed-industries/livekit-rust-sdks", features = ["__rustls-tls"] } livekit = { rev = "ffc215666621cd903a689d1c56cce0a706ffe022", git = "https://github.com/zed-industries/livekit-rust-sdks", features = ["__rustls-tls"] }
[target.'cfg(target_os = "macos")'.dependencies] [target.'cfg(target_os = "macos")'.dependencies]
core-foundation.workspace = true core-foundation.workspace = true

View File

@ -1,48 +1,49 @@
{ {
lib, lib,
crane,
rustToolchain,
rustPlatform,
cmake,
copyDesktopItems,
fetchFromGitHub,
curl,
clang,
perl,
pkg-config,
protobuf,
fontconfig,
freetype,
libgit2,
openssl,
sqlite,
zlib,
zstd,
alsa-lib,
libxkbcommon,
wayland,
libglvnd,
xorg,
stdenv, stdenv,
makeFontsConf,
vulkan-loader,
envsubst,
cargo-about,
cargo-bundle,
git,
livekit-libwebrtc,
apple-sdk_15, apple-sdk_15,
darwin, darwin,
darwinMinVersionHook, darwinMinVersionHook,
cargo-about,
cargo-bundle,
crane,
rustPlatform,
rustToolchain,
copyDesktopItems,
envsubst,
fetchFromGitHub,
makeFontsConf,
makeWrapper, makeWrapper,
alsa-lib,
cmake,
curl,
fontconfig,
freetype,
git,
libgit2,
libglvnd,
libxkbcommon,
livekit-libwebrtc,
nodejs_22, nodejs_22,
openssl,
perl,
pkg-config,
protobuf,
sqlite,
vulkan-loader,
wayland,
xorg,
zlib,
zstd,
withGLES ? false, withGLES ? false,
profile ? "release", profile ? "release",
}: }:
assert withGLES -> stdenv.hostPlatform.isLinux; assert withGLES -> stdenv.hostPlatform.isLinux;
let let
mkIncludeFilter = mkIncludeFilter =
root': path: type: root': path: type:
@ -58,6 +59,7 @@ let
"tooling" "tooling"
"Cargo.toml" "Cargo.toml"
".config" # nextest? ".config" # nextest?
".cargo"
]; ];
firstComp = builtins.head (lib.path.subpath.components relPath); firstComp = builtins.head (lib.path.subpath.components relPath);
in in
@ -68,6 +70,7 @@ let
commonArgs = commonArgs =
let let
zedCargoLock = builtins.fromTOML (builtins.readFile ../crates/zed/Cargo.toml); zedCargoLock = builtins.fromTOML (builtins.readFile ../crates/zed/Cargo.toml);
stdenv' = stdenv;
in in
rec { rec {
pname = "zed-editor"; pname = "zed-editor";
@ -82,7 +85,6 @@ let
nativeBuildInputs = nativeBuildInputs =
[ [
clang # TODO: use pkgs.clangStdenv or ignore cargo config?
cmake cmake
copyDesktopItems copyDesktopItems
curl curl
@ -92,8 +94,8 @@ let
cargo-about cargo-about
rustPlatform.bindgenHook rustPlatform.bindgenHook
] ]
++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ] ++ lib.optionals stdenv'.hostPlatform.isLinux [ makeWrapper ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ ++ lib.optionals stdenv'.hostPlatform.isDarwin [
# TODO: move to overlay so it's usable in the shell # TODO: move to overlay so it's usable in the shell
(cargo-bundle.overrideAttrs ( (cargo-bundle.overrideAttrs (
new: old: { new: old: {
@ -128,14 +130,14 @@ let
zlib zlib
zstd zstd
] ]
++ lib.optionals stdenv.hostPlatform.isLinux [ ++ lib.optionals stdenv'.hostPlatform.isLinux [
alsa-lib alsa-lib
libxkbcommon libxkbcommon
wayland wayland
gpu-lib gpu-lib
xorg.libxcb xorg.libxcb
] ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ ++ lib.optionals stdenv'.hostPlatform.isDarwin [
apple-sdk_15 apple-sdk_15
darwin.apple_sdk.frameworks.System darwin.apple_sdk.frameworks.System
(darwinMinVersionHook "10.15") (darwinMinVersionHook "10.15")
@ -143,6 +145,22 @@ let
cargoExtraArgs = "-p zed -p cli --locked --features=gpui/runtime_shaders"; cargoExtraArgs = "-p zed -p cli --locked --features=gpui/runtime_shaders";
stdenv =
pkgs:
let
base = pkgs.llvmPackages.stdenv;
addBinTools = old: {
cc = old.cc.override {
inherit (pkgs.llvmPackages) bintools;
};
};
custom = lib.pipe base [
(stdenv: stdenv.override addBinTools)
pkgs.stdenvAdapters.useMoldLinker
];
in
if stdenv'.hostPlatform.isLinux then custom else base;
env = { env = {
ZSTD_SYS_USE_PKG_CONFIG = true; ZSTD_SYS_USE_PKG_CONFIG = true;
FONTCONFIG_FILE = makeFontsConf { FONTCONFIG_FILE = makeFontsConf {
@ -153,7 +171,6 @@ let
}; };
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.";
RELEASE_VERSION = version; RELEASE_VERSION = version;
RUSTFLAGS = if withGLES then "--cfg gles" else "";
LK_CUSTOM_WEBRTC = livekit-libwebrtc; LK_CUSTOM_WEBRTC = livekit-libwebrtc;
CARGO_PROFILE = profile; CARGO_PROFILE = profile;
@ -162,7 +179,7 @@ let
# for some reason these deps being in buildInputs isn't enough, the only thing # for some reason these deps being in buildInputs isn't enough, the only thing
# about them that's special is that they're manually dlopened at runtime # about them that's special is that they're manually dlopened at runtime
NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux "-rpath ${ NIX_LDFLAGS = lib.optionalString stdenv'.hostPlatform.isLinux "-rpath ${
lib.makeLibraryPath [ lib.makeLibraryPath [
gpu-lib gpu-lib
wayland wayland
@ -171,7 +188,7 @@ let
}; };
# prevent nix from removing the "unused" wayland/gpu-lib rpaths # prevent nix from removing the "unused" wayland/gpu-lib rpaths
dontPatchELF = stdenv.hostPlatform.isLinux; dontPatchELF = stdenv'.hostPlatform.isLinux;
# TODO: try craneLib.cargoNextest separate output # TODO: try craneLib.cargoNextest separate output
# for now we're not worried about running our test suite (or tests for deps) in the nix sandbox # for now we're not worried about running our test suite (or tests for deps) in the nix sandbox
@ -182,13 +199,24 @@ let
overrideVendorGitCheckout = overrideVendorGitCheckout =
let let
hasWebRtcSys = builtins.any (crate: crate.name == "webrtc-sys"); hasWebRtcSys = builtins.any (crate: crate.name == "webrtc-sys");
# we can't set $RUSTFLAGS because that clobbers the cargo config
# see https://github.com/rust-lang/cargo/issues/5376#issuecomment-2163350032
glesConfig = builtins.toFile "config.toml" ''
[target.'cfg(all())']
rustflags = ["--cfg", "gles"]
'';
# `webrtc-sys` expects a staticlib; nixpkgs' `livekit-webrtc` has been patched to # `webrtc-sys` expects a staticlib; nixpkgs' `livekit-webrtc` has been patched to
# produce a `dylib`... patching `webrtc-sys`'s build script is the easier option # produce a `dylib`... patching `webrtc-sys`'s build script is the easier option
# TODO: send livekit sdk a PR to make this configurable # TODO: send livekit sdk a PR to make this configurable
postPatch = '' postPatch =
substituteInPlace webrtc-sys/build.rs --replace-fail \ ''
"cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc" substituteInPlace webrtc-sys/build.rs --replace-fail \
''; "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc"
''
+ lib.optionalString withGLES ''
cat ${glesConfig} >> .cargo/config/config.toml
'';
in in
crates: drv: crates: drv:
if hasWebRtcSys crates then if hasWebRtcSys crates then

View File

@ -1,7 +1,5 @@
{ {
mkShell, mkShell,
stdenv,
stdenvAdapters,
makeFontsConf, makeFontsConf,
zed-editor, zed-editor,
@ -12,12 +10,7 @@
protobuf, protobuf,
nodejs_22, nodejs_22,
}: }:
let (mkShell.override { inherit (zed-editor) stdenv; }) {
moldStdenv = stdenvAdapters.useMoldLinker stdenv;
mkShell' =
if stdenv.hostPlatform.isLinux then mkShell.override { stdenv = moldStdenv; } else mkShell;
in
mkShell' {
inputsFrom = [ zed-editor ]; inputsFrom = [ zed-editor ];
packages = [ packages = [
rust-analyzer rust-analyzer