Soup Build Tutorial: My First Executable

Posted by mwasplund on August 30, 2020

Overview

This tutorial will show how to create the most simple "Hello World" Command Line Application using the Soup Build system.

Setup

Ensure you have the latest version of the Soup Build Application installed. If not, here is a How To Guide I put together for installing Soup on Windows.

Initialize A New Project

Create a folder to contain your new project and run the soup initialize command.

mkdir MyApp
cd MyApp
soup initialize

You will then be prompted to give the project a name and version. Feel free to accept the default values.

C:\Users\mwasp\source\repos>mkdir MyApp

C:\Users\mwasp\source\repos>cd MyApp

C:\Users\mwasp\source\repos\MyApp>soup initialize
The initialize utility will walk through the creation of the most basic Console recipe.

Name: (MyApp)

Version: (1.0.0)

Let's take a quick look into what was generated for us.

C:\Users\mwasp\source\repos\MyApp>dir
 Volume in drive C is OS
 Volume Serial Number is ****-****

 Directory of C:\Users\mwasp\source\repos\MyApp

08/30/2020  02:56 PM    <DIR>          .
08/30/2020  02:56 PM    <DIR>          ..
08/30/2020  02:56 PM                92 Main.cpp
08/30/2020  02:56 PM                84 Recipe.toml
               2 File(s)            176 bytes
               2 Dir(s)  22,821,453,824 bytes free

The initialize command will create two files for us:

Recipe.toml

The declarative Recipe file that tells the Soup Build System how to build our project. It uses the TOML configuration language that was created to be a more readible way to write configuration files written by humans. A Simple Executable only needs 4 properties to get up and running.

  • Name - The unique name for this project, which will be used as the package name if published to a public feed.
  • Version - The current version of the project. Currently only used to ensure compatiblity when published, but will be injected into result binary files in the future.
  • Type - Tells the build system that we want an executable, dynamic library or static library. Note: The default is a static library and can be left off in those projects.
  • Source - The list of source files to compile.
Name = "MyApp"
Version = "1.0.0"
Type = "Executable"
Source = [
"Main.cpp",
]

Main.cpp

The most basic C++ translation unit that has a single main method that prints "Hello World" using the standard out stream and exits.

#include <iostream>
int main()
{
	std::cout << "Hello World" << std::endl;
	return 0;
}

Build

Run the Soup Build command. Which will detect the default machine configuration and compile a debug version.

C:\Users\mwasp\source\repos\MyApp>soup build
1>Build 'MyApp'
1>MakeDir [C:/Users/mwasp/source/repos/MyApp/out/obj/MSVC/debug/win32/x64]
1>MakeDir [C:/Users/mwasp/source/repos/MyApp/out/bin/MSVC/debug/win32/x64]
1>Main.cpp
1>out/bin/MSVC/debug/win32/x64/MyApp.exe
1>Done
1.129877 seconds.

Run

Now that we have an executable we can run it! You can easily find the correct output binary folder and run the exe directly, or you can use the Soup Run command to resolve the provided configuration parameters for you and invoke the child executable.

C:\Users\mwasp\source\repos\MyApp>soup run
Hello World

Conclusion

A primary goal of the Soup Build system is to be as easy as possible to get up and running. This will allow the engineer to focus on the more important task of writing code and not fiddling with their builds!