https://github.com/tid-kijyun/Kanna could be replaced with something like https://github.com/drmohundro/SWXMLHash.
This would remove the need for https://github.com/tid-kijyun/SwiftClibxml2 and libxml2, and would make SwiftGen buildable with Swift PM without having to run brew install libxml2
From a quick look, it doesn’t seem to support XPaths, which we need for a few parsers (mainly IB parser)
Sent with GitHawk
Isn’t that just a sort of predicate, which could also be one by filtering elements in a more “swifty” way. From having a quick play it does the job. I’ve used that library before in other projects as well
Xpaths are predicates on massive steroid pills 😆 They are sort of like regexes, but for tree/node structures.
For example:
https://github.com/SwiftGen/SwiftGen/blob/feature/scene-segues/Sources/SwiftGenKit/Parsers/InterfaceBuilder/Scene.swift#L58
Allows me to match any segue nodes, with a connection node as parent, anywhere in the structure. That can be in the root of the document, or somewhere very deep inside the view hierarchy (needed for segues starting from a button for example).
Doing the same thing with SWXMLHash would probably involve some manually written code with a bunch of recursion, and would be a lot less clear.
In Kanna 4.0.3 they switched to the (new in) swift 4.2 SPM feature systemLibrary:
https://github.com/tid-kijyun/Kanna/pull/205
I don't know if that solves this issue, improves it a bit, or doesn't do anything...
The SwiftClibxml2 dependency they were using was doing the same thing so I dont think this really does anything, just moves it into the same package
Well the SwiftClibxml2 package was a normal package/target, now it's in Kanna as a systemLibrary target. That's why I'm curious if it maybe changes anything 🤷♂️
From a quick read of the docs, systemLibrary is indeed only for avoiding a separate repository for c-libs.
I did find this though, maybe we can do some pkgconfig stuff to use the system provided libxml (especially with PKG_CONFIG_PATH):
https://stackoverflow.com/questions/47096503/cleanly-handling-usr-local-with-swift-package-manager-and-libevent
FWIW, someone ping'd me on Slack the other day, as they tried to install SwiftGen via Mint, realised they had to install libxml2 manually before, but wanted to install it via MacPorts (instead of Homebrew) but then the Mint install still failed, not finding the headers (while bundle exec cli:install worked).
Not sure if they ended up trying further and managed to install it via Mint, but that confirms that this libxml2 issue is annoying (and maybe they can help us test installation problems if we decide to try updating to Kanna 4.0.3 and see if that systemLibrary thing changes anything or not?)
It's worth a try, that and the pkgconfig route.
For now mint installation of swiftgen is broken in XCode 10.2. It can't resolve Swift 3 dependency SwiftClibxml2.

Mint error can be found in this Travis build https://travis-ci.com/alphatroya/swift-project-template/builds/107019651 (line 839)
https://github.com/SwiftGen/SwiftGen/issues/580#issuecomment-479777954
I have same problem.
When using Kanna with SwiftPM (or Mint), it is inevitable for now to install libxml2 using brew.
I hope that the cross platform moudlemap problem is solved 🙏 Then we might be able to make it unnecessary to install it.
https://github.com/apple/swift-package-manager/blob/c85fc1b266b5b57580b50251de0a1b2f21d942cb/Documentation/Usage.md#cross-platform-module-maps
Removing libxml would be very helpful since this could allow us to use SwiftGen via SwiftPM without requiring the user to do additional steps
Hi guys and @djbe,
I have the same problem. SwiftGen isn't compilable via SPM or Mint. That means on the other hand that currently it's only usable with CocoaPods. Currently we plan to switch to SPM. Is there any suggestion to fix this issue? Any due date for an updated version of SwiftGen?
I haven’t tested it yet but this line in the Xcode 11.4 release notes seems to suggest this will be fixed in Swift 5.2
You can import libxml2, libxslt, and libexslt modules in both Swift package targets and regular Xcode targets, without any additional search paths
It sounds good. Did anyone test it? How it will works?
Thanks for the information. I have confirmed that it can be built using Xcode 11.4 beta. After migrating to Swift 5.2, we will no longer need to perform any additional steps.
That's very good news to hear! Thanks a lot @tid-kijyun for having taken the time to check this out!
@tid-kijyun
Can you publish a branch or feature PR?
@AF-cgi
You could use the develop branch of this library. Just change the toolchain to Xcode 11.4 beta and you can build.
@tid-kijyun
It's crazy. I can build SwiftGen 6.1.0 on one machine with macOS Catalina and Xcode 11.3.1. This machine use the bash as default shell and was updated from macOS before.
On another Mac with a brand new installation of macOS Catalina (with zsh as default shell) it works only with the beta of Xcode 11.4 and only if I used Mint. If I changed the command tool chain to Xcode 11.3.1, it's not compilable. Crazy.
@AF-cgi
The former may have installed libxml2 with brew. In that case, you can build. If you uninstall it with brew, you should not be able to build.
@tid-kijyun
You're totally right. On my Xcode 11.3.1 machine I has installed libxml2 via brew. But this was not an intention. 👍
Fixed in SwiftGen 6.2.0, should be available on CocoaPods (and other package managers) very soon!
Most helpful comment
Removing libxml would be very helpful since this could allow us to use SwiftGen via SwiftPM without requiring the user to do additional steps