progrium/darwinkit is a server-side project on GitHub with 5.4k stars, written primarily in Go. Native Mac APIs for Go. Previously known as MacDriver
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
[!IMPORTANT]
July 11, 2024: MacDriver is now DarwinKit! You can also now get high-quality example starter apps when you support the project as a sponsor.
DarwinKit lets you work with supported Apple frameworks and build native applications using Go. With XCode and Go 1.18+ installed, you can write this program in a main.go file:
go mod init helloworld
go get github.com/progrium/darwinkit@main
go run main.go
This may take a moment the first time, but once the window pops up you just made a macOS program without using XCode or Objective-C. Run go build to get an executable.
Although currently outside the scope of this project, if you wanted you could put this executable into an Application bundle. You could even add entitlements, then sign and notarize this bundle or executable to let others run it. It could theoretically even be put on the App Store. It could theoretically be put on an iOS, tvOS, or watchOS device, though you would have to use different platform specific frameworks.
Caveats
You still need to know or learn how Apple frameworks work, so you'll have to use Apple documentation and understand how to translate Objective-C example code to the equivalent Go with DarwinKit.
Your programs link against the actual Apple frameworks using cgo, so XCode needs to be installed for the framework headers.
You will be using two memory management systems. Framework objects are managed by Objective-C memory management, so be sure to read our docs on memory management with DarwinKit.
Exceptions in frameworks will segfault, giving you both an Objective-C stacktrace and a Go panic stacktrace. You will be debugging a hybrid Go and Objective-C program.
Goroutines that interact with GUI objects need to dispatch operations on the main thread otherwise it will segfault.
This is all tenable for simple programs, but these are the reasons we don't recommend large/complex programs using DarwinKit.
Examples
There are basic usage examples here in this repo, but there are higher-quality full utilities you can use as examples or starter templates when you sponsor.
How it works
Brief background on Objective-C
Ever since acquiring NeXT Computer in the 90s, Apple has used NeXTSTEP as the basis of their software stack, which is written in Objective-C. Unlike most systems languages with object orientation, Objective-C implements OOP as a runtime library. In fact, Objective-C is just C with the weird OOP specific syntax rewritten into C calls to libobjc, which is a normal C library implementing an object runtime. This runtime could be used to bring OOP to any language that can make calls to C code. It also lets you interact with objects and classes registered by other libraries, such as the Apple frameworks.
At the heart of DarwinKit is a package wrapping the Objective-C runtime using cgo and libffi. This is actually all you need to interact with Objective-C objects and classes, it'll just look like this:
These bindings are great, but we need to define them for every API we want to use. Presently,
Apple has around 200 frameworks of nearly 5000 classes with 77k combined methods and properties. Not to
mention all the constants, functions, structs, unions, and enums we need to work with those objects.
So DarwinKit generates its bindings. This is the hard part. Making sure the generation pipeline accurately produces usable bindings for all possible symbols is quite an arduous, iterative, manual process. Then since we're moving symbols that lived in a single namespace into Go packages, we have to manually decouple dependencies between them enough to avoid circular imports. If you want to help add frameworks, read our documentation on generation.
Objects are passed around as typed pointer values in Objective-C. When we receive an object from a method
call in Go, the objc package receives it as a raw pointer, which it first puts into an unsafe.Pointer. The
bindings for a class define a struct type that embeds an objc.Object struct, which contains a single
field to hold the unsafe.Pointer. So unless working with a primitive type, you're working with an unsafe.Pointer wrapped in an objc.Object wrapped in a struct type that has the methods for the class of the object of the pointer. Be sure to read our documentation on memory management.
If you have questions, feel free to ask in the discussion forums.
Thanks
This project was inspired by and originally based on packages written by Mikkel Krautz. The latest version is based on packages written by Dong Liu.
Notice
This project is not affiliated or supported by Apple.
No homepage URL was recorded for progrium/darwinkit in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on progrium/darwinkit?
The most recent commit recorded on progrium/darwinkit was 1.7 years ago, based on the GitHub push timestamp. The repository has 179 forks — one of the better signals of community interest.
Is progrium/darwinkit open source?
Yes — progrium/darwinkit ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/progrium/darwinkit.
What license does progrium/darwinkit use?
progrium/darwinkit is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is progrium/darwinkit associated with?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/progrium/darwinkit is the definitive source.
Read full README in the tab above.
Still deciding about darwinkit?
One click hands the question to an AI along with this page — see what it says about darwinkit.