[swift-users] Swift Package Manager and main.swift

Natthan Leong kar.joon at icloud.com
Sun May 1 19:23:45 CDT 2016


Hi there,

This is what happened as I was trying out the Swift Package Manager for another project similar to the one shown below:

~ $ mkdir example
~ $ cd example/
example $ touch Package.swift
example $ mkdir Sources
example $ vi Sources/Example.swift
example $ cat Sources/Example.swift
func printOther() {
  print("other")
}
example $ vi Sources/Main.swift
example $ cat Sources/Main.swift
print("Hello World")
printOther()

example $ swift build
Compile Swift Module 'example' (2 sources)
/PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
print("Hello World")
^
/PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
printOther()
^
/PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at the top level
print("Hello World")
^
/PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at the top level
printOther()
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /PATH-SWIFT/usr/bin/swift-build-tool -f /PATH/example/.build/debug.yaml

example $ mv Sources/Main.swift Sources/main.swift
example $ swift build
Compile Swift Module 'example' (2 sources)
Linking .build/debug/example
example $ .build/debug/example
Hello World
other
example $

I had to rename Main.swift to main.swift. Is there a design decision on why the filename for the main swift file has to be lowercase or is this a bug?

If it’s a design decision, why are directory names for source files allowed to have variations like Sources, Source, src and srcs as stated here <https://github.com/apple/swift-package-manager/blob/master/Documentation/SourceLayouts.md#other-rules> but not the main swift file?

I’d be ok if only Main.swift and main.swift are allowed since other files in the Sources directory are commonly UpperCamelCase due to the Type naming conventions e.g. example-package-playingcard/Sources <https://github.com/apple/example-package-playingcard/tree/master/Sources>.

Or maybe I’m just being pedantic?

p.s. even Package.swift is capitalized and not package.swift

$ swift --version
Swift version 3.0-dev (LLVM 752e1430fc, Clang 1e6cba3ce3, Swift 56052cfe61)
Target: x86_64-unknown-linux-gnu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160501/a3874fe7/attachment.html>


More information about the swift-users mailing list