Document
WAMR on GitHubWAMR Blogs
  • WAMR Document Home Page
  • Basics
    • Introduction
      • WebAssembly
      • WAMR Project
      • Security Feature
    • Getting Started
      • Host Environment Preparation
      • Hello-world Program On Host
      • Docker Environment Preparation
      • Hello-world Program On Docker
      • Build And Run WASM Application
        • More Tools To Create WASM Application
  • WAMR In Practice
    • Tutorial
      • WAMR Running Modes
      • Build Tutorial
        • Build iwasm
        • Build wamrc
      • Language Embedding
        • C/C++
        • Python
        • Go
      • Debugging & IDE Support
        • WAMR Source Debugging With LLDB
        • VS Code Support
          • Enable Debugging In VS Code
          • Move LLDB Binaries
    • Advance Tutorial
      • Performance Test
        • PolyBench
        • CoreMark
        • Sightglass
        • JetStream2
      • Memory Usage Tunning
      • Application Framework
      • Remote Application Management
        • Example 1: Install/Uninstall WASM App Remotely
        • Example 2: IoT App Store Demo
      • WAMR Porting Guide
    • Features
      • Export Native APIs To WASM Applications
        • Example 1: Export C Functions to WASM
        • Example 2: Using "native-lib"
      • Multiple Modules As Dependencies
        • Multi-modules Example
      • Multi-thread, Pthread APIs And Thread Management
        • Multi-thread Example
      • Linux SGX(Intel Software Guard Extension) Support
      • Linux SGX Remote Attestation
      • XIP(Execution In Place) Support
      • Socket Support
        • Example: Use Socket Api in WAMR
      • Post-MVP Features
        • WASM C API
        • 128-bit SIMD
        • Reference Types
    • More Examples
      • File Interaction Of WASI
      • GUI Example
        • Littlevgl
        • LVGL
      • Same WASM Program Executing Concurrently
      • Build And Run Workload
    • User Case
  • Programmer's Manual
    • Programmer's Manual
      • C API Lists
  • Community
    • How To Contribute
    • WAMR On Github
    • WAMR Blogs
  • Appendix
    • Appendix A. Background Knowledge And Glossary Of Terms
    • Appendix B. WebAssembly Details
    • Appendix C. Complete WAMR Guide
Powered by GitBook
On this page
  • WAMR porting guide
  • Step 1: Implement platform API layer
  • Step 2: Create the mini product for the platform
  1. WAMR In Practice
  2. Advance Tutorial

WAMR Porting Guide

PreviousExample 2: IoT App Store DemoNextFeatures

Last updated 2 years ago

WAMR porting guide

This document describes how to port WAMR to a new platform "new-os"

Step 1: Implement platform API layer


Firstly create the folder for platform API layer implementations:

  • for common platforms, create a folder in core/shared/platform/new-os in WAMR repository folder, so the implementation can be upstreamed

  • for platforms that are internal and its implementation shouldn't be published, it's recommended to create a folder outside of the WAMR repository folder (e.g. have separate repository for platform API layer implementation)

In the folder you just created, you must provide the following files:

  • platform_internal.h: It can be used for any platform-specific definitions such as macros, data types and internal APIs.

  • shared_platform.cmake: the cmake file will be included by the building script. It is recommended to add a definition for your platform:

    • add_definitions(-DBH_PLATFORM_YOUR_NAME)

Then go to implement the APIs defined in the following header files for the platform abstraction layer:

  • : mandatory for building mini-product (vmcore only). Part of the APIs is needed only for Ahead of Time compilation support.

  • : mandatory for app-mgr and app-framework. Given that the app-mgr and app-framework are not required for your target platform, you won't have to implement the API defined in the platform_api_extension.h.

common/posix:

There is posix based implementation of the platform API located in the platform/common/posix folder. You can include it if your platform supports posix API. refer to platform linux implementation.

common/math:

Some platforms such as ZephyrOS don't provide math functions e.g. sqrt, fabs and isnan, then you should include source files under the folder platform/common/math.

Step 2: Create the mini product for the platform


You can build a mini WAMR product which is only the vmcore for your platform. Normally you need to implement the main function which loads a WASM file and run it with the WASM runtime. You don't have to do this step if there is no mini-product need for your platform porting.

Firstly create folder product-mini/platforms/new-os for the platform mini product build, then refer to the linux platform mini-product for creating the CMakeList.txt and the C implementations.

You should set cmake variable WAMR_BUILD_PLATFORM to your platform name while building the mini product. It can be done in the mini product CMakeList.txt file, or pass arguments to cmake command line like:

mkdir build
cd build
cmake .. -DWAMR_BUILD_PLATFORM=new-os

For platform implementations that are outside of the WAMR repository (e.g. internal platforms), you also need to provide SHARED_PLATFORM_CONFIG path:

cmake .. -DWAMR_BUILD_PLATFORM=new-os -DSHARED_PLATFORM_CONFIG=/path/to/new-os/shared_platform.cmake

Refer to for the building configurations and parameters.

platform_api_vmcore.h
platform_api_extension.h
build_wamr.md