From d20c8697ebdbecada47fac8ffb7e30d322fd517c Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Fri, 7 Oct 2022 20:06:12 -0500 Subject: [PATCH] llvmPackages_{13,14}.lldb: fix build on x86 macOS See: https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 --- .../lldb/cpu_subtype_arm64e_replacement.patch | 12 ++++++++++++ .../compilers/llvm/13/lldb/default.nix | 19 +++++++++++++++++-- .../lldb/cpu_subtype_arm64e_replacement.patch | 12 ++++++++++++ .../compilers/llvm/14/lldb/default.nix | 18 ++++++++++++++++-- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/compilers/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch create mode 100644 pkgs/development/compilers/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch diff --git a/pkgs/development/compilers/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch b/pkgs/development/compilers/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 000000000000..20d35c9f3ea9 --- /dev/null +++ b/pkgs/development/compilers/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/pkgs/development/compilers/llvm/13/lldb/default.nix b/pkgs/development/compilers/llvm/13/lldb/default.nix index d5a24753856a..d040e2b3975e 100644 --- a/pkgs/development/compilers/llvm/13/lldb/default.nix +++ b/pkgs/development/compilers/llvm/13/lldb/default.nix @@ -20,6 +20,7 @@ , Cocoa , lit , makeWrapper +, darwin , enableManpages ? false }: @@ -38,7 +39,22 @@ stdenv.mkDerivation (rec { substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir '') ./gnu-install-dirs.patch - ]; + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./cpu_subtype_arm64e_replacement.patch; + outputs = [ "out" "lib" "dev" ]; @@ -102,7 +118,6 @@ stdenv.mkDerivation (rec { ''; meta = llvm_meta // { - broken = stdenv.isDarwin; homepage = "https://lldb.llvm.org/"; description = "A next-generation high-performance debugger"; longDescription = '' diff --git a/pkgs/development/compilers/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch b/pkgs/development/compilers/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 000000000000..20d35c9f3ea9 --- /dev/null +++ b/pkgs/development/compilers/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/pkgs/development/compilers/llvm/14/lldb/default.nix b/pkgs/development/compilers/llvm/14/lldb/default.nix index dade90cc4668..2493dcde0c84 100644 --- a/pkgs/development/compilers/llvm/14/lldb/default.nix +++ b/pkgs/development/compilers/llvm/14/lldb/default.nix @@ -20,6 +20,7 @@ , Cocoa , lit , makeWrapper +, darwin , enableManpages ? false , lua5_3 }: @@ -44,7 +45,21 @@ stdenv.mkDerivation (rec { substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir '') ./gnu-install-dirs.patch - ]; + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./cpu_subtype_arm64e_replacement.patch; outputs = [ "out" "lib" "dev" ]; @@ -116,7 +131,6 @@ stdenv.mkDerivation (rec { larger LLVM Project, such as the Clang expression parser and LLVM disassembler. ''; - broken = stdenv.isDarwin; # error: use of undeclared identifier 'CPU_SUBTYPE_ARM64E' }; } // lib.optionalAttrs enableManpages { pname = "lldb-manpages";