Commit 0596d39e authored by Alexis Hildebrandt's avatar Alexis Hildebrandt
Browse files

vcv-rack: add support for darwin platform and modernize

parent ab04d94e
Loading
Loading
Loading
Loading
+179 −110
Original line number Diff line number Diff line
{
  alsa-lib,
  apple-sdk_13,
  cmake,
  copyDesktopItems,
  curl,
@@ -21,8 +22,10 @@
  libsamplerate,
  makeDesktopItem,
  makeWrapper,
  openssl,
  pkg-config,
  rtmidi,
  rsync,
  speexdsp,
  stdenv,
  wrapGAppsHook3,
@@ -38,65 +41,65 @@ let
    owner = "jpommier";
    repo = "pffft";
    rev = "fbc4058602803f40dc554b8a5d2bcc694c005f2f";
    sha256 = "16biji3115232cr1j975hpxw68lfybajlspnhfjcwg8jz2d8ybrf";
    hash = "sha256-Li+PmvgSPc6kg/ZqKtXyjiLD+4XlJBkyE0OUEEaUcZk=";
  };
  fuzzysearchdatabase-source = fetchFromBitbucket {
    owner = "j_norberg";
    repo = "fuzzysearchdatabase";
    rev = "23122d1ff60d936fd766361a30210c954e0c5449";
    sha256 = "1s88blx1rn2racmb8n5g0kh1ym7v21573l5m42c4nz266vmrvrvz";
    hash = "sha256-f+ed6zZGfEuYILXQcUoQ+1Qf4ASvWLQqU1nYHDpdCOk=";
  };
  nanovg-source = fetchFromGitHub {
    owner = "VCVRack";
    repo = "nanovg";
    rev = "0bebdb314aff9cfa28fde4744bcb037a2b3fd756";
    sha256 = "HmQhCE/zIKc3f+Zld229s5i5MWzRrBMF9gYrn8JVQzg=";
    hash = "sha256-HmQhCE/zIKc3f+Zld229s5i5MWzRrBMF9gYrn8JVQzg=";
  };
  nanosvg-source = fetchFromGitHub {
    owner = "memononen";
    repo = "nanosvg";
    rev = "9da543e8329fdd81b64eb48742d8ccb09377aed1";
    sha256 = "1pkzv75kavkhrbdd2kvq755jyr0vamgrfr7lc33dq3ipkzmqvs2l";
    hash = "sha256-VOiN6583DtzGYPRkl19VG2QvSzl4T9HaynBuNcvZf94=";
  };
  osdialog-source = fetchFromGitHub {
    owner = "AndrewBelt";
    repo = "osdialog";
    rev = "d0f64f0798c2e47f61d90a5505910ff2d63ca049";
    sha256 = "1d3058x6wgzw7b0wai792flk7s6ffw0z4n9sl016v91yjwv7ds3a";
    hash = "sha256-auh2Npc+pG0CoDpZ8gF3zugzqRPpRMXBOvw/bjoqYLQ=";
  };
  oui-blendish-source = fetchFromGitHub {
    owner = "VCVRack";
    repo = "oui-blendish";
    rev = "2fc6405883f8451944ed080547d073c8f9f31898";
    sha256 = "1bs0654312555vm7nzswsmky4l8759bjdk17pl22p49rw9k4a1px";
    hash = "sha256-/QZFZuI5kSsEvSfMJlcqB1HiZ9Vcf3vqLqWIMEgxQK8=";
  };
  simde-source = fetchFromGitHub {
    owner = "simd-everywhere";
    repo = "simde";
    rev = "416091ebdb9e901b29d026633e73167d6353a0b0";
    sha256 = "064ygc6c737yjx04rydwwhkr4n4s4rbvj27swxwyzvp1h8nka6xf";
    hash = "sha256-rhs1LYLh7u955/oIuVcmmliSJ+S8+UxAl/6Mwwx7nhg=";
  };
  tinyexpr-source = fetchFromGitHub {
    owner = "codeplea";
    repo = "tinyexpr";
    rev = "9907207e5def0fabdb60c443517b0d9e9d521393";
    sha256 = "0xbpd09zvrk2ppm1qm1skk6p50mqr9mzjixv3s0biqq6jpabs88l";
    hash = "sha256-FCG91JUG47iAHrtH+WvKuIJyzZw6VBzqvWLm/RNod3U=";
  };
  fundamental-source = fetchFromGitHub {
    owner = "VCVRack";
    repo = "Fundamental";
    rev = "5ed79544161e0fa9a55faa7c0a5f299e828e12ab"; # tip of branch v2
    sha256 = "0c6qpigyr0ppvra20hcy1fdcmqa212jckb9wkx4f6fgdby7565wv";
    rev = "b453f192d22b1c951d71e8a73f28a37cd96a7b6c"; # tip of branch v2
    hash = "sha256-Wr5G2wgCMIduMqFdIJUtkWQEbvihte/WZb/qUWXGE04=";
  };
  vcv-rtaudio = stdenv.mkDerivation {
    pname = "vcv-rtaudio";
    version = "unstable-2020-01-30";
    version = "5.1.0-unstable-2020-01-30";

    src = fetchFromGitHub {
      owner = "VCVRack";
      repo = "rtaudio";
      rev = "ece277bd839603648c80c8a5f145678e13bc23f3"; # tip of master branch
      sha256 = "11gpl0ak757ilrq4fi0brj0chmlcr1hihc32yd7qza4fxjw2yx2v";
      hash = "sha256-W3QvuOyOqI9P82IwGGHIjFbIgMwLREdwpvGUMxWg94U=";
    };

    nativeBuildInputs = [
@@ -104,28 +107,33 @@ let
      pkg-config
    ];

    buildInputs = [
    buildInputs =
      [
        openssl
      ]
      ++ lib.optionals stdenv.hostPlatform.isLinux [
        alsa-lib
        libjack2
        libpulseaudio
    ];
      ]
      ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_13 ];

    cmakeFlags = [
      "-DRTAUDIO_API_ALSA=ON"
      "-DRTAUDIO_API_PULSE=ON"
      "-DRTAUDIO_API_JACK=ON"
      "-DRTAUDIO_API_CORE=OFF"
      (lib.cmakeBool "RTAUDIO_API_ALSA" stdenv.hostPlatform.isLinux)
      (lib.cmakeBool "RTAUDIO_API_PULSE" stdenv.hostPlatform.isLinux)
      (lib.cmakeBool "RTAUDIO_API_JACK" stdenv.hostPlatform.isLinux)
      (lib.cmakeBool "RTAUDIO_API_CORE" stdenv.hostPlatform.isDarwin)
    ];
  };
in
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "vcv-rack";
  version = "2.6.0";

  desktopItems = [
    (makeDesktopItem {
      type = "Application";
      name = pname;
      name = "vcv-rack";
      desktopName = "VCV Rack";
      genericName = "Eurorack simulator";
      comment = "Create music by patching together virtual synthesizer modules";
@@ -143,7 +151,7 @@ stdenv.mkDerivation rec {
  src = fetchFromGitHub {
    owner = "VCVRack";
    repo = "Rack";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-leI0wwhYiA8qktJFe6DuZjs6q5tMFQ4WFLD4Ivom5+E=";
  };

@@ -151,7 +159,8 @@ stdenv.mkDerivation rec {
    ./rack-minimize-vendoring.patch
  ];

  prePatch = ''
  prePatch =
    ''
      # As we can't use `make dep` to set up the dependencies (as explained
      # above), we do it here manually
      mkdir -p dep/include
@@ -177,44 +186,77 @@ stdenv.mkDerivation rec {
      # Build and dist the Fundamental plugins
      cp -r ${fundamental-source} plugins/Fundamental/
      chmod -R +rw plugins/Fundamental # will be used as build dir
    substituteInPlace plugin.mk --replace ":= all" ":= dist"
      substituteInPlace plugin.mk --replace-fail ":= all" ":= dist"
      substituteInPlace plugins/Fundamental/src/Logic.cpp \
      --replace \
        --replace-fail \
          "LightButton<VCVBezelBig, VCVBezelLightBig<WhiteLight>>" \
          "struct rack::componentlibrary::LightButton<VCVBezelBig, VCVBezelLightBig<WhiteLight>>"

    ''
    + lib.optionalString stdenv.hostPlatform.isLinux ''
      # Fix reference to zenity
      substituteInPlace dep/osdialog/osdialog_zenity.c \
      --replace 'zenityBin[] = "zenity"' 'zenityBin[] = "${zenity}/bin/zenity"'
        --replace-fail 'zenityBin[] = "zenity"' 'zenityBin[] = "${lib.getExe zenity}"'
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      # * Set VERSION from finalAttrs to avoid build using git to determine version
      # * Darwin needs to build the dist target, which builds the .app container,
      #   yet we want to exclude the documentation from dist target.
      # * Replace path to Fundamental module with path to produced build artifact
      #   to avoid downloading a pre-compiled version
      substituteInPlace Makefile \
        --replace-fail 'VERSION ?= $' 'VERSION ?= ${finalAttrs.version}#$' \
        --replace-fail 'DIST_HTML :=' '#DIST_HTML :=' \
        --replace-fail 'FUNDAMENTAL_FILENAME := Fundamental' 'FUNDAMENTAL_FILENAME := plugins/Fundamental/dist/Fundamental'
      # Skip codesigning
      substituteInPlace plugin.mk \
        --replace-fail '$(CODESIGN)' '#$(CODESIGN)'

      # To support macOS drag & drop a custom glfw patch is needed
      # (see https://github.com/glfw/glfw/pull/1579 for details).
      # Since the patch does not apply cleanly on the current glfw contained in nixpkgs
      # disable drag & drop functionality for the time being.
      substituteInPlace adapters/standalone.cpp \
        --replace-fail 'glfwGetOpenedFilenames()' 'NULL'
    '';

  nativeBuildInputs = [
    copyDesktopItems
    imagemagick
  nativeBuildInputs =
    [
      jq
    libicns
      makeWrapper
      pkg-config
    ]
    ++ lib.optionals stdenv.isLinux [
      copyDesktopItems
      libicns
      imagemagick
      wrapGAppsHook3
  ];
  buildInputs = [
    alsa-lib
    ]
    ++ lib.optionals stdenv.isDarwin [ rsync ];

  buildInputs =
    [
      curl
      ghc_filesystem
      glew
      glfw
    zenity
    gtk3-x11
      jansson
      libarchive
    libjack2
    libpulseaudio
      libsamplerate
      rtmidi
      speexdsp
      vcv-rtaudio
      zstd
  ];
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      alsa-lib
      gtk3-x11
      libjack2
      libpulseaudio
      zenity
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_13 ];

  enableParallelBuilding = true;

  makeFlags =
    lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
@@ -225,8 +267,18 @@ stdenv.mkDerivation rec {
      "plugins"
    ];

  installPhase = ''
  postBuild = lib.optionalString stdenv.hostPlatform.isDarwin ''
    # To be able to use enableParallelBuilding = true
    # the dist target needs run after the buildPhase as
    # it depends on the all and plugin targets.
    make "SED=sed -i" dist
  '';

  installPhase =
    ''
      runHook preInstall
    ''
    + lib.optionalString stdenv.hostPlatform.isLinux ''

      install -D -m755 -t $out/bin Rack
      install -D -m755 -t $out/lib libRack.so
@@ -245,16 +297,33 @@ stdenv.mkDerivation rec {
        fi
        install -Dm644 icon_"$size"x"$size"x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/Rack.png
      done;
    ''
    + lib.optionalString stdenv.isDarwin ''
      mkdir -p $out/{bin,Applications}
      mv dist/'VCV Rack ${lib.versions.major finalAttrs.version} Free.app' \
        $out/Applications

      # plugins/Fundamental/dist/Fundamental-*.vcvplugin
      cp -r res cacert.pem Core.json template.vcv LICENSE-GPLv3.txt \
        $out/Applications/'VCV Rack ${lib.versions.major finalAttrs.version} Free.app'/Contents/Resources
    ''
    + ''
      runHook postInstall
    '';

  dontWrapGApps = true;
  postFixup = ''
  postFixup =
    lib.optionalString stdenv.hostPlatform.isLinux ''
      # Wrap gApp and override the default global resource file directory
      wrapProgram $out/bin/Rack \
          "''${gappsWrapperArgs[@]}" \
          --add-flags "-s $out/share/vcv-rack"
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      makeWrapper \
        $out/Applications/'VCV Rack ${lib.versions.major finalAttrs.version} Free.app'/Contents/MacOS/Rack \
        $out/bin/${finalAttrs.meta.mainProgram} \
        --add-flags "-s $out/Applications/'VCV Rack ${lib.versions.major finalAttrs.version} Free.app'/Contents/Resources"
    '';

  meta = with lib; {
@@ -273,6 +342,6 @@ stdenv.mkDerivation rec {
      ddelabru
    ];
    mainProgram = "Rack";
    platforms = platforms.linux;
    platforms = platforms.linux ++ platforms.darwin;
  };
}
})
+8 −11
Original line number Diff line number Diff line
diff --git a/Makefile b/Makefile
index fc7c3af1..c3672c6a 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ ifdef ARCH_LIN
 
 	LDFLAGS += -Wl,--whole-archive
 	LDFLAGS += -static-libstdc++ -static-libgcc
diff --git i/Makefile w/Makefile
index 1d6accc6..f772883c 100644
--- i/Makefile
+++ w/Makefile
@@ -38 +38 @@ ifdef ARCH_LIN
-	LDFLAGS += dep/lib/libGLEW.a dep/lib/libglfw3.a dep/lib/libjansson.a dep/lib/libcurl.a dep/lib/libssl.a dep/lib/libcrypto.a dep/lib/libarchive.a dep/lib/libzstd.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a dep/lib/librtmidi.a dep/lib/librtaudio.a
+	LDFLAGS += -lGLEW -lglfw -ljansson -lcurl -lssl -lcrypto -larchive -lz -lspeexdsp -lsamplerate -lrtmidi -lrtaudio
 	LDFLAGS += -Wl,--no-whole-archive
 	LDFLAGS += -lpthread -lGL -ldl -lX11 -lasound -ljack -lpulse -lpulse-simple
 endif
@@ -53 +53 @@ ifdef ARCH_MAC
-	LDFLAGS += dep/lib/libGLEW.a dep/lib/libglfw3.a dep/lib/libjansson.a dep/lib/libcurl.a dep/lib/libssl.a dep/lib/libcrypto.a -Wl,-load_hidden,dep/lib/libarchive.a -Wl,-load_hidden,dep/lib/libzstd.a dep/lib/libspeexdsp.a dep/lib/libsamplerate.a -Wl,-load_hidden,dep/lib/librtmidi.a -Wl,-load_hidden,dep/lib/librtaudio.a
+	LDFLAGS += -lGLEW -lglfw -ljansson -lcurl -lssl -lcrypto -larchive -lz -lspeexdsp -lsamplerate -lrtmidi -lrtaudio