Setting Up a New Project
To build an Atym container, you need to follow a structured project layout. This ensures your code is easy to manage, build, and deploy. In this section, we'll first cover the required files, explore best practices for organizing your project, and then provide you with further resources in creating container-based applications.
Required Files
Building an Atym container requires three main components:
- Application source code: Your C/C++ application code serves as the foundation of your container.
- Build configuration: A build configuration file (typically
CMakeLists.txt, but aMakefileor other build system can work too) to compile your code into a WebAssembly binary. - Build definition file: The build definition file tells Atym how to create your container using the WebAssembly binary you built.
Let's take a closer look at these, using the name your-project for our bare bones demo.
Application Code (main.c)
Your C/C++ application code serves as the foundation of your container. This is where you implement your application logic, utilizing container APIs and following the container lifecycle patterns.
Example:
#include <stdio.h>
int main()
{
printf("\nYour Project\n\n");
}
For a comprehensive guide on developing C/C++ applications for WebAssembly, including best practices, memory management, and platform-specific considerations, see the C & C++ Development for WebAssembly page in the Creating Container-Based Applications section.
Build Configuration
You need a build system configuration to compile your application into a WebAssembly binary that will be packaged into your Atym container. While CMake is the recommended approach due to its flexibility and direct support by the WASI SDK, you can also use standard Makefiles or other build systems of your choice.
Option 1: Using CMake (Recommended)
The following example shows a complete CMakeLists.txt file. Note that while the WASI SDK toolchain, project name, and executable target are required, the linker and compilation flags are optional.
Example:
# Required: Set minimum CMake version
cmake_minimum_required(VERSION 3.20.0)
# Required: Set the WASI SDK toolchain file
set(CMAKE_TOOLCHAIN_FILE /opt/wasi-sdk/share/cmake/wasi-sdk-p1.cmake)
# Required: Set the project name and create project
set(APPNAME your-project)
project(${APPNAME})
# Optional: Linker flags
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--strip-all -Wl,--allow-undefined")
# Optional: Compilation flags
add_compile_options(
-O0 -Wno-unknown-attributes
-O3
-Wall
-Wextra
-Wno-unused-parameter
)
# Required: Create the executable target
add_executable(${APPNAME}.wasm main.c)
Option 2: Using a Makefile
If you prefer using a traditional Makefile, you can configure it to use the WASI SDK compilers directly.
Example:
CC = /opt/wasi-sdk/bin/clang
CFLAGS = -O3 -Wall -Wextra
LDFLAGS = -Wl,--strip-all -Wl,--allow-undefined
TARGET = your-project.wasm
SOURCES = main.c
$(TARGET): $(SOURCES)
$(CC) $(CFLAGS) $(SOURCES) -o $(TARGET) $(LDFLAGS)
clean:
rm -f $(TARGET)
For detailed information about build system configuration, including optimization flags and advanced compilation options, see the Build System Optimization page in the Creating Container-Based Applications section.
Build Definition File (build.yaml)
The build definition file tells Atym how to create your container. It defines basic metadata like version and name, specifies which WebAssembly binaries to include, and configures runtime elements such as environment variables and permissions.
Example:
version: '1'
name: your-project
binaries:
- path: build/your-project.wasm
config:
permissions:
- networking
For detailed information about advanced configuration options see the Advanced Project Configuration page in the Creating Container-Based Applications section.
Project Organization
A well-organized project structure improves maintainability, collaboration, and build efficiency. While Atym does not enforce a strict directory layout, the following best practices can help streamline development:
Example Project Structure:
/your-project
│── /src # Application source code
│ ├── main.c # Entry point
│ ├── utils.c/.h # Utility functions (if needed)
│── /include # Header files
│── /build # Output directory for compiled binaries
│── CMakeLists.txt # Build configuration (or Makefile)
│── build.yaml # Atym build definition file
│── README.md # Project documentation
Learn More
This guide covers the basics of setting up a new project, but for a deep dive into how container creation works—including advanced configuration, API usage guide, best practices, and more—check out the Creating Container-Based Applications section.