giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.39k forks source link

[macOS] error: unknown type name 'CFTimeInterval' #2362

Closed ryandesign closed 8 months ago

ryandesign commented 10 months ago

Summary

Description

After applying #2361 to fix #2360, the build still fails on OS X 10.11 with these errors:

In file included from psutil/arch/osx/sensors.c:15:
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:250:1: error: unknown type name 'CFTimeInterval'
CFTimeInterval IOPSGetTimeRemainingEstimate(void);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:270:1: error: unknown type name 'CFTypeRef'
CFTypeRef IOPSCopyPowerSourcesInfo(void);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:284:1: error: unknown type name 'CFArrayRef'
CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:284:37: error: unknown type name 'CFTypeRef'
CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
                                    ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:1: error: unknown type name 'CFDictionaryRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:47: error: unknown type name 'CFTypeRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
                                              ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:302:63: error: unknown type name 'CFTypeRef'
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);
                                                              ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:314:1: error: unknown type name 'CFStringRef'
CFStringRef     IOPSGetProvidingPowerSourceType(CFTypeRef snapshot);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:314:49: error: unknown type name 'CFTypeRef'
CFStringRef     IOPSGetProvidingPowerSourceType(CFTypeRef snapshot);
                                                ^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:339:1: error: unknown type name 'CFRunLoopSourceRef'
CFRunLoopSourceRef IOPSNotificationCreateRunLoopSource(IOPowerSourceCallbackType callback, void *context);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:359:1: error: unknown type name 'CFRunLoopSourceRef'
CFRunLoopSourceRef IOPSCreateLimitedPowerNotification(IOPowerSourceCallbackType callback, void *context) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
^
/System/Library/Frameworks/IOKit.framework/Headers/ps/IOPowerSources.h:372:1: error: unknown type name 'CFDictionaryRef'
CFDictionaryRef IOPSCopyExternalPowerAdapterDetails(void);
^
psutil/arch/osx/sensors.c:24:5: error: use of undeclared identifier 'CFTypeRef'
    CFTypeRef power_info = NULL;
    ^
psutil/arch/osx/sensors.c:25:5: error: use of undeclared identifier 'CFArrayRef'
    CFArrayRef power_sources_list = NULL;
    ^
psutil/arch/osx/sensors.c:26:5: error: use of undeclared identifier 'CFDictionaryRef'
    CFDictionaryRef power_sources_information = NULL;
    ^
psutil/arch/osx/sensors.c:27:5: error: use of undeclared identifier 'CFNumberRef'
    CFNumberRef capacity_ref = NULL;
    ^
psutil/arch/osx/sensors.c:28:5: error: use of undeclared identifier 'CFNumberRef'
    CFNumberRef time_to_empty_ref = NULL;
    ^
psutil/arch/osx/sensors.c:29:5: error: use of undeclared identifier 'CFStringRef'
    CFStringRef ps_state_ref = NULL;
    ^
psutil/arch/osx/sensors.c:34:5: error: use of undeclared identifier 'power_info'
    power_info = IOPSCopyPowerSourcesInfo();
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
XCode (https://developer.apple.com/xcode/) is not installed
error: command '/usr/bin/clang' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel

I was going to investigate but then had a power outage which interrupted my work so I'll just leave my notes here for now.

Those CF types are surely CoreFoundation types. I saw that you were including a couple individual headers from the IOKit framework, and evidently at least on this old version of macOS, those individual headers aren't including the CoreFoundation headers.

I suspect the solution may be not to include those individual headers but instead include only the top-level header, as is customary for frameworks. In other words, to use IOKit, only use #include <IOKit/IOKit.h>. Hopefully I can test later if that fixes it and if so I'll send a PR.

ryandesign commented 10 months ago

In other words, to use IOKit, only use #include <IOKit/IOKit.h>.

Well, forget that. Looks like IOKit is not one of those frameworks that uses an umbrella header; there is no IOKit/IOKit.h. And I grepped through the extant IOKit headers and none of them include the ones you're including, so it must be correct for you to include them directly.

The fix, then, is to include CoreFoundation/CoreFoundation.h directly. I've submitted a PR to do that.