Hello World Application

Following this first part of the guide, you’ll create a trivial project for your bRANECell, invoke some of the basic commands, and get a sense of how the brane-builder manages a project.

Create a new Project #

Start IntelliJ IDEA and select Open Project Wizard, in the left-hand pane select Gradle.

Set up #

In the right-hand pane, IntelliJ IDEA automatically adds a project SDK (JDK) and a default option Java in the Additional Libraries and Frameworks area. You can deselect this option because we will compile C code in this project.

Create a new project

Click Next.

On the next page of the wizard, specify the ArtifactId that is the name of the project e.g. hello-world. You can use the default information in the version field. You don’t need to specify a GroupId unless you plan to deploy our project in some Maven repository.

Configure your new project part 1

Click Next.

On the next page of the wizard, you may leave the default options Create separate module per source set and Use default gradle wrapper (recommended) selected. You should also select the Use auto-import option to resolve all the changes made to the project automatically every time you refresh your project.

Configure your new project part 2

Click Next.

You already have specified a project’s name so you should not have to modify it here. You can change the location of your project if required.

Configure your new project part 3

Click Finish

Your New Project #

IntelliJ IDEA creates a project with the build.gradle file and some assets.

Generated New Project

There is no src folder with main and test subdirectories at that point. We will add them with some pieces of software code in the next section.

Generated New Project Folders

IntelliJ IDEA also creates a dedicated tool window with default tasks.

Default Tasks


You can run one of these tasks e.g. init (right click and run) and see the result on the console view.

5:02:31 PM: Executing task 'init'...

> Task :init SKIPPED
The build file 'build.gradle' already exists. Skipping build initialization.

BUILD SUCCESSFUL in 1s
5:02:33 PM: Task execution finished 'init'.

Write your first application #

There are a few build configuration files and auto-generated files that are a part of the standard project structure. Before you can start configuring your build, you need to add the source code of your own application(s).

Add source folders #

By convention, C projects in Gradle follows a contemporary layout. The brane-builder is composed of plugins for Gradle so we will follow the same layout. If you need to migrate a C project to Gradle you shall also use the same layout or you may configure the build.gradle file to use your own layout, see the Configure your Build section of this documentation or the advanced project tutorials.

The executable component is called main. By convention, Gradle will look in src/main/c for source files and non-exported header files. Create these folders in the IntelliJ IDEA.

Create Main folder

Add source files #

Let’s add the following C source code to the project.

#include<stdio.h>

int main(void)
{
   printf("Hello World!\n");
   return 0;
}


Create a new file and name it hello.c. Add the source code above and save.

Create New Source Files.

Update build configuration file #

Now, you need to inform Gradle about your source code. To do so, open the build.gradle build configuration file and add the following code.

apply plugin : 'c'

/*
 ** DSL Block that defines the executables
 */
model {
    // Optional: Remove a bug with IntelliJ EDA and Gradle using noinspection
    //noinspection GroovyAssignabilityCheck
    components {
        main (NativeExecutableSpec)
    }
}


This piece of code in a DSL block informs Gradle about the C code you just added. The executable component is called main. By convention, Gradle will look in src/main/c for source files and non-exported header files. For learning purpose, you are using the default C compiler that is part of the Gradle compilation infrastructure. You will use the brane-builder in the next section.

First Program Gradle Build.

Compile your Project and Run your application #

Try the default C compiler #

Go ahead and try to compile your first application. You can either run a compilation using the gradle view (double click on task assemble) or type gradle assemble in the console view.

Compile First program Command.


You should get a result similar to the one below.

5:51:12 PM: Executing task 'assemble'...

> Task :compileMainExecutableMainC
> Task :linkMainExecutable
> Task :mainExecutable
> Task :assemble

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed
5:51:12 PM: Task execution finished 'assemble'.
Compile First program.

Run your application locally #


You can run this application on your computer. To do so, go to build/exe/main, right click on main and select Open in a Terminal. Type ./main in the new terminal and you should get something similar to the result below.

|

$ ./main
Hello World!
Execute First program.



You should follow the same pattern every time you start developing a new project for a bRANECell. Alternatively, you can copy/pate existing projects or download projects from our open source repository. In the next section, you will use the brane-builder to compile your project for the computing units of a bRANECell.

What are your feelings
Updated on February 5, 2025