Skip to content

macos support - #2

Open
takeiteasy wants to merge 1 commit into
fosskers:masterfrom
takeiteasy:master
Open

macos support#2
takeiteasy wants to merge 1 commit into
fosskers:masterfrom
takeiteasy:master

Conversation

@takeiteasy

Copy link
Copy Markdown

macos requires window operations run on the main thread. Added dependency for trivial-main-thread on macos and wrapped window functions inside `trivial-main-thread:call-on-main-thread' on macos (just progn on other systems) also added macos target to Makefile.

macos requires window operations run on the main thread. Added
dependency for trivial-main-thread on macos and wrapped window functions
inside `trivial-main-thread:call-on-main-thread' on macos (just progn on
other systems) also added macos target to Makefile
Comment thread raylib.asd
Comment on lines +2 to +3
:depends-on (:trivial-garbage
#+darwin :trivial-main-thread)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There should be a way to specify the dependency without an inline feature flag like this, such that vend can properly detect it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm unsure on that, could just have it as a dependency for all platforms? It's not a very big library and isn't platform dependant. Alternatively implement it (for just sbcl and ecl) inside the wrappers? Sorry, I'm still quite new to lisp. Do you have a suggestion?

@fosskers fosskers Jan 13, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Here's an example of how to do that:
https://github.com/fosskers/parcom/blob/master/parcom.asd#L48-L49

You would just need to specify the :darwin feature instead.

Here's an even more complex one: https://github.com/Shirakumo/harmony/blob/master/harmony.asd#L25-L34

Comment thread lisp/ecl.lisp
(defmacro with-main-thread (&body body)
"Execute BODY on the main thread on macOS, or directly on other platforms."
#+darwin
`(tmt:call-in-main-thread (lambda () ,@body))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Will this cause a lambda allocation upon every invocation?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did some testing and you're right it would. Both SBCL and ECL.

;; On macOS, window operations must run on the main thread.
(defmacro with-main-thread (&body body)
  "Execute BODY on the main thread on macOS, or directly on other platforms."
  #+darwin
  (let ((thunk (gensym "THUNK")))
    `(flet ((,thunk () ,@body))
       (declare (dynamic-extent #',thunk))
       (tmt:call-in-main-thread #',thunk)))
  #-darwin
  `(progn ,@body))

Using flet and dynamic-extend makes SBCL optimise out the allocation but it doesn't work in ECL, which stays the same either way. I don't know of a way around it for ECL personally.

@fosskers fosskers Jan 13, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Try some some additional optimize flags, like:

(declare (optimize (speed 3)))

within the quoted part of the macro.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey man sorry for the late response, I already tried that when I tested before and unfortunately it didn't change anything for ecl.

My thoughts are if the extra allocations aren't acceptable (which I totally get) you could close this merge and just include the changes to the makefile + the dylib loading? then just tell people that on mac window related code needs to be executed on the main thread and suggest trivial-main-thread. Then the user can just wrap the whole entry point in a call-in-main-thread call rather than each function being individually wrapped. I only did it this way as to try and hide it. That would also solve the dependency issue lol.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hm, yes I'd like to avoid those allocations.

and just include the changes to the makefile + the dylib loading?

I'm happy to follow this as well.

Then the user can just wrap the whole entry point in a call-in-main-thread

Since I don't have a mac, could you test this out for me and confirm that it works?

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.

2 participants