|
| 1 | +# Set up host to build Ocre |
| 2 | + |
| 3 | +This document provides instructions on how to build the Ocre Runtime from source without requiring Docker. These instructions also work inside a docker container, however this is provided as a reference for whose who need the development enviroment available in the host. |
| 4 | + |
| 5 | +For quick instructions on how to build the Ocre Runtime (potentially using docker), see [Devcontainers](Devcontainers.md), [Getting Started with Linux](GetStartedLinux.md) and [Getting Started with Zephyr](GetStartedZephyr.md) documents. |
| 6 | + |
| 7 | +We detail the procedure to set up the host system prerequisites, and build a native Linux version of the Ocre Runtime, and also how to set up a Zephyr development environment locally, which includes Ocre. |
| 8 | + |
| 9 | +## General Prerequisites |
| 10 | + |
| 11 | +These prerequisites are necessary both for Linux and Zephyr build. |
| 12 | + |
| 13 | +Our reference system is a Ubuntu 24.04 LTS, however these instructions can be easily adapted for other Linux distributions, as well as other POSIX based operating systems. |
| 14 | + |
| 15 | +### Build Tools |
| 16 | + |
| 17 | +Ocre requires CMake and a C compiler such as GCC. For full testing support, we also use clang. |
| 18 | +If we are checking out the Ocre repository, we also need Git to clone Ocre Runtime, and Wget to unpack the WASI-SDK. Install all with: |
| 19 | + |
| 20 | +```sh |
| 21 | +sudo apt update -y |
| 22 | +sudo apt install -y apt install build-essential git cmake clang wget |
| 23 | +``` |
| 24 | + |
| 25 | +### WASI-SDK |
| 26 | + |
| 27 | +For building WASM/WASI containers (including the test containers), we need the WASI-SDK. |
| 28 | +Download a WASI-P1 compatible WASI-SDK from [the WASI SDK releases page](https://github.com/WebAssembly/wasi-sdk/releases) for your platform. The current recommended version is `wasi-sdk-29`. |
| 29 | + |
| 30 | +This is usually installed under `/opt/wasi-sdk` for default easy usage without the need to set environment variables. |
| 31 | + |
| 32 | +Download, unpack and install WASI SDK. Note that these are Linux binary packages. Make sure you replace `amd_64` with `arm64` in case your host is ARM64 based: |
| 33 | + |
| 34 | +```sh |
| 35 | +wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-29/wasi-sdk-29.0-amd_64-linux.tar.gz |
| 36 | +tar -xzf wasi-sdk-29.0-amd_64-linux.tar.gz |
| 37 | +sudo wasi-sdk-29.0-amd_64-linux /opt/wasi-sdk |
| 38 | +``` |
| 39 | + |
| 40 | +You can check that WASI SDK is properly installed by checking the WASI clang version: |
| 41 | + |
| 42 | +```sh |
| 43 | +/opt/wasi-sdk/bin/clang --version |
| 44 | +``` |
| 45 | + |
| 46 | +The output should be similar to: |
| 47 | + |
| 48 | +``` |
| 49 | +clang version 21.1.4-wasi-sdk (https://github.com/llvm/llvm-project 222fc11f2b8f25f6a0f4976272ef1bb7bf49521d) |
| 50 | +Target: wasm32-unknown-wasi |
| 51 | +Thread model: posix |
| 52 | +InstalledDir: /opt/wasi-sdk/bin |
| 53 | +Configuration file: /opt/wasi-sdk/bin/clang.cfg |
| 54 | +``` |
| 55 | + |
| 56 | +## Linux |
| 57 | + |
| 58 | +This environment is enough to build and run Ocre on Linux: |
| 59 | + |
| 60 | +```sh |
| 61 | +git clone --recursive https://github.com/project-ocre/ocre-runtime.git |
| 62 | +cd ocre-runtime |
| 63 | +mkdir build |
| 64 | +cd build |
| 65 | +cmake .. |
| 66 | +make |
| 67 | +``` |
| 68 | + |
| 69 | +Check the [Getting Started with Linux](GetStartedLinux.md) and [Linux Build System](BuildSystemLinux.md) for more information. |
| 70 | + |
| 71 | +## Zephyr |
| 72 | + |
| 73 | +As stated in the Zephyr [Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html), |
| 74 | +Zephyr requires additional tools such as `python3` among others. We can install them with: |
| 75 | + |
| 76 | +```sh |
| 77 | +sudo apt update -y |
| 78 | +sudo apt install --no-install-recommends git cmake ninja-build gperf \ |
| 79 | + ccache dfu-util device-tree-compiler wget python3-dev python3-venv python3-tk \ |
| 80 | + xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 |
| 81 | +``` |
| 82 | + |
| 83 | +Then we need `west`. This is usually done in the venv because we might need some more Python packages and we do not want to tamper with the system Python packages (which are outside of the virtual environment). |
| 84 | + |
| 85 | +Create a virtual environment: |
| 86 | + |
| 87 | +```sh |
| 88 | +python3 -m venv .venv |
| 89 | +source venv/bin/activate |
| 90 | +``` |
| 91 | + |
| 92 | +Install `west`: |
| 93 | + |
| 94 | +```sh |
| 95 | +pip install west |
| 96 | +``` |
| 97 | + |
| 98 | +Now you can proceed to build your Zephyr application as detailed in Zephyr's [Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html). |
| 99 | + |
| 100 | +Alternatively you can check [Get Started with Zephyr](GetStartedZephyr.md) and [Custom Zephyr Application](CustomZephyrApplication.md) to build a custom application or the Ocre samples. |
| 101 | + |
| 102 | +You can also check the [Zephyr Build System](BuildSystemZephyr.md) for more information about the build configuration. |
0 commit comments