I have a bug when I try to build a swift package on linux :
> swift build -v
lsb_release -r
which clang
/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/4 -lPackageDescription -swift-version 4 -I /opt/swift/usr/lib/swift/pm/4 -sdk / /home/me/SwiftProject/Package.swift -fileno 5
/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/siesta-3156441904511450749/Package.swift -fileno 5
/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/SwiftyJSON-6376406316629445150/Package.swift -fileno 5
error: missingLinuxMain
I have no error when I run the last command:
/opt/swift/usr/bin/swiftc --driver-mode=swift -L /opt/swift/usr/lib/swift/pm/3 -lPackageDescription -swift-version 3 -I /opt/swift/usr/lib/swift/pm/3 -sdk / /home/me/SwiftProject/.build/checkouts/SwiftyJSON-6376406316629445150/Package.swift -fileno 5
I have a file LinuxMain.swift in the Test directory:
Tests
├── ProjectTests
│ ├── SomeTests.swift
└── LinuxMain.swift
LinuxMain.swift:
import XCTest
@testable import ProjectTests
XCTMain([
testCase(SomeTests.allTests),
])
I use swift 4.0 on ubuntu 17.04
SwiftPM uses a file named LinuxMain.swift
(located in the root directory of your test targets, usually Tests/LinuxMain.swift
) to find the unit tests on Linux. (On Apple platforms it uses the Objective-C runtime for this, but that's not available on Linux.)
It looks like your build fails because SwiftPM can't find the file.
If you haven't got a LinuxMain.swift
file, you should create one. The easiest way to see how it should be formatted is probably to run swift package init
in an empty directory and check out the expected directory and file structure.
The file should look something like this, but adapted for your package (I copied this one from here):
import XCTest
@testable import MarathonTests
XCTMain([
testCase(MarathonTests.allTests)
])
Each of your XCTestCase
subclasses also needs an allTests
property. Again, the default directory structure should give you an idea how it should look.
You might also find this article I wrote a few months ago interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With