From d383e90ace6480d6846b6dd3cbe66d30c044bd30 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Sun, 14 Nov 2021 16:27:00 -0300 Subject: [PATCH] _7zz: build on macOS --- pkgs/tools/archivers/7zz/default.nix | 47 ++++++++++++------- .../archivers/7zz/fix-build-on-darwin.patch | 24 ++++++++++ pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 pkgs/tools/archivers/7zz/fix-build-on-darwin.patch diff --git a/pkgs/tools/archivers/7zz/default.nix b/pkgs/tools/archivers/7zz/default.nix index 0c8c6ed5d3ad..150230f775a4 100644 --- a/pkgs/tools/archivers/7zz/default.nix +++ b/pkgs/tools/archivers/7zz/default.nix @@ -2,9 +2,9 @@ , lib , fetchurl - # Only used for x86/x86_64 + # Only used for Linux's x86/x86_64 , uasm -, useUasm ? stdenv.hostPlatform.isx86 +, useUasm ? (stdenv.isLinux && stdenv.hostPlatform.isx86) # RAR code is under non-free unRAR license # see the meta.license section below for more details @@ -16,13 +16,13 @@ }: let - inherit (stdenv.hostPlatform) system; - platformSuffix = { - aarch64-linux = "_arm64"; - i686-linux = "_x86"; - x86_64-linux = "_x64"; - }.${system} or - (builtins.trace "`platformSuffix` not available for `${system}.` Making a generic `7zz` build." ""); + makefile = { + aarch64-darwin = "../../cmpl_mac_arm64.mak"; + x86_64-darwin = "../../cmpl_mac_x64.mak"; + aarch64-linux = "../../cmpl_gcc_arm64.mak"; + i686-linux = "../../cmpl_gcc_x86.mak"; + x86_64-linux = "../../cmpl_gcc_x64.mak"; + }.${stdenv.hostPlatform.system} or "../../cmpl_gcc.mak"; # generic build in stdenv.mkDerivation rec { pname = "7zz"; @@ -51,27 +51,40 @@ stdenv.mkDerivation rec { ''; }; - sourceRoot = "CPP/7zip/Bundles/Alone2"; + sourceRoot = "."; + + patches = [ ./fix-build-on-darwin.patch ]; + patchFlags = [ "-p0" ]; + + NIX_CFLAGS_COMPILE = lib.optionals stdenv.isDarwin [ + "-Wno-deprecated-copy-dtor" + ]; + + inherit makefile; makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" "CXX=${stdenv.cc.targetPrefix}c++" - ] ++ - lib.optionals useUasm [ "MY_ASM=uasm" ] ++ + ] + ++ lib.optionals useUasm [ "MY_ASM=uasm" ] + # We need at minimum 10.13 here because of utimensat, however since + # we need a bump anyway, let's set the same minimum version as the one in + # aarch64-darwin so we don't need additional changes for it + ++ lib.optionals stdenv.isDarwin [ "MACOSX_DEPLOYMENT_TARGET=10.16" ] # it's the compression code with the restriction, see DOC/License.txt - lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]; - - makefile = "../../cmpl_gcc${platformSuffix}.mak"; + ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]; nativeBuildInputs = lib.optionals useUasm [ uasm ]; enableParallelBuilding = true; + preBuild = "cd CPP/7zip/Bundles/Alone2"; + installPhase = '' runHook preInstall - install -Dm555 -t $out/bin b/g${platformSuffix}/7zz + install -Dm555 -t $out/bin b/*/7zz install -Dm444 -t $out/share/doc/${pname} ../../../../DOC/*.txt runHook postInstall @@ -96,7 +109,7 @@ stdenv.mkDerivation rec { # the unRAR compression code is disabled by default lib.optionals enableUnfree [ unfree ]; maintainers = with maintainers; [ anna328p peterhoeg jk ]; - platforms = platforms.linux; + platforms = platforms.unix; mainProgram = "7zz"; }; } diff --git a/pkgs/tools/archivers/7zz/fix-build-on-darwin.patch b/pkgs/tools/archivers/7zz/fix-build-on-darwin.patch new file mode 100644 index 000000000000..9d8ee7f9bc60 --- /dev/null +++ b/pkgs/tools/archivers/7zz/fix-build-on-darwin.patch @@ -0,0 +1,24 @@ +diff -Naur CPP/7zip/Common/FileStreams.cpp CPP/7zip/Common/FileStreams.cpp +--- CPP/7zip/Common/FileStreams.cpp ++++ CPP/7zip/Common/FileStreams.cpp +@@ -12,7 +12,7 @@ + #include + + // for major()/minor(): +-#if defined(__FreeBSD__) || defined(BSD) ++#if defined(__FreeBSD__) || defined(BSD) || defined(__APPLE__) + #include + #else + #include +diff -Naur CPP/7zip/UI/Common/UpdateCallback.cpp CPP/7zip/UI/Common/UpdateCallback.cpp +--- CPP/7zip/UI/Common/UpdateCallback.cpp ++++ CPP/7zip/UI/Common/UpdateCallback.cpp +@@ -9,7 +9,7 @@ + // #include + + // for major()/minor(): +-#if defined(__FreeBSD__) || defined(BSD) ++#if defined(__FreeBSD__) || defined(BSD) || defined(__APPLE__) + #include + #else + #include diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 325540d5baa7..622d78b7ecd1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -995,7 +995,7 @@ with pkgs; _6tunnel = callPackage ../tools/networking/6tunnel { }; - _7zz = callPackage ../tools/archivers/7zz { }; + _7zz = darwin.apple_sdk_11_0.callPackage ../tools/archivers/7zz { }; _9pfs = callPackage ../tools/filesystems/9pfs { };