Unverified Commit a214160f authored by dotlambda's avatar dotlambda Committed by GitHub
Browse files

anki: fix darwin build, add missing platform wheels (#499992)

parents d0951ec3 74db1477
Loading
Loading
Loading
Loading
+57 −51
Original line number Diff line number Diff line
@@ -43,7 +43,9 @@ let
  srcHash = "sha256-0hLTQR7f7s58DUgAZbDeREMee6VrqAKHyhS1Hs/Em1A=";
  cargoHash = "sha256-qcB+r9VzBz6ACZaXPL26MOxxtb/h2OIuxyc54vUgfPM=";
  yarnHash = "sha256-EmKeHORr/+qsDzAwtearMi7qodcCgjeAQcy+79HL7Vg=";
  pythonDeps = with python3Packages; [
  pythonDeps =
    with python3Packages;
    [
      # anki (pylib) runtime deps
      decorator
      distro
@@ -93,6 +95,10 @@ let
      urllib3
      werkzeug
      wrapt
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      anki-audio
      anki-mac-helper
    ];

  src = fetchFromGitHub {
+53 −0
Original line number Diff line number Diff line
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  stdenv,
  hatchling,
  mpv-unwrapped,
  lame,
}:

buildPythonPackage (finalAttrs: {
  pname = "anki-audio";
  version = "0.1.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "ankitects";
    repo = "anki-bundle-extras";
    rev = "e83c6e64dcb110ed579fc78afbb4e72bed8fb9e9";
    hash = "sha256-iOAZ7EytEVpvsrnVFk6bkiU8FWf2Q7tTzJjawZQCW6E=";
  };

  build-system = [ hatchling ];

  env = {
    ANKI_AUDIO_TARGET_OS = "darwin";
    ANKI_AUDIO_TARGET_ARCH = stdenv.hostPlatform.darwinArch;
  };

  preBuild =
    let
      archDir = if stdenv.hostPlatform.isAarch64 then "arm64" else "amd64";
    in
    ''
      mkdir -p mac/${archDir}/dist/audio/Resources
      ln -s ${lib.getExe mpv-unwrapped} ${lib.getExe lame} mac/${archDir}/dist/audio/Resources/
    '';

  pythonImportsCheck = [ "anki_audio" ];

  meta = {
    description = "Audio binaries (mpv, lame) for Anki";
    homepage = "https://github.com/ankitects/anki-bundle-extras";
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    platforms = lib.platforms.darwin;
    license = lib.licenses.gpl2Plus;
    maintainers = with lib.maintainers; [
      euank
      junestepp
      oxij
    ];
  };
})
+46 −0
Original line number Diff line number Diff line
{
  lib,
  buildPythonPackage,
  stdenv,
  anki,
  hatchling,
  swift,
}:

buildPythonPackage (finalAttrs: {
  pname = "anki-mac-helper";
  inherit (anki) version src;
  pyproject = true;

  sourceRoot = "${finalAttrs.src.name}/qt/mac";

  build-system = [ hatchling ];
  nativeBuildInputs = [ swift ];

  # This is intended to emulate github:ankitects/anki/qt/mac/helper_build.py,
  # but targets the platform directly instead of universal binary + lipo.
  preBuild = ''
    swiftc \
      -target ${stdenv.hostPlatform.darwinArch}-apple-macos11 \
      -emit-library \
      -module-name ankihelper \
      -O \
      *.swift \
      -o anki_mac_helper/libankihelper.dylib
  '';

  pythonImportsCheck = [ "anki_mac_helper" ];

  meta = {
    description = "Small support library for Anki on Macs";
    homepage = "https://github.com/ankitects/anki";
    sourceProvenance = with lib.sourceTypes; [ fromSource ];
    platforms = lib.platforms.darwin;
    license = lib.licenses.agpl3Plus;
    maintainers = with lib.maintainers; [
      euank
      junestepp
      oxij
    ];
  };
})
+6 −0
Original line number Diff line number Diff line
@@ -758,6 +758,12 @@ self: super: with self; {
  anitopy = callPackage ../development/python-modules/anitopy { };
  anki-audio = callPackage ../development/python-modules/anki-audio { };
  anki-mac-helper = callPackage ../development/python-modules/anki-mac-helper {
    inherit (pkgs) swift;
  };
  anndata = callPackage ../development/python-modules/anndata { };
  annexremote = callPackage ../development/python-modules/annexremote { };