Skip to content

Commit

Permalink
osx: use nix's apple sdk by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Jan 16, 2024
1 parent 80b23c9 commit c59669a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@
# Solving platform specific spaghetti below
runtimeForTarget = target: let
system = zig2nix-lib.mkZigSystemFromString target;
double = nlib.systems.parse.doubleFromSystem system;
targetPkgs = nixpkgs.outputs.legacyPackages.${double};
env = {
linux = {
LIBRARY_PATH = "LD_LIBRARY_PATH";
nativeBuildInputs = [ pkgs.autoPatchelfHook ];
};
darwin = {
darwin = let
sdk =
if (nlib.versionAtLeast targetPkgs.targetPlatform.darwinSdkVersion "10.13") then targetPkgs.darwin.apple_sdk.MacOSX-SDK
else warn "zig only supports macOS 10.13+, forcing SDK 11.0" targetPkgs.darwin.apple_sdk_11_0.MacOSX-SDK;
in {
LIBRARY_PATH = "DYLD_LIBRARY_PATH";
defaultTargetFlags = [ "--sysroot" sdk ];
};
};
libs = {
Expand Down
2 changes: 1 addition & 1 deletion lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ rec {
darwin = let
sdkVer =
if (versionAtLeast p.darwinSdkVersion "10.13") then p.darwinSdkVersion
else warn "zig only supports macOS 10.13+, forcing darwinSdkVersion to 10.13" "10.13";
else warn "zig only supports macOS 10.13+, forcing SDK 11.0" "11.0";
in "${system.zig.cpu}-${system.zig.kernel}.${sdkVer}-${system.zig.abi}";
}.${system.kernel.name} or (zigTripleFromSystem system);

Expand Down
10 changes: 6 additions & 4 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ let
wrapper-args = zigWrapperArgs
++ optionals (length runtime.bins > 0) [ "--prefix" "PATH" ":" (makeBinPath runtime.bins) ]
++ optionals (length runtime.libs > 0) [ "--prefix" runtime.env.LIBRARY_PATH ":" (makeLibraryPath runtime.libs) ];
attrs = lib.optionalAttrs (pathExists zigBuildZon && !userAttrs ? name) {
attrs = optionalAttrs (pathExists zigBuildZon && !userAttrs ? name) {
pname = zon.name;
} // lib.optionalAttrs (pathExists zigBuildZon && !userAttrs ? version) {
} // optionalAttrs (pathExists zigBuildZon && !userAttrs ? version) {
version = zon.version;
} // userAttrs;
default-flags = if lib.versionAtLeast zig.version "0.11" then
default-flags =
if versionAtLeast zig.version "0.11" then
[ "-Doptimize=ReleaseSafe" ]
else
[ "-Drelease-safe=true" ];
default-target-flags = optionals (zigTarget == null) (runtime.env.defaultTargetFlags or []);
in stdenvNoCC.mkDerivation (
attrs // {
zigBuildFlags = (attrs.zigBuildFlags or default-flags) ++ [ "-Dtarget=${target}" ];
zigBuildFlags = (attrs.zigBuildFlags or default-flags) ++ [ "-Dtarget=${target}" ] ++ default-target-flags;
nativeBuildInputs = [ zig.hook makeWrapper ]
++ (runtime.env.nativeBuildInputs or [])
++ (attrs.nativeBuildInputs or []);
Expand Down

0 comments on commit c59669a

Please sign in to comment.