summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers/firefox/common.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/applications/networking/browsers/firefox/common.nix')
-rw-r--r--pkgs/applications/networking/browsers/firefox/common.nix76
1 files changed, 60 insertions, 16 deletions
diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix
index 336cd2556611..b8a5faddc346 100644
--- a/pkgs/applications/networking/browsers/firefox/common.nix
+++ b/pkgs/applications/networking/browsers/firefox/common.nix
@@ -16,7 +16,7 @@
 
 ## optional libraries
 
-, alsaSupport ? true, alsaLib
+, alsaSupport ? stdenv.isLinux, alsaLib
 , pulseaudioSupport ? true, libpulseaudio
 , ffmpegSupport ? true, gstreamer, gst-plugins-base
 , gtk3Support ? !isTorBrowserLike, gtk2, gtk3, wrapGAppsHook
@@ -39,6 +39,10 @@
 , safeBrowsingSupport ? false
 , drmSupport ? false
 
+# macOS dependencies
+, xcbuild, CoreMedia, ExceptionHandling, Kerberos, AVFoundation, MediaToolbox
+, CoreLocation, Foundation, AddressBook, libobjc, cups, rsync
+
 ## other
 
 # As stated by Sylvestre Ledru (@sylvestre) on Nov 22, 2017 at
@@ -66,7 +70,14 @@ assert stdenv.cc.libc or null != null;
 
 let
   flag = tf: x: [(if tf then "--enable-${x}" else "--disable-${x}")];
-  gcc = if stdenv.cc.isGNU then stdenv.cc.cc else stdenv.cc.cc.gcc;
+
+  default-toolkit = if stdenv.isDarwin then "cairo-cocoa"
+                    else "cairo-gtk${if gtk3Support then "3" else "2"}";
+
+  execdir = if stdenv.isDarwin
+            then "/Applications/${browserName}.app/Contents/MacOS"
+            else "/bin";
+  browserName = if stdenv.isDarwin then "Firefox" else "firefox";
 in
 
 stdenv.mkDerivation (rec {
@@ -90,13 +101,27 @@ stdenv.mkDerivation (rec {
   ++ lib.optional  pulseaudioSupport libpulseaudio # only headers are needed
   ++ lib.optionals ffmpegSupport [ gstreamer gst-plugins-base ]
   ++ lib.optional  gtk3Support gtk3
-  ++ lib.optional  gssSupport kerberos;
-
-  NIX_CFLAGS_COMPILE = "-I${nspr.dev}/include/nspr -I${nss.dev}/include/nss -I${glib.dev}/include/gio-unix-2.0";
+  ++ lib.optional  gssSupport kerberos
+  ++ lib.optionals stdenv.isDarwin [ CoreMedia ExceptionHandling Kerberos
+                                     AVFoundation MediaToolbox CoreLocation
+                                     Foundation libobjc AddressBook cups ];
+
+  NIX_CFLAGS_COMPILE = [ "-I${nspr.dev}/include/nspr"
+                         "-I${nss.dev}/include/nss"
+                         "-I${glib.dev}/include/gio-unix-2.0" ]
+                      ++ lib.optional stdenv.isDarwin [
+                         "-isystem ${llvmPackages.libcxx}/include/c++/v1"
+                         "-DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_10" ];
+
+  postPatch = lib.optionalString stdenv.isDarwin ''
+    substituteInPlace js/src/jsmath.cpp --replace 'defined(HAVE___SINCOS)' 0
+  '';
 
   nativeBuildInputs =
     [ autoconf213 which gnused pkgconfig perl python2 cargo rustc ]
-    ++ lib.optional gtk3Support wrapGAppsHook ++ extraNativeBuildInputs;
+    ++ lib.optional gtk3Support wrapGAppsHook
+    ++ lib.optionals stdenv.isDarwin [ xcbuild rsync ]
+    ++ extraNativeBuildInputs;
 
   preConfigure = ''
     # remove distributed configuration files
@@ -110,11 +135,23 @@ stdenv.mkDerivation (rec {
   '' else ''
     make -f client.mk configure-files
     configureScript="$(realpath ./configure)"
-  '') + ''
-    cxxLib=$( echo -n ${gcc}/include/c++/* )
-    archLib=$cxxLib/$( ${gcc}/bin/gcc -dumpmachine )
-
-    test -f layout/style/ServoBindings.toml && sed -i -e '/"-DRUST_BINDGEN"/ a , "-cxx-isystem", "'$cxxLib'", "-isystem", "'$archLib'"' layout/style/ServoBindings.toml
+  '') + lib.optionalString (!isTorBrowserLike && lib.versionAtLeast version "53") ''
+    export MOZCONFIG=$(pwd)/mozconfig
+
+    # Set C flags for Rust's bindgen program. Unlike ordinary C
+    # compilation, bindgen does not invoke $CC directly. Instead it
+    # uses LLVM's libclang. To make sure all necessary flags are
+    # included we need to look in a few places.
+    # TODO: generalize this process for other use-cases.
+
+    BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-cflags) \
+      $(< ${stdenv.cc}/nix-support/cc-cflags) \
+      ${stdenv.cc.default_cxx_stdlib_compile} \
+      ${lib.optionalString stdenv.cc.isClang "-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"} \
+      ${lib.optionalString stdenv.cc.isGNU "-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc} -isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/$(cc -dumpmachine)"} \
+      $NIX_CFLAGS_COMPILE"
+
+    echo "ac_add_options BINDGEN_CFLAGS='$BINDGEN_CFLAGS'" >> $MOZCONFIG
   '' + lib.optionalString googleAPISupport ''
     # Google API key used by Chromium and Firefox.
     # Note: These are for NixOS/nixpkgs use ONLY. For your own distribution,
@@ -146,8 +183,9 @@ stdenv.mkDerivation (rec {
     "--enable-jemalloc"
     "--disable-maintenance-service"
     "--disable-gconf"
-    "--enable-default-toolkit=cairo-gtk${if gtk3Support then "3" else "2"}"
+    "--enable-default-toolkit=${default-toolkit}"
   ]
+  ++ lib.optional stdenv.isDarwin "--disable-xcode-checks"
   ++ lib.optional (lib.versionOlder version "61") "--enable-system-hunspell"
   ++ lib.optionals (lib.versionAtLeast version "56" && !stdenv.hostPlatform.isi686) [
     # on i686-linux: --with-libclang-path is not available in this configuration
@@ -223,7 +261,12 @@ stdenv.mkDerivation (rec {
     paxmark m dist/bin/xpcshell
   '';
 
-  postInstall = ''
+  installPhase = if stdenv.isDarwin then ''
+    mkdir -p $out/Applications
+    cp -LR dist/Firefox.app $out/Applications
+  '' else null;
+
+  postInstall = lib.optionalString stdenv.isLinux ''
     # For grsecurity kernels
     paxmark m $out/lib/firefox*/{firefox,firefox-bin,plugin-container}
 
@@ -234,7 +277,7 @@ stdenv.mkDerivation (rec {
     gappsWrapperArgs+=(--argv0 "$out/bin/.firefox-wrapped")
   '';
 
-  postFixup = ''
+  postFixup = lib.optionalString stdenv.isLinux ''
     # Fix notifications. LibXUL uses dlopen for this, unfortunately; see #18712.
     patchelf --set-rpath "${lib.getLib libnotify
       }/lib:$(patchelf --print-rpath "$out"/lib/firefox*/libxul.so)" \
@@ -244,11 +287,10 @@ stdenv.mkDerivation (rec {
   doInstallCheck = true;
   installCheckPhase = ''
     # Some basic testing
-    "$out/bin/firefox" --version
+    "$out${execdir}/${browserName}" --version
   '';
 
   passthru = {
-    browserName = "firefox";
     inherit version updateScript;
     isFirefox3Like = true;
     inherit isTorBrowserLike;
@@ -256,6 +298,8 @@ stdenv.mkDerivation (rec {
     inherit nspr;
     inherit ffmpegSupport;
     inherit gssSupport;
+    inherit execdir;
+    inherit browserName;
   } // lib.optionalAttrs gtk3Support { inherit gtk3; };
 
 } // overrides)