Skip to content

Commit

Permalink
llvmPackages_{13,14}.lldb: fix build on x86 macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rrbutani committed Oct 9, 2022
1 parent d967f5d commit d20c869
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 17 additions & 2 deletions pkgs/development/compilers/llvm/13/lldb/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, Cocoa
, lit
, makeWrapper
, darwin
, enableManpages ? false
}:

Expand All @@ -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" ];

Expand Down Expand Up @@ -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 = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 16 additions & 2 deletions pkgs/development/compilers/llvm/14/lldb/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
, Cocoa
, lit
, makeWrapper
, darwin
, enableManpages ? false
, lua5_3
}:
Expand All @@ -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" ];

Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit d20c869

Please sign in to comment.