8

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

2
  • Which package are you building? Is it one you created yourself or something you cloned from GitHub? Commented Oct 11, 2017 at 16:32
  • One I created myself
    – Hugal31
    Commented Oct 11, 2017 at 16:32

1 Answer 1

16

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.

2
  • I have this file
    – Hugal31
    Commented Oct 11, 2017 at 16:46
  • 10
    Today you can also run swift test --generate-linuxmain to create & update the file.
    – zoul
    Commented Oct 24, 2018 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.