Skip to content

Commit

Permalink
feat: switch to new Darwin SDK
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Oct 21, 2024
1 parent f9e6192 commit 58c672d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 64 deletions.
28 changes: 14 additions & 14 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
84 changes: 35 additions & 49 deletions lib/rust/mkAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) (
{
Expand Down

0 comments on commit 58c672d

Please sign in to comment.