Unverified Commit b932454f authored by 7c6f434c's avatar 7c6f434c Committed by GitHub
Browse files

botan: refactoring (#339560)

parents bcc7693c c8a92b60
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
{ callPackage, ... } @ args:

callPackage ./generic.nix (args // {
  baseVersion = "2.19";
  revision = "5";
  hash = "sha256-3+6g4KbybWckxK8B2pp7iEh62y2Bunxy/K9S21IsmtQ=";
})
+0 −9
Original line number Diff line number Diff line
{ callPackage, stdenv, lib, ... } @ args:

callPackage ./generic.nix (args // {
  baseVersion = "3.5";
  revision = "0";
  hash = "sha256-Z+ja4cokaNkN5OYByH1fMf9JKzjoq4vL0C3fcQTtip8=";
  # this patch fixes build errors on MacOS with SDK 10.12, recheck to remove this again
  extraPatches = lib.optionals stdenv.hostPlatform.isDarwin [ ./botan3-macos.patch ];
})
+130 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchurl,
  python3,
  docutils,
  bzip2,
  zlib,
  darwin,
  static ? stdenv.hostPlatform.isStatic, # generates static libraries *only*
}:

let
  common =
    {
      version,
      hash,
      patches ? [ ],
    }:
    stdenv.mkDerivation (finalAttrs: {
      pname = "botan";
      inherit version;

      __structuredAttrs = true;
      enableParallelBuilding = true;
      strictDeps = true;

      outputs = [
        "bin"
        "out"
        "dev"
        "doc"
        "man"
      ];

      src = fetchurl {
        url = "http://botan.randombit.net/releases/Botan-${finalAttrs.version}.tar.xz";
        inherit hash;
      };

      inherit patches;

      nativeBuildInputs = [
        python3
        docutils
      ];

      buildInputs =
        [
          bzip2
          zlib
        ]
        ++ lib.optionals stdenv.isDarwin (
          with darwin.apple_sdk.frameworks;
          [
            CoreServices
            Security
          ]
        );

      buildTargets =
        [ "cli" ]
        ++ lib.optionals finalAttrs.doCheck [ "tests" ]
        ++ lib.optionals static [ "static" ]
        ++ lib.optionals (!static) [ "shared" ];

      botanConfigureFlags =
        [
          "--prefix=${placeholder "out"}"
          "--bindir=${placeholder "bin"}/bin"
          "--docdir=${placeholder "doc"}/share/doc"
          "--mandir=${placeholder "man"}/share/man"
          "--no-install-python-module"
          "--build-targets=${lib.concatStringsSep "," finalAttrs.buildTargets}"
          "--with-bzip2"
          "--with-zlib"
          "--with-rst2man"
        ]
        ++ lib.optionals stdenv.cc.isClang [
          "--cc=clang"
        ]
        ++ lib.optionals stdenv.hostPlatform.isAarch64 [
          "--cpu=aarch64"
        ];

      configurePhase = ''
        runHook preConfigure
        python configure.py ''${botanConfigureFlags[@]}
        runHook postConfigure
      '';

      preInstall = ''
        if [ -d src/scripts ]; then
          patchShebangs src/scripts
        fi
      '';

      postInstall = ''
        cd "$out"/lib/pkgconfig
        ln -s botan-*.pc botan.pc || true
      '';

      doCheck = true;

      meta = with lib; {
        description = "Cryptographic algorithms library";
        homepage = "https://botan.randombit.net";
        mainProgram = "botan";
        maintainers = with maintainers; [
          raskin
          thillux
        ];
        platforms = platforms.unix;
        license = licenses.bsd2;
      };
    });
in
{
  botan3 = common {
    version = "3.5.0";
    hash = "sha256-Z+ja4cokaNkN5OYByH1fMf9JKzjoq4vL0C3fcQTtip8=";
    # this patch fixes build errors on MacOS with SDK 10.12, recheck to remove this again
    patches = lib.optionals stdenv.hostPlatform.isDarwin [ ./botan3-macos.patch ];
  };

  botan2 = common {
    version = "2.19.5";
    hash = "sha256-3+6g4KbybWckxK8B2pp7iEh62y2Bunxy/K9S21IsmtQ=";
  };
}
+0 −83
Original line number Diff line number Diff line
{ lib, stdenv, fetchurl, python3, bzip2, zlib, gmp, boost
# Passed by version specific builders
, baseVersion, revision, hash
, sourceExtension ? "tar.xz"
, extraConfigureFlags ? ""
, extraPatches ? [ ]
, badPlatforms ? [ ]
, postPatch ? null
, knownVulnerabilities ? [ ]
, CoreServices ? null
, Security ? null
, static ? stdenv.hostPlatform.isStatic # generates static libraries *only*
, ...
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "botan";
  version = "${baseVersion}.${revision}";

  __structuredAttrs = true;

  outputs = [ "out" "dev" ];

  src = fetchurl {
    name = "Botan-${finalAttrs.version}.${sourceExtension}";
    urls = [
       "http://files.randombit.net/botan/v${baseVersion}/Botan-${finalAttrs.version}.${sourceExtension}"
       "http://botan.randombit.net/releases/Botan-${finalAttrs.version}.${sourceExtension}"
    ];
    inherit hash;
  };
  patches = extraPatches;
  inherit postPatch;

  nativeBuildInputs = [ python3 ];
  buildInputs = [ bzip2 zlib gmp boost ]
    ++ lib.optionals stdenv.isDarwin [ CoreServices Security ];

  botanConfigureFlags = [
    "--prefix=${placeholder "out"}"
    "--with-bzip2"
    "--with-zlib"
  ] ++ lib.optionals stdenv.cc.isClang [
    "--cc=clang"
  ] ++ lib.optionals stdenv.hostPlatform.isAarch64 [
    "--cpu=aarch64"
  ] ++ lib.optionals static [
    "--enable-static-library"
    "--disable-shared-library"
  ];

  configurePhase = ''
    runHook preConfigure
    python configure.py ''${botanConfigureFlags[@]} ${extraConfigureFlags}
    runHook postConfigure
  '';

  enableParallelBuilding = true;

  preInstall = ''
    if [ -d src/scripts ]; then
      patchShebangs src/scripts
    fi
  '';

  postInstall = ''
    cd "$out"/lib/pkgconfig
    ln -s botan-*.pc botan.pc || true
  '';

  doCheck = true;

  meta = with lib; {
    description = "Cryptographic algorithms library";
    mainProgram = "botan";
    maintainers = with maintainers; [ raskin thillux ];
    platforms = platforms.unix;
    license = licenses.bsd2;
    inherit badPlatforms;
    inherit knownVulnerabilities;
  };
  passthru.updateInfo.downloadPage = "http://files.randombit.net/botan/";
})
+4 −7
Original line number Diff line number Diff line
@@ -19487,13 +19487,10 @@ with pkgs;
  bosh-cli = callPackage ../applications/networking/cluster/bosh-cli { };
  botan2 = callPackage ../development/libraries/botan/2.0.nix {
    inherit (darwin.apple_sdk.frameworks) CoreServices Security;
  };
  botan3 = callPackage ../development/libraries/botan/3.0.nix {
    inherit (darwin.apple_sdk.frameworks) CoreServices Security;
  };
  inherit (callPackages ../development/libraries/botan { })
    botan2
    botan3
    ;
  box2d = callPackage ../development/libraries/box2d {
    inherit (darwin.apple_sdk.frameworks) Carbon Cocoa Kernel OpenGL;