Skip to content

[Mac] Update cocoa for mac os 15#13

Merged
hughperkins merged 3 commits intomainfrom
hp/mac-fix-cocoa
Jun 9, 2025
Merged

[Mac] Update cocoa for mac os 15#13
hughperkins merged 3 commits intomainfrom
hp/mac-fix-cocoa

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

@hughperkins hughperkins commented Jun 4, 2025

Issue: #

See https://genesis-ai-company.slack.com/archives/C08UKDR6KGR/p1749077734526669?thread_ts=1749076147.261559&cid=C08UKDR6KGR for context

Pre-requisite for merging #5

Brief Summary

Update cocoa for mac os 15

copilot:summary

Walkthrough

copilot:walkthrough

Comment thread taichi/ui/gui/cocoa.cpp Outdated
#include <objc/objc.h>
#include <objc/runtime.h>

typedef const struct __CFAttributedString *CFAttributedStringRef;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this typedef required by the included header file below? Is there a better way to do this? Like making this typedef part of the included header file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These headers are all system headers, from OS X:

#include <ApplicationServices/ApplicationServices.h>

#include <CoreGraphics/CGBase.h>
#include <CoreGraphics/CGGeometry.h>
#include <AppKit/AppKit.h>

This is mine, that I create in this PR, but is dedicated to keycodes:

#include "taichi/ui/gui/cocoa_keycodes.h"

It is an interesting quesiton however, why we need this random spurious define 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked copilot, and it claims i should use:

#include <CoreFoundation/CFAttributedString.h>

Not sure if that is hallucinated though 🤔 I guess I can try the build 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that hreader from copilot totally didnt work for me:

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/CoreText.framework/Headers/CoreText.h:26:
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/CoreText.framework/Headers/CTFramesetter.h:85:5: error: unknown type name 'CFAttributedStringRef'; did you mean 'NSAttributedStringKey'?
    CFAttributedStringRef attrString ) CT_AVAILABLE(macos(10.5), ios(3.2), watchos(2.0), tvos(9.0));
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:22:20: note: 'NSAttributedStringKey' declared here
typedef NSString * NSAttributedStringKey NS_TYPED_EXTENSIBLE_ENUM;
                   ^
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.mm:1:
In file included from /Users/hugh/git/taichi/taichi/rhi/metal/metal_device.h:14:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/MetalKit.framework/Headers/MetalKit.h:8:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/MetalKit.framework/Headers/MTKView.h:11:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/AppKit.framework/Headers/AppKit.h:28:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSCollectionView.h:9:
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSViewController.h:260:39: error: unknown type name 'NSExtensionContext'; did you mean 'NSAnimationContext'?
@property (nullable, readonly,retain) NSExtensionContext *extensionContext API_AVAILABLE(macos(10.10));
                                      ^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSAnimationContext.h:19:12: note: 'NSAnimationContext' declared here
@interface NSAnimationContext : NSObject
           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
[13/427] Building CXX object taichi/rhi/common/CMakeFiles/common_rhi.dir/host_memory_pool.cpp.o
ninja: build stopped: subcommand failed.
Traceback (most recent call last):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually... that did work, I was building the wrong branch :) I'll make the change

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(updated)

Comment thread taichi/ui/gui/cocoa.cpp
constexpr int NSEventTypeKeyDown = 10;
constexpr int NSEventTypeKeyUp = 11;
constexpr int NSEventTypeFlagsChanged = 12;
constexpr int NSEventTypeScrollWheel = 22;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning the unused code.

Copy link
Copy Markdown

@yuhongyi yuhongyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, since the renderer will be gone at some point

@hughperkins
Copy link
Copy Markdown
Collaborator Author

Thanks!

@hughperkins
Copy link
Copy Markdown
Collaborator Author

(Note: we will probably remove the UI, but for now, merging this is the lowest hanging fruit for getting mac build working I feel. I don't want to spend time right now looking into how to remove the UI :) )

@duburcqa
Copy link
Copy Markdown
Contributor

duburcqa commented Jun 9, 2025

Do we have unit test to make sure the GUI is working fine ? Anyway not a big deal if the plan is to remove it.

@hughperkins
Copy link
Copy Markdown
Collaborator Author

Thanks!

@hughperkins hughperkins merged commit f31aacf into main Jun 9, 2025
13 checks passed
@hughperkins hughperkins deleted the hp/mac-fix-cocoa branch June 9, 2025 20:46
hughperkins added a commit that referenced this pull request Apr 26, 2026
Convert MatrixField.to_torch / to_numpy to thin calls into
_interop.get_zerocopy_torch / get_zerocopy_numpy.

Adds a single _matrix_view_shape() helper that returns (expected_shape,
as_vector); both to_torch and to_numpy now go through it instead of
duplicating the n / m / keep_dims branching (closes review #13, #14).

Same wins as the ScalarField migration:
- _zerocopy_cache as cached_property (closes review #17)
- automatic registration with pyquadrants.cache_holders (closes #18)
- copy=True now zerocopies + clones (closes #15, #16, #21)
- to_numpy(copy=False) goes through numpy.from_dlpack directly, no torch
  round-trip (closes #6)
- Apple Metal double-sync via the centralised helpers (closes #1, #22, #23)

The redundant reshape after zerocopy stays (DLPack returns the field's flat
n-d shape; numpy/torch users expect the matrix dims appended) but it's now
in one place per method instead of two.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants