From f607a7851619a6efda5f7c57f0345018a3ea403c Mon Sep 17 00:00:00 2001 From: Andrew Pan Date: Tue, 29 Aug 2023 12:52:53 -0500 Subject: [PATCH] emacs-macport: build on LLVM 14 - Build on `apple_sdk_11_0` to support `aarch64-darwin` - Add frameworks required for building on newer SDKs - `Accelerate`, `UniformTypeIdentifiers` - Include header to work around `CF_NOESCAPE` issue circa LLVM 7.0 --- pkgs/applications/editors/emacs/default.nix | 6 ++-- pkgs/applications/editors/emacs/generic.nix | 13 ++++++-- .../editors/emacs/macport_noescape_noop.h | 31 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 +- 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 pkgs/applications/editors/emacs/macport_noescape_noop.h diff --git a/pkgs/applications/editors/emacs/default.nix b/pkgs/applications/editors/emacs/default.nix index a6914a43d413..81e4667c1fb0 100644 --- a/pkgs/applications/editors/emacs/default.nix +++ b/pkgs/applications/editors/emacs/default.nix @@ -8,9 +8,9 @@ lib.makeScope pkgs.newScope (self: inherit gconf; inherit (pkgs.darwin) sigtool; - inherit (pkgs.darwin.apple_sdk.frameworks) - AppKit Carbon Cocoa GSS ImageCaptureCore ImageIO IOKit OSAKit Quartz - QuartzCore WebKit; + inherit (pkgs.darwin.apple_sdk_11_0.frameworks) + Accelerate AppKit Carbon Cocoa GSS ImageCaptureCore ImageIO IOKit OSAKit + Quartz QuartzCore UniformTypeIdentifiers WebKit; }; in { sources = import ./sources.nix { diff --git a/pkgs/applications/editors/emacs/generic.nix b/pkgs/applications/editors/emacs/generic.nix index 9da821de3f54..494355b4353e 100644 --- a/pkgs/applications/editors/emacs/generic.nix +++ b/pkgs/applications/editors/emacs/generic.nix @@ -42,7 +42,7 @@ , libtiff , libwebp , libxml2 -, llvmPackages_6 +, llvmPackages_14 , m17n_lib , makeWrapper , motif @@ -99,6 +99,7 @@ else "lucid") # macOS dependencies for NS and macPort +, Accelerate , AppKit , Carbon , Cocoa @@ -109,6 +110,7 @@ , OSAKit , Quartz , QuartzCore +, UniformTypeIdentifiers , WebKit }: @@ -135,7 +137,7 @@ let ]; inherit (if variant == "macport" - then llvmPackages_6.stdenv + then llvmPackages_14.stdenv else stdenv) mkDerivation; in mkDerivation (finalAttrs: (lib.optionalAttrs withNativeCompilation { @@ -287,6 +289,7 @@ mkDerivation (finalAttrs: (lib.optionalAttrs withNativeCompilation { GSS ImageIO ] ++ lib.optionals (variant == "macport") [ + Accelerate AppKit Carbon Cocoa @@ -294,6 +297,7 @@ mkDerivation (finalAttrs: (lib.optionalAttrs withNativeCompilation { OSAKit Quartz QuartzCore + UniformTypeIdentifiers WebKit # TODO are these optional? GSS @@ -337,6 +341,11 @@ mkDerivation (finalAttrs: (lib.optionalAttrs withNativeCompilation { ++ lib.optional withXwidgets "--with-xwidgets" ; + # Fixes intermittent segfaults when compiled with LLVM >= 7.0. + # See https://github.com/NixOS/nixpkgs/issues/127902 + env.NIX_CFLAGS_COMPILE = lib.optionalString (variant == "macport") + "-include ${./macport_noescape_noop.h}"; + enableParallelBuilding = true; installTargets = [ "tags" "install" ]; diff --git a/pkgs/applications/editors/emacs/macport_noescape_noop.h b/pkgs/applications/editors/emacs/macport_noescape_noop.h new file mode 100644 index 000000000000..64c65bd90f88 --- /dev/null +++ b/pkgs/applications/editors/emacs/macport_noescape_noop.h @@ -0,0 +1,31 @@ +#ifndef NOESCAPE_NOOP_H_ +#define NOESCAPE_NOOP_H_ + +// First, do some work to get definitions for *_WIDTH. Normally, Emacs would +// have these defined by headers in-tree, but clang's headers clash with those. +// Due to how include paths work, we have to include clang headers if we want to +// mess with CoreFoundation definitions. +#pragma push_macro("__STDC_VERSION__") +// Make the preprocessor think that we're on C2x. The macros we want are gated +// on it. +#undef __STDC_VERSION__ +#define __STDC_VERSION__ 202000L +// Include limits.h first, as stdint.h includes it. +#include + +// XX: clang's stdint.h is shy and won't give us its defs unless it thinks it's +// in freestanding mode. +#undef __STDC_HOSTED__ +#include +#define __STDC_HOSTED__ 1 + +#pragma pop_macro("__STDC_VERSION__") + +// Now, pull in the header that defines CF_NOESCAPE. +#include + +// Redefine CF_NOESCAPE as empty. +#undef CF_NOESCAPE +#define CF_NOESCAPE + +#endif // NOESCAPE_NOOP_H_ diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0d224d4d18d8..fd090b3b28f3 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -31492,7 +31492,7 @@ with pkgs; em = callPackage ../applications/editors/em { }; - inherit (recurseIntoAttrs (callPackage ../applications/editors/emacs { })) + inherit (recurseIntoAttrs (darwin.apple_sdk_11_0.callPackage ../applications/editors/emacs { })) emacs28 emacs28-gtk2 emacs28-gtk3