diff --git a/.devcontainer/linux/Dockerfile b/.devcontainer/linux/Dockerfile index 6fb29f14..96c250c1 100644 --- a/.devcontainer/linux/Dockerfile +++ b/.devcontainer/linux/Dockerfile @@ -28,6 +28,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ clang-format \ clang-tools \ libclang-rt-dev \ + libclang-rt-dev-wasm32 \ + lld \ llvm \ net-tools \ sudo \ @@ -42,10 +44,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean -y\ && update-alternatives --install /usr/bin/python python /usr/bin/python3 50 -# Install wasi-sdk -RUN mkdir /opt/wasi-sdk && \ - curl -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk-$WASI_SDK_VERSION.0-$(uname -m | sed s/aarch64/arm64/)-linux.tar.gz | \ - tar zxvf - --strip-components=1 -C /opt/wasi-sdk +# Install wasi-sysroot +RUN mkdir /opt/wasi-sysroot && \ + curl -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sysroot-$WASI_SDK_VERSION.0.tar.gz | \ + tar zxvf - --strip-components=1 -C /opt/wasi-sysroot FROM ocre-ci AS ocre-dev diff --git a/.devcontainer/zephyr/Dockerfile b/.devcontainer/zephyr/Dockerfile index 57c48bb7..ddc3434f 100644 --- a/.devcontainer/zephyr/Dockerfile +++ b/.devcontainer/zephyr/Dockerfile @@ -32,8 +32,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ gperf \ gpg \ jq \ + libclang-rt-dev-wasm32 \ libmagic1 \ libsdl2-dev \ + lld \ llvm \ make \ net-tools \ @@ -51,10 +53,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean -y\ && update-alternatives --install /usr/bin/python python /usr/bin/python3 50 -# Install wasi-sdk -RUN mkdir /opt/wasi-sdk && \ - curl -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sdk-$WASI_SDK_VERSION.0-$(uname -m | sed s/aarch64/arm64/)-linux.tar.gz | \ - tar zxvf - --strip-components=1 -C /opt/wasi-sdk +# Install wasi-sysroot +RUN mkdir /opt/wasi-sysroot && \ + curl -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VERSION/wasi-sysroot-$WASI_SDK_VERSION.0.tar.gz | \ + tar zxvf - --strip-components=1 -C /opt/wasi-sysroot RUN python -m venv /opt/zephyr-venv && \ . /opt/zephyr-venv/bin/activate && \ @@ -78,7 +80,9 @@ RUN . /opt/zephyr-venv/bin/activate && \ west sdk install --install-base /opt -t \ x86_64-zephyr-elf \ aarch64-zephyr-elf \ - arm-zephyr-eabi + arm-zephyr-eabi \ + riscv64-zephyr-elf + FROM base AS ocre-ci diff --git a/.github/workflows/hardware-bu585.yml b/.github/workflows/hardware-bu585.yml index f4aabbb9..85f74a66 100644 --- a/.github/workflows/hardware-bu585.yml +++ b/.github/workflows/hardware-bu585.yml @@ -44,26 +44,10 @@ jobs: strategy: matrix: sample: - - name: generic-hello-world - path: generic/hello-world - filename: hello-world.wasm - - name: generic-subscriber - path: generic/messaging/subscriber - filename: subscriber.wasm - - name: generic-publisher - path: generic/messaging/publisher - filename: publisher.wasm - - name: generic-blinky - path: generic/blinky - filename: blinky.wasm - - # Examples for future images to add - # - name: generic-filesystem-full - # path: generic/filesystem-full - # filename: filesystem-full.wasm - # - name: b_u585i-modbus-server - # path: board_specific/b_u585i_iot02a/modbus-server - # filename: modbus-server.wasm + - hello-world + - subscriber + - publisher + - blinky steps: - name: Cleanup workspace @@ -80,26 +64,17 @@ jobs: - name: Build WASM sample run: | - SAMPLE_DIR=$GITHUB_WORKSPACE/ocre-runtime/ocre-sdk/${{ matrix.sample.path }} - if [ ! -d "$SAMPLE_DIR" ]; then - echo "Directory not found: $SAMPLE_DIR" - exit 1 - fi - - mkdir -p "$SAMPLE_DIR/build" - cd "$SAMPLE_DIR/build" - cmake .. -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake - make - - env: - WASI_SDK_PATH: /opt/wasi-sdk + mkdir -p "ocre-runtime/ocre-sdk/build" + cd "ocre-runtime/ocre-sdk/build" + cmake .. + make ${{ matrix.sample }} # Saving files to the runner so avoid uploading .wasm files as artifacts individually, uploaded in separate step - name: Save .wasm artifact locally if: always() run: | - mkdir /var/ocre-ci-files/wasm/${{ matrix.sample.name }}/ - cp "ocre-runtime/ocre-sdk/${{ matrix.sample.path }}/build/${{ matrix.sample.filename }}" "/var/ocre-ci-files/wasm/${{ matrix.sample.name }}/${{ matrix.sample.filename }}" + mkdir /var/ocre-ci-files/wasm/${{ matrix.sample }}/ + cp "ocre-runtime/ocre-sdk/build/dist/${{ matrix.sample }}.wasm" "/var/ocre-ci-files/wasm/${{ matrix.sample }}/${{ matrix.sample }}.wasm" artifact-wasm-files: name: Artifact built .wasm Files diff --git a/cmake/state_information.cmake b/cmake/state_information.cmake index 8f5a3574..a1d91bf5 100644 --- a/cmake/state_information.cmake +++ b/cmake/state_information.cmake @@ -9,15 +9,18 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/var/lib/ocre/images) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/var/lib/ocre/containers) if(OCRE_SDK_PRELOADED_IMAGES) + string(REPLACE ".wasm" "" OCRE_SDK_PRELOADED_IMAGES_STR "${OCRE_SDK_PRELOADED_IMAGES}") + include(ExternalProject) ExternalProject_Add( OcreSampleContainers + SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../ocre-sdk" PREFIX "${CMAKE_CURRENT_BINARY_DIR}/OcreSampleContainers" + BUILD_COMMAND cmake --build . -- ${OCRE_SDK_PRELOADED_IMAGES_STR} BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/OcreSampleContainers/build" BUILD_ALWAYS TRUE INSTALL_COMMAND "" - SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../ocre-sdk" - CMAKE_ARGS "-DWAMR_ROOT_DIR=${CMAKE_CURRENT_LIST_DIR}/../wasm-micro-runtime" "-DCMAKE_VERBOSE_MAKEFILE=ON" + CMAKE_ARGS "-DWAMR_ROOT:STRING=${CMAKE_CURRENT_LIST_DIR}/../wasm-micro-runtime" ) endif() @@ -31,7 +34,7 @@ foreach(image IN ITEMS ${OCRE_SDK_PRELOADED_IMAGES}) message(STATUS "Adding sdk sample '${image}' to preloaded images") add_custom_target(${image} COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/OcreSampleContainers/build/${image} + ${CMAKE_CURRENT_BINARY_DIR}/OcreSampleContainers/build/dist/${image} ${CMAKE_CURRENT_BINARY_DIR}/var/lib/ocre/images/${image} DEPENDS OcreSampleContainers ) diff --git a/docs/Devcontainers.md b/docs/Devcontainers.md index f3170904..f1c4d0e5 100644 --- a/docs/Devcontainers.md +++ b/docs/Devcontainers.md @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 --> Devcontainers are tools that allows you to create and manage isolated development environments in containers. It provides a consistent and reproducible development environment across different machines and operating systems. -It is the fastest and easiest way to develop Ocre in Linux, macOS, and Windows. As it already comes preinstalled with all the necessary tools for building Ocre and the samples, including wasi-sdk. +It is the fastest and easiest way to develop Ocre in Linux, macOS, and Windows. As it already comes preinstalled with all the necessary tools for building Ocre and the samples, including wasi-sysroot. More information can be found at [the official Devcontainers documentation](https://containers.dev/). diff --git a/docs/NativeBuild.md b/docs/NativeBuild.md index 2fd69ec7..b4386df2 100644 --- a/docs/NativeBuild.md +++ b/docs/NativeBuild.md @@ -20,42 +20,26 @@ Our reference system is a Ubuntu 24.04 LTS, however these instructions can be ea ### Build Tools Ocre requires CMake and a C compiler such as GCC. For full testing support, we also use clang. -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: +If we are checking out the Ocre repository, we also need Git to clone Ocre Runtime, and Wget to unpack wasi-sysroot. Install all with: ```sh sudo apt update -y -sudo apt install -y apt install build-essential git cmake clang wget +sudo apt install -y apt install build-essential git cmake clang wget libclang-rt-dev-wasm32 lld ``` -### WASI-SDK +### WASI Sysroot -For building WASM/WASI containers (including the test containers), we need the WASI-SDK. -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`. +For building WASM/WASI containers (including the test containers), we need the WASI Sysroot. +Download wasi-sysroot from [the WASI SDK releases page](https://github.com/WebAssembly/wasi-sdk/releases) for your platform. The current recommended version is `wasi-sysroot-29`. -This is usually installed under `/opt/wasi-sdk` for default easy usage without the need to set environment variables. +This is usually installed under `/opt/wasi-sysroot` for default easy usage without the need to set environment variables. -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: +Download, unpack and install wasi-sysroot: ```sh -wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-29/wasi-sdk-29.0-amd_64-linux.tar.gz -tar -xzf wasi-sdk-29.0-amd_64-linux.tar.gz -sudo mv wasi-sdk-29.0-amd_64-linux /opt/wasi-sdk -``` - -You can check that WASI SDK is properly installed by checking the WASI clang version: - -```sh -/opt/wasi-sdk/bin/clang --version -``` - -The output should be similar to: - -``` -clang version 21.1.4-wasi-sdk (https://github.com/llvm/llvm-project 222fc11f2b8f25f6a0f4976272ef1bb7bf49521d) -Target: wasm32-unknown-wasi -Thread model: posix -InstalledDir: /opt/wasi-sdk/bin -Configuration file: /opt/wasi-sdk/bin/clang.cfg +wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-29/wasi-sysroot-29.0.tar.gz +tar -xzf wasi-sysroot-29.0.tar.gz +sudo mv wasi-sysroot-29.0 /opt/wasi-sysroot ``` ## Linux diff --git a/ocre-sdk b/ocre-sdk index 8201db68..584f19ee 160000 --- a/ocre-sdk +++ b/ocre-sdk @@ -1 +1 @@ -Subproject commit 8201db681e8b4ac447da62e612628923ebd7cdbc +Subproject commit 584f19ee058195b297caa570d9f5676fde326143 diff --git a/tests/system/posix/CMakeLists.txt b/tests/system/posix/CMakeLists.txt index 051540b0..71d11b23 100644 --- a/tests/system/posix/CMakeLists.txt +++ b/tests/system/posix/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_C_COMPILER /usr/bin/clang) list(APPEND OCRE_SDK_PRELOADED_IMAGES "return0.wasm" "return1.wasm" - "sleep_5_return_0.wasm" + "sleep5_return0.wasm" ) if (SANITIZER) diff --git a/tests/system/zephyr/container/CMakeLists.txt b/tests/system/zephyr/container/CMakeLists.txt index 4ae6e372..32204662 100644 --- a/tests/system/zephyr/container/CMakeLists.txt +++ b/tests/system/zephyr/container/CMakeLists.txt @@ -12,7 +12,7 @@ list(APPEND EXTRA_DTC_OVERLAY_FILE fstab.overlay) list(APPEND OCRE_SDK_PRELOADED_IMAGES "return0.wasm" "return1.wasm" - "sleep_5_return_0.wasm" + "sleep5_return0.wasm" "hello-world.wasm" "blinky.wasm" ) diff --git a/tests/system/zephyr/context/CMakeLists.txt b/tests/system/zephyr/context/CMakeLists.txt index 853590f5..fd40d5af 100644 --- a/tests/system/zephyr/context/CMakeLists.txt +++ b/tests/system/zephyr/context/CMakeLists.txt @@ -12,7 +12,7 @@ list(APPEND EXTRA_DTC_OVERLAY_FILE fstab.overlay) list(APPEND OCRE_SDK_PRELOADED_IMAGES "return0.wasm" "return1.wasm" - "sleep_5_return_0.wasm" + "sleep5_return0.wasm" "hello-world.wasm" "filesystem.wasm" "blinky.wasm"