Skip to content

Commit

Permalink
pkg/wamr: add WAMR to provide WASM support in RIOT
Browse files Browse the repository at this point in the history
  • Loading branch information
kfessel committed Oct 28, 2020
1 parent 9105c60 commit 476d69a
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/wamr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.8.2)

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

project(NONE)

enable_language (ASM)

set (WAMR_BUILD_PLATFORM "riot")

# Build as X86_32 by default, change to "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS" or "XTENSA"
# if we want to support arm, thumb, mips or xtensa
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "X86_32")
endif ()

if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
# Disable AOT by default.
set (WAMR_BUILD_AOT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Disable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 0)
endif ()

if (NOT DEFINED WAMR_ROOT_DIR)
# this assumption is true if this file is copied to WAMR_ROOT
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif ()

include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

# need includes from RIOT
string(REGEX MATCHALL "([^\ ]+\ |[^\ ]+$)" RIOT_INCLUDES_LIST "${RIOT_INCLUDES}")

include_directories(SYSTEM ${RIOT_INCLUDES_LIST})


# target_sources( ${WAMR_RUNTIME_LIB_SOURCE} )
# executable linking is done by RIOT build system

add_library( wamr ${WAMR_RUNTIME_LIB_SOURCE})
61 changes: 61 additions & 0 deletions pkg/wamr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
PKG_NAME=wamr
PKG_URL=https://github.com/bytecodealliance/wasm-micro-runtime.git
PKG_VERSION=main
PKG_LICENSE=Apache-2.0

include $(RIOTBASE)/pkg/pkg.mk

#less Wall TODO: get things fixed upstream
CFLAGS := $(filter-out -pedantic, $(CFLAGS))
CFLAGS += -Wno-format
CFLAGS += -Wno-strict-prototypes
CFLAGS += -Wno-old-style-definition
CFLAGS += -Wno-cast-function-type

#Prepapre includes for cmake
RIOT_INCLUDES = $(filter-out -%,$(subst -I,,$(INCLUDES)))

#translate (CPU_ARCH) to Build Target
#WAMR_BUILD_TARGET is "X86_32" "AARCH64[sub]", "ARM[sub]",
# "THUMB[sub]", "MIPS" or "XTENSA"
#no msp430, no AVR support for now
ifeq ($(CPU),native)
#$(CPU) ist defined for every CPU
#everyone build on x86_32
WAMR_BUILD_TARGET = X86_32
else ifeq ($(findstring arm,$(CPU_ARCH)),arm)
WAMR_BUILD_TARGET = THUMB
else ifeq ($(CPU_ARCH),mips32r2)
WAMR_BUILD_TARGET = MIPS
else ifeq ($(CPU_ARCH),xtensa)
WAMR_BUILD_TARGET = XTENSA
endif

ifeq ($(QUIET), 0)
CMAKEMAKEFLAGS += VERBOSE=1
endif


all: $(BINDIR)/libwamr.a

$(BINDIR)/libwamr.a: $(PKG_BUILD_DIR)/libwamr.a
cp $< $@

$(PKG_BUILD_DIR)/libwamr.a: $(PKG_BUILD_DIR)/Makefile
$(MAKE) -C $(PKG_BUILD_DIR) $(CMAKEMAKEFLAGS)

$(PKG_BUILD_DIR)/Makefile: $(PKG_PREPARED)
cmake -B$(PKG_BUILD_DIR) \
"-DRIOT_INCLUDES=$(RIOT_INCLUDES)"\
-DWAMR_BUILD_TARGET=$(WAMR_BUILD_TARGET)\
-DWAMR_ROOT_DIR=$(PKG_SOURCE_DIR)\\
-DCMAKE_SYSTEM_NAME=Generic \
-DCMAKE_SYSTEM_PROCESSOR="$(MCPU)" \
-DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_C_COMPILER_WORKS=TRUE \

print_build_target:
@echo CPU_ARCH: $(CPU_ARCH)
@echo CPU: $(CPU)
@echo CFLAGS: $(CFLAGS)
@echo WAMR_BUILD_TARGET: $(WAMR_BUILD_TARGET)
5 changes: 5 additions & 0 deletions pkg/wamr/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USEMODULE += sema

#WAMR supports "X86_32/64", "AARCH64", "ARM", "THUMB", "MIPS" and "XTENSA"
#no 8/16 Bit TODO: might need to blacklist more
FEATURES_BLACKLIST += arch_8bit arch_16bit
12 changes: 12 additions & 0 deletions pkg/wamr/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
IWASM_CORE = $(PKGDIRBASE)/wamr/core
IWASM_ROOT = $(IWASM_CORE)/iwasm
SHARED_LIB_ROOT = $(IWASM_CORE)/shared

IWASM_INCLUDES += ${IWASM_ROOT}/include \
${SHARED_LIB_ROOT}/platform/include \
${SHARED_LIB_ROOT}/platform/riot \


INCLUDES += $(addprefix -I,${IWASM_INCLUDES})

ARCHIVES += $(BINDIR)/libwamr.a
6 changes: 6 additions & 0 deletions pkg/wamr/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @defgroup pkg_wamr WebAssembly Micro Runtime
* @ingroup pkg
* @brief Provides WebAssembly support for RIOT
* @see https://github.com/bytecodealliance/wasm-micro-runtime
*/

0 comments on commit 476d69a

Please sign in to comment.