2011-02-10: Creating a Pod

The pod is both Fantom's module system and its method of distributing software. In this post, I want to look at the process of compiling the simple graphical application from my previous post into a pod.

The build environment

As your programs become more complex, there will be other elements within your projects, such as tests and perhaps native libraries etc. For such projects, the Fantom documentation recommends a standard directory structure for placing the different elements. Our example is very simple, so we only need to worry about a few parts. Assuming our program is called 'simple-app.fan', and the main class is called 'Main' (as in the previous post):

  1. create a directory 'simple-app'
  2. create a directory 'simple-app/fan'
  3. copy 'simple-app.fan' into 'simple-app/fan'
  4. use the instructions below to create the file 'build.fan' in the directory 'simple-app'

The build script

Our program is compiled using a build script, which is itself a piece of Fantom code. For our application, we place the following code in a file 'build.fan':

01: class Build : build::BuildPod
02: {
03:   new make()
04:   {
05:     podName = "simpleApp"
06:     summary = "simple GUI application"
07:     depends = ["sys 1.0", "fwt 1.0", "gfx 1.0"]
08:     srcDirs = [`fan/`]
09:   }
10: }

This program defines a new class,which inherits from BuildPod, with a constructor created as: new make () Lines 5-8 are the ones you need to change for your programs.

Line 5 gives the pod a name. This will also be a file name, so keep something simple, but distinctive.

Line 6 gives a description of the pod.

Line 7 provides a list of dependencies. The dependency on "sys" will be required in all Fantom programs. The dependencies on "fwt" and "gfx" are due to the libraries used in our program. Notice the version number for the dependencies.

Line 8 provides a list of the directories in which the compiler can find the source code. Note the backtick notation fan\ which converts the text into a URI, a place on the computer: providing the directories as strings will not work.

Compiling the pod

To compile the pod, you need to be in the directory 'simple-app'. Compiling is achieved by running the 'build.fan' script. If successful, you get a 'BUILD SUCCESS' message:

> fan build.fan 
compile [simpleApp] 
  Compile [simpleApp] 
    FindSourceFiles [1 files] 
    WritePod [file:../fantom-1.0.57/lib/fan/simpleApp.pod] 
BUILD SUCCESS [405ms]!

Once compiled, the pod will be found in the folder FANTOM_HOME/lib/fan/. The pod can be distributed to users, who merely need to copy the pod into their Fantom setup to use.

Running a pod

Once a pod has been compiled or downloaded and installed in the appropriate place, it can be run from the command line using:

> fan simpleApp

Another description of creating a pod is in the documentation.


Page from Peter's Scrapbook, output from a VimWiki on 2024-02-06.