From 58c672d14086891286bc4b1be8352c25396cdd09 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 21 Oct 2024 19:03:21 +0200 Subject: [PATCH] feat: switch to new Darwin SDK Signed-off-by: Roman Volosatovs --- flake.lock | 28 +++++++-------- flake.nix | 2 +- lib/rust/mkAttrs.nix | 84 ++++++++++++++++++-------------------------- 3 files changed, 50 insertions(+), 64 deletions(-) diff --git a/flake.lock b/flake.lock index e3cebf56..afb617f0 100644 --- a/flake.lock +++ b/flake.lock @@ -73,11 +73,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1729375822, - "narHash": "sha256-bRo4xVwUhvJ4Gz+OhWMREFMdBOYSw4Yi1Apj01ebbug=", + "lastModified": 1729492502, + "narHash": "sha256-d6L4bBlUWr4sHC+eRXo+4acFPEFXKmqHpM/BfQ5gQQw=", "owner": "nix-community", "repo": "fenix", - "rev": "2853e7d9b5c52a148a9fb824bfe4f9f433f557ab", + "rev": "4002a1ec3486b855f341d2b864ba06b61e73af28", "type": "github" }, "original": { @@ -161,7 +161,7 @@ "macos-sdk": { "flake": false, "locked": { - "lastModified": 1694769349, + "lastModified": 1693509154, "narHash": "sha256-TEvVJy+NMPyzgWSk/6S29ZMQR+ICFxSdS3tw247uhFc=", "type": "tarball", "url": "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz" @@ -323,16 +323,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1729265718, - "narHash": "sha256-4HQI+6LsO3kpWTYuVGIzhJs1cetFcwT7quWCk/6rqeo=", + "lastModified": 1729519136, + "narHash": "sha256-6/hRRcendHWPsRHwrQD692XIJX/qKE+RQtUlk+7kbbE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ccc0c2126893dd20963580b6478d1a10a4512185", + "rev": "3576b958e4397bcfbf8d664286fca8f418c906be", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-unstable", + "ref": "staging", "repo": "nixpkgs", "type": "github" } @@ -354,11 +354,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1729255720, - "narHash": "sha256-yODOuZxBkS0UfqMa6nmbqNbVfIbsu0tYLbV5vZzmsqI=", + "lastModified": 1729454508, + "narHash": "sha256-1W5B/CnLgdC03iIFG0wtawO1+dGDWDpc84PeOHo2ecU=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "72b214fbfbe6f7b95a7877b962783bd42062cc0a", + "rev": "9323b5385863739d1c113f02e4cf3f2777c09977", "type": "github" }, "original": { @@ -419,11 +419,11 @@ ] }, "locked": { - "lastModified": 1729391507, - "narHash": "sha256-as0I9xieJUHf7kiK2a9znDsVZQTFWhM1pLivII43Gi0=", + "lastModified": 1729477859, + "narHash": "sha256-r0VyeJxy4O4CgTB/PNtfQft9fPfN1VuGvnZiCxDArvg=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "784981a9feeba406de38c1c9a3decf966d853cca", + "rev": "ada8266712449c4c0e6ee6fcbc442b3c217c79e1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index dac2e853..85b10e8b 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ inputs.nix-filter.url = "github:numtide/nix-filter"; inputs.nix-log.url = "github:rvolosatovs/nix-log"; inputs.nixlib.url = "github:nix-community/nixpkgs.lib"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/staging"; inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; inputs.rust-overlay.url = "github:oxalica/rust-overlay"; diff --git a/lib/rust/mkAttrs.nix b/lib/rust/mkAttrs.nix index 0a34cd22..1e375a05 100644 --- a/lib/rust/mkAttrs.nix +++ b/lib/rust/mkAttrs.nix @@ -334,21 +334,9 @@ with self.lib.rust.targets; # Removing vendor references here invalidates the signature, which is required on aarch64-darwin doNotRemoveReferencesToVendorDir = true; } - // optionalAttrs pkgsCross.stdenv.hostPlatform.isDarwin { - preBuild = '' - export SDKROOT="${macos-sdk}" - ''; - - # Use `rust-lld` linker for Darwin targets - "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; - } // ( - if final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin - then { - # use defaults for Darwin-to-Darwin builds - } # Use Zig C compiler and `rust-lld` linker for Darwin targets on non-Darwin platforms - else if pkgsCross.stdenv.hostPlatform.isDarwin + if !final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin then { depsBuildBuild = [ crossZigCC @@ -358,51 +346,49 @@ with self.lib.rust.targets; crossZigCC ]; - preBuild = - '' - export HOME=$(mktemp -d) - '' - + optionalString pkgsCross.stdenv.hostPlatform.isDarwin '' - export SDKROOT="${macos-sdk}" - ''; + preBuild = '' + export HOME=$(mktemp -d) + export SDKROOT="${macos-sdk}" + ''; "CC_${target}" = "${target}-zigcc"; "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; } else - ( - { - depsBuildBuild = - [ - pkgsCross.stdenv.cc - ] - ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads; - - disallowedReferences = [ + { + depsBuildBuild = + [ pkgsCross.stdenv.cc - ]; + ] + ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads; - "AR_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}ar"; - "CC_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; - } - # Use `mold` linker for Linux targets - // optionalAttrs pkgsCross.stdenv.hostPlatform.isLinux { - nativeBuildInputs = [ - final.mold - ]; + disallowedReferences = [ + pkgsCross.stdenv.cc + ]; - "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Clink-arg=-fuse-ld=mold"; - } - # Always build static binaries for Windows targets - // optionalAttrs pkgsCross.stdenv.hostPlatform.isWindows { - "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Ctarget-feature=+crt-static"; - } - # Use default linker for Wasm targets - // optionalAttrs (!pkgsCross.stdenv.hostPlatform.isWasm) { - "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; - } - ) + "AR_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}ar"; + "CC_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; + } + # Use `mold` linker for Linux targets + // optionalAttrs pkgsCross.stdenv.hostPlatform.isLinux { + nativeBuildInputs = [ + final.mold + ]; + + "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Clink-arg=-fuse-ld=mold"; + } + # Always build static binaries for Windows targets + // optionalAttrs pkgsCross.stdenv.hostPlatform.isWindows { + "CARGO_TARGET_${toUpper (kebab2snake target)}_RUSTFLAGS" = "-Ctarget-feature=+crt-static"; + } + // optionalAttrs pkgsCross.stdenv.hostPlatform.isDarwin { + "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "rust-lld"; + } + # Use default linker for Wasm targets + // optionalAttrs (!pkgsCross.stdenv.hostPlatform.isWasm) { + "CARGO_TARGET_${toUpper (kebab2snake target)}_LINKER" = "${pkgsCross.stdenv.cc.targetPrefix}cc"; + } ) // optionalAttrs (final.stdenv.buildPlatform.config != pkgsCross.stdenv.hostPlatform.config) ( {