Hello, Mana Build!
In this chapter, we'll explore learn to use mana's build system for managing projects.
Hello, Mana Build!
Mana Build is Mana's build system and package manager. Most Mana developers use this tool to manage their projects because it handles many tasks for you, such as building your code, downloading dependencies, and building those dependencies.
Creating a Project with Mana Build
Let's create a new project and see how it differs from our original "Hello, world!" project.
Navigate to your projects directory and run:
mana new hello_mana
cd hello_manaThe first command creates a new directory and project called hello_mana. Inside, Mana Build has generated two files and one directory:
hello_mana/
├── mana.toml
└── src/
└── main.mana
Open mana.toml in your text editor:
[package]
name = "hello_mana"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
[dependencies]This file is in TOML format. The [package] section contains metadata about your package. The [dependencies] section lists your project's dependencies.
Now open src/main.mana:
module main
fn main() {
println("Hello, world!")
}Mana Build generated a "Hello, world!" program for you! Notice the module main declaration at the top—every Mana file requires this. Also note that semicolons are optional in Mana and the main function doesn't require a return type.
Building and Running a Mana Build Project
From your hello_mana directory, build your project:
mana buildThis command creates an executable file in build/hello_mana (or build\hello_mana.exe on Windows).
Run the executable:
./build/hello_manaYou should see Hello, world! printed to the terminal.
Building for Release
When your project is ready for release, use mana build --release to compile with optimizations:
mana build --releaseThis creates an optimized executable. The optimizations make your code run faster, but compiling takes longer.
Build and Run in One Step
Use mana run to compile and run in one command:
mana runThis is convenient during development when you're rapidly iterating.
Project Structure Conventions
Mana Build expects your source files to live inside a src directory. The top-level project directory is for README files, license information, configuration files, and anything else not related to your code.
For a binary project, the main source file is src/main.mana. For a library, it's src/lib.mana.
A more complex project might look like:
my_project/
├── mana.toml
├── src/
│ ├── main.mana
│ ├── lib.mana
│ └── utils/
│ ├── math.mana
│ └── helpers.mana
├── tests/
│ └── integration_test.mana
├── examples/
│ └── demo.mana
└── build/
Mana Build Commands
Here's a quick reference of common commands:
| Command | Description |
|---|---|
mana new <name> | Create a new project |
mana build | Build the project |
mana build --release | Build with optimizations |
mana run | Build and run |
mana test | Run tests |
mana clean | Remove build artifacts |
mana check | Check for errors without building |
Recap
You've learned to:
- Create a new project with
mana new - Build a project with
mana build - Build and run with
mana run - Build for release with
mana build --release
Let's move on to building a more substantial program in Chapter 2.