Example

A project example with 2 dependancy modules showing the pre-compiler build command output.

Project File - hello world.swift
// name:helloworld
// type:project
// include:numbers.swift
// include:date.swift

print("Hello, swift world")  
printNumbers()  
printToday()  
Module File - numbers.swift
// name:numbers
// type:module

import Glibc

func printNumbers() {  
   for i in 1...10 {
      usleep(500000)
      print(i * i * i * i * i)
   }
}
Module File - date.swift
// name:date
// type:module

import Foundation     

func printToday(){  
   let date = Date()
   let dateFormatter = DateFormatter()

   dateFormatter.dateStyle = .full
   dateFormatter.timeStyle = .full

   let dateString = dateFormatter.string(from: date as Date)

   print("FullStyle Date Format = \(dateString)") 

}

If we try to run this project using swiftc it will fail!

$ swiftc helloworld.swift

This because we haven't referenced our dependancy modules.

error: use of unresolved identifier 'printNumbers'  
printNumbers()  
error: use of unresolved identifier 'printToday'  
printToday()  

So lets try again referencing the correct files.

$ swiftc helloworld.swift ../swiftModules/numbers.swift ../swiftModules/date.swift

Another fail! What is going on? Now we have different errors, even our simple print statement won't work.

expressions are not allowed at the top level  
print("Hello, swifty world!")  
error: expressions are not allowed at the top level  
printNumbers()  
error: expressions are not allowed at the top level  
printToday()  

This is because as soon as we add dependancies swiftc is looking for a main.swift, we don't have one and swiftc thinks our helloworld.swift is just another dependancy.

We have to rename helloworld.swift to main.swift and then we can build with no errors.

$ swiftc main.swift ../swiftModules/numbers.swift ../swiftModules/date.swift

This will build an app called main.

if we add -o helloworld.app to the command we will get our correctly named app.

$ swiftc -o helloworld.app main.swift ../swiftModules/numbers.swift ../swiftModules/date.swift

Wouldn't it be great if we could just select "helloworld.swift", tap a run button, or type a simple command like ...

$ swift-lite-build helloworld.swift

Well now you can!

The Swift-Lite pre-compiler scans your project file for dependancies and constructs a custom build command to create your app.

// type:project
// name:helloworld
// include:numbers.swift
// include:date.swift

The project file identifies itself as a project and lists the dependancies to include using meta-data tags.

// type:module
// name:numbers

The module file identifies itself as module using meta-tags.

$ swift-lite-build helloworld.swift

An example of a build command using Swift-Lite.

This build command will do the following:-
1. Create a tmp build directory
2. Copy the project.swift file to the tmp build directory as main.swift
3. Create a custom swiftc build command
4. Build the app and output as the same name as the project
5. Remove tmp build directory and contents