rhx/SwiftGLib

Example Usage?

xanderdunn opened this issue · 2 comments

I am investigating whether SwiftGLib would be appropriate for writing a Swift wrapper library of the Apache Arrow GLib library. I don't see any example usage in the docs or in the tests to help me figure out how this might be done. Are there any example projects that are using SwiftGLib that might be used as reference?

rhx commented

What you are after is probably less some example usage for SwiftGLib, but instructions on how to use gir2swift to wrap libraries (such as Apache Arrow GLib). While there is no tutorial, there are plenty of examples, such as SwiftGLib, SwiftCairo, etc.

In essence, what you need is the following:
1. Some basic understanding of how the Swift Package Manager works
2. Enough knowledge of how to use pkg-config (but I would expect that libraries such as Apache GLib would come with the necessary instructions)
3. Knowledge of the tools you want to use to create the necessary scripts. SwiftGLib and the like use bash as well as sed and awk for some post-processing. You could use other tools and languages such as CMake and Python, but I wanted to avoid even more pre-requisites.
4. An installation of your favourite library (e.g. Apache Arrow GLib) with the corresponding .gir files (gobject-introspection XML files)

Feel free to use one of the projects as an example. If Apache Arrow GLib builds directly on glib or glib-object then SwiftAtk might be a good starting point, if there is no dependency, then you could use SwiftGLib as an example. Both combine a System Library target for the underlying C package as well a high level Swift target with the (mostly) generated code.

So a good starting point would be to copy the Package.swift and *.sh and use them as a starting point. Modify the Package.swift and config.sh to suit your needs. The module files (e.g. Atk-1.0.preamble etc.) contain the boilerplate that gir2swift uses to make your project work, so you would need to adapt these as well (sorry no detailed instructions here, but I’m happy to answer questions if you are not sure what they are doing). Start with empty .sed and .awk files and only add to them any modifications to the generated that you need to make it compile.

Hope this gets you started, let me know if you have any questions!

@rhx Excellent, thank you very much! This is plenty for me to get started. I will close this issue and may be back with additional questions along the way.