diff --git a/flake.nix b/flake.nix index 1b2bf20..be2599e 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { diff --git a/lib.nix b/lib.nix index 6575fe1..457fb2d 100644 --- a/lib.nix +++ b/lib.nix @@ -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); diff --git a/package.nix b/package.nix index 66150b2..4633c4d 100644 --- a/package.nix +++ b/package.nix @@ -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 []);