Skip to content

Commit

Permalink
feat: Add "Hello, world!" C-based example
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung committed Oct 23, 2023
1 parent 88e488b commit 79f3efb
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kraft pkg ls --apps --update

| | Example |
|-|:-|
| ![](https://raw.githubusercontent.com/unikraft/catalog/main/icons/c.svg) | [Simple "Hello, world!" application written in C](https://github.com/unikraft/catalog/tree/main/examples/helloworld-c) |
| ![](https://raw.githubusercontent.com/unikraft/catalog/main/icons/python3.svg) | [Simple Flask 3.0 HTTP Web Server](https://github.com/unikraft/catalog/tree/main/examples/http-python3.10-flask3.0) |
| ![](https://raw.githubusercontent.com/unikraft/catalog/main/icons/python3.svg) | [Simple Python 3.10 HTTP Web Server with `http.server.HTTPServer`](https://github.com/unikraft/catalog/tree/main/examples/http-python3.10) |

Expand Down
13 changes: 13 additions & 0 deletions examples/helloworld-c/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spec: v0.6

name: helloworld

unikraft: stable

targets:
- fc/arm64
- fc/x86_64
- linuxu/x86_64
- qemu/arm64
- qemu/x86_64
- xen/x86_64
3 changes: 3 additions & 0 deletions examples/helloworld-c/Makefile.uk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(eval $(call addlib,apphelloworld))

APPHELLOWORLD_SRCS-y += $(APPHELLOWORLD_BASE)/main.c
27 changes: 27 additions & 0 deletions examples/helloworld-c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Simple "Hello, world!" C Program on Unikraft

This directory contains an example C-based "Hello, world!" example.

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli).

Then, clone this repository and cd into this directory.
You can then build the project with:

```
kraft build
```

In the above command, `kraft build` will prompt you with the target you wish to compile for.
If you are unsure, select `qemu/` and your host's architecture, e.g. `qemu/x86_64`.

Once built, you can execute the unikernel via:

```
kraft run
```

## Learn more

- [How to build unikernels](https://unikraft.org/docs/cli/building)
- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [The `Kraftfile` specification](https://unikraft.org/docs/cli/reference/kraftfile/latest)
7 changes: 7 additions & 0 deletions examples/helloworld-c/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main(int argc, char *argv[]) {
printf("Hello, world!\n");

return 0;
}
6 changes: 6 additions & 0 deletions icons/c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 79f3efb

Please sign in to comment.