Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build error: missingLinuxMain

Tags:

linux

swift

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

like image 842
Hugal31 Avatar asked Oct 11 '17 16:10

Hugal31


1 Answers

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.

like image 70
Ole Begemann Avatar answered Sep 29 '22 21:09

Ole Begemann