-
Notifications
You must be signed in to change notification settings - Fork 3.4k
another attempt at getting Swift to build; works but I think it rebuild antlr lib each time. #3984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
…ld antlr lib each time. Signed-off-by: Terence Parr <[email protected]>
Runs stuff like:
|
Maybe @nesevis or @edigaryev can comment. This is much simpler than #3969 |
Signed-off-by: Terence Parr <[email protected]>
This was exactly what I was going to try next, so if this works 👍🏻 Great stuff, thank you for persisting with getting this working! |
Three hours on CI? 😬 I'm going to call time of death on this approach. So the next step would be to build a distributable It's the weekend here, so I'm not going to be able to look at this properly for a couple of days, but if you're happy to wait I will pull together the scripts to build an XCFramework from a Swift package, and we can try that. |
I'm fine with any Swift-related change as long as one will be able to link against ANTLR 4 statically and use it from Swift without forking this repository. Also, consider trying out the Cirrus CI for faster build times with Apple silicon. |
I totally agree. that's what I'm hoping to do here: build the runtime lib ONCE then reuse/bind into a test example. It's has to be a simple matter of command-line args. I'm enclosing a sample generated test rig example. Currently the antlr test infra runs this equivalent:
Unfortunately, this builds the runtime and dumps into current dir's .build rather than reusing the static lib. Must be a config or command line thing to fix easily. Hopefully you guys can use this as a base to more quickly figure it out. :) |
btw, I added a bug about the github actions not installing some targets properly #3988 |
Hi @tonyarnold had a chance to take a peek at this? If you can make example.zip reuse the existing library we are 99% there! |
Apologies for the delay in replying - I've been travelling for work. Okay, so the good news is that I have part of a workable solution. The bad news is that it is only part of a solution. If you (temporarily) force the Antlr4 library in // swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "Antlr4",
products: [
.library(name: "Antlr4", type: .static, targets: ["Antlr4"]),
],
// … Then execute the following commands to build an XCFramework (assuming that $ cd antlr4-checkout
$ swift build --configuration release
…
$ swift build --configuration release --show-bin-path
/Users/tonyarnold/Developer/Repositories/antlr4/.build/arm64-apple-macosx/release
$ xcodebuild -create-xcframework -library .build/arm64-apple-macosx/release/libAntlr4.a -allow-internal-distribution -output Antlr4.xcframework
$ cp Antlr4.xcframework ~/Downloads/example/ Now, update the example // swift-tools-version: 5.6
import PackageDescription
let package = Package(
name: "Test",
products: [
.executable(name: "Test", targets: ["Test"]),
],
targets: [
.executableTarget(
name: "Test",
dependencies: [
.target(name: "Antlr4")
],
path: ".",
exclude: [
"TLexer.tokens", "T.interp", "T.g4", "T.tokens", "TLexer.interp", "Antlr4.xcframework"
]
),
.binaryTarget(
name: "Antlr4",
path: "Antlr4.xcframework"
)
]
) You should now be able to open the Package.swift in Xcode 14.x, and it will build the binary correctly. Unfortunately,
|
It looks like what I was proposing will work once this fix makes it into a released version of Swift and Xcode: swiftlang/swift-package-manager#5724 |
Well this is kind of disappointing that Swift can't reuse an existing library. Finding it hard to believe but I have no idea. I guess we can only turn off the swift tests until set a time is Swift can run the test in a couple of minutes. |
I turned off the swift tests with 539ffaf |
It's not Swift, per se, it's Swift's package manager (SwiftPM). Swift itself supports what you're trying to do, it just gets extremely manual to get it to do it - we'd need to manually find and link all the object files ourselves (which is totally plausible, but outside of what I know how to do right now). Once SwiftPM has had that PR merged, this should work without a lot of fuss. |
ok. just surprising people have tolerated this lack of build reuse for years. seems odd. make xcode hides this? |
Heh @tonyarnold how about this one?