Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: switch to new Darwin SDK #286

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/rust-complex/flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
inputs.nixify.inputs.nixpkgs-darwin.follows = "nixpkgs";
inputs.nixify.inputs.nixpkgs-nixos.follows = "nixpkgs";
inputs.nixify.inputs.nixpkgs.follows = "nixpkgs";
inputs.nixify.url = "github:rvolosatovs/nixify";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";

Expand Down
53 changes: 18 additions & 35 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
inputs.advisory-db.flake = false;
inputs.advisory-db.url = "github:rustsec/advisory-db";
inputs.crane.url = "github:ipetkov/crane";
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs-nixos";
inputs.fenix.inputs.nixpkgs.follows = "nixpkgs";
inputs.fenix.url = "github:nix-community/fenix";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.macos-sdk.url = "https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.0/MacOSX14.0.sdk.tar.xz";
inputs.macos-sdk.flake = false;
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-darwin.url = "github:nixos/nixpkgs/nixpkgs-24.05-darwin";
inputs.nixpkgs-nixos.url = "github:nixos/nixpkgs/nixos-24.05";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs-nixos";
inputs.nixpkgs.url = "github:nixos/nixpkgs/staging";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";

outputs = inputs: let
Expand Down
9 changes: 2 additions & 7 deletions lib/mkFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
self,
flake-utils,
nixlib,
nixpkgs-darwin,
nixpkgs-nixos,
nixpkgs,
...
}: {
defaultExcludePaths,
Expand Down Expand Up @@ -61,11 +60,7 @@ with self.lib;
(
system: let
pkgs =
import (
if system == aarch64-darwin || system == x86_64-darwin
then nixpkgs-darwin
else nixpkgs-nixos
) {
import nixpkgs {
inherit
overlays
system
Expand Down
9 changes: 2 additions & 7 deletions lib/rust/defaultPkgsFor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
self,
flake-utils,
nixpkgs-darwin,
nixpkgs-nixos,
nixpkgs,
...
}:
with flake-utils.lib.system;
Expand Down Expand Up @@ -88,11 +87,7 @@ with self.lib.rust.targets;
else if target == wasm32-unknown-unknown || target == wasm32-wasip1
then pkgs.pkgsCross.wasi32
else
import (
if pkgs.stdenv.buildPlatform.isDarwin
then nixpkgs-darwin
else nixpkgs-nixos
) {
import nixpkgs {
crossSystem.config =
if target == riscv64gc-unknown-linux-musl
then "riscv64-unknown-linux-musl"
Expand Down
74 changes: 36 additions & 38 deletions lib/rust/mkAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ with self.lib.rust.targets;
# Removing vendor references here invalidates the signature, which is required on aarch64-darwin
doNotRemoveReferencesToVendorDir = true;
}
# Use `rust-lld` linker and Zig C compiler for Darwin targets
// (
if pkgsCross.stdenv.hostPlatform.isDarwin
# Use Zig C compiler and `rust-lld` linker for Darwin targets on non-Darwin platforms
if !final.stdenv.buildPlatform.isDarwin && pkgsCross.stdenv.hostPlatform.isDarwin
then {
depsBuildBuild = [
crossZigCC
Expand All @@ -346,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) (
{
Expand Down
Loading