mxcl / swift-sh

Easily script with third-party Swift dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example file does not compile

djtech42 opened this issue · comments

test.swift:

#!/usr/bin/swift sh

import PromiseKit  // @mxcl ~> 6.5

firstly {
    after(.seconds(2))
}.then {
    after(.milliseconds(500))
}.done {
    print("notice: two and a half seconds elapsed")
    exit(0)
}

RunLoop.main.run()

After running chmod +x test.swift, running it with ./test.swift results in these errors:

Compile Swift Module 'test' (1 sources)
/Users/dan/Library/Developer/swift-sh.cache/test/main.swift:10:5: error: use of unresolved identifier 'exit'
    exit(0)
    ^~~~
/Users/dan/Library/Developer/swift-sh.cache/test/main.swift:13:1: error: use of unresolved identifier 'RunLoop'
RunLoop.main.run()
^~~~~~~
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/dan/Library/Developer/swift-sh.cache/test/.build/debug.yaml test.exe output:
    Compile Swift Module 'test' (1 sources)
    /Users/dan/Library/Developer/swift-sh.cache/test/main.swift:10:5: error: use of unresolved identifier 'exit'
        exit(0)
        ^~~~
    /Users/dan/Library/Developer/swift-sh.cache/test/main.swift:13:1: error: use of unresolved identifier 'RunLoop'
    RunLoop.main.run()
    ^~~~~~~


Fatal error: Error raised at top level: (extension in Shwifty):__C.NSTask.ExecutionError(stdout: (extension in Shwifty):__C.NSTask.Output, stderr: (extension in Shwifty):__C.NSTask.Output, status: 1, arg0: "/usr/bin/swift", args: ["run"]): file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/core/ErrorType.swift, line 191
fish: './test.swift' terminated by signal SIGILL (Illegal instruction)

I fixed it by adding
import Foundation

fixed with #19