Make the source directory useable as a CMake library, plus ESP32 related cleanup (#30)

* m3_config_platforms: esp32: make the dependency on esp_system optional

If the application places wasm3 into IRAM using the linker script,
it can define M3_IN_IRAM flag. In this case we don't need to pull in
the dependency on IDF-specific header file into m3.

* cmake: make the source directory useable as a CMake library

Also replace globbing with an explicit list of files, following CMake
best practices.

* platforms/esp32-idf: link m3 as a static library

* platforms/esp32-pio: wrap the wasm3 code into a "PIO library"
extensions
Ivan Grokhotkov 5 years ago committed by Volodymyr Shymanskyy
parent 60117db070
commit 804d14991b

@ -114,9 +114,10 @@ jobs:
source $HOME/.wasienv/wasienv.sh
mkdir build-wasi
cd build-wasi
cmake -DWASIENV=1 ..
wasimake cmake -DWASIENV=1 ..
- name: Build
run: |
source $HOME/.wasienv/wasienv.sh
cmake --build build-wasi
- name: Run spec tests (in Wasmer)
run: |

@ -36,11 +36,6 @@ if(EMSCRIPTEN)
set(APP_DIR "platforms/emscripten")
endif()
if(WASIENV)
set(CMAKE_C_COMPILER "wasicc")
set(CMAKE_CXX_COMPILER "wasic++")
endif()
if(BUILD_32BIT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
endif()
@ -67,11 +62,9 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
file(GLOB M3_SRC "source/*.c" "source/*.cpp" "${APP_DIR}/*.c")
add_executable(${OUT_FILE} ${M3_SRC})
include_directories("./source/")
file(GLOB app_srcs "${APP_DIR}/*.c")
add_executable(${OUT_FILE} ${app_srcs})
#-fno-optimize-sibling-calls
@ -141,6 +134,9 @@ else()
message("LTO: OFF")
endif()
add_subdirectory(source)
target_link_libraries(${OUT_FILE} m3)
message("Flags: ${CMAKE_C_FLAGS}")
message("Debug flags: ${CMAKE_C_FLAGS_DEBUG}")
message("Release flags: ${CMAKE_C_FLAGS_RELEASE}")

@ -1,11 +1,26 @@
file(GLOB_RECURSE M3_SOURCES "m3/*.c")
set(idf_ver "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}")
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
idf_build_get_property(build_dir BUILD_DIR)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../source ${build_dir}/m3)
endif()
set(APP_SOURCES "main.cpp")
idf_component_register(SRCS ${APP_SOURCES} ${M3_SOURCES}
INCLUDE_DIRS "")
idf_component_register(SRCS ${APP_SOURCES}
INCLUDE_DIRS ""
LDFRAGMENTS linker.lf)
if (idf_ver STREQUAL "4.0")
# IDF v4.0 links apps with -nostdlib, so need to explicitly list the dependencies.
add_library(m3_deps INTERFACE)
target_link_libraries(m3_deps INTERFACE c m gcc)
target_link_libraries(${COMPONENT_TARGET} PRIVATE m3 m3_deps)
else()
# For IDF v4.1 and later, no tricks required.
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error -O3 -DESP32 -Dd_m3LogOutput=false)
target_link_libraries(${COMPONENT_TARGET} PRIVATE m3)
endif()
# Disable harmless warnings
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers)
target_compile_options(m3 PUBLIC -DM3_IN_IRAM -DESP32 -Dd_m3LogOutput=false)

@ -0,0 +1,6 @@
[mapping:wasm3]
archive: libm3.a
entries:
m3_core (noflash_text)
m3_exec (noflash_text)
m3_compile (noflash_text)

@ -1 +0,0 @@
../../../source

@ -11,10 +11,10 @@
#include <time.h>
#include <unistd.h>
#include "m3/wasm3.h"
#include "m3/m3_env.h"
#include "wasm3.h"
#include "m3_env.h"
#include "m3/extra/fib32.wasm.h"
#include "extra/fib32.wasm.h"
#define FATAL(msg, ...) { printf("Fatal: " msg "\n", ##__VA_ARGS__); return; }

@ -0,0 +1,3 @@
This is a placeholder for the wasm3 PIO library.
At the moment it simply adds the source code as a symlink, and sets some build flags.

@ -0,0 +1,5 @@
{
"build" : {
"flags": "-DESP32 -Dd_m3LogOutput=false -O3 -Wfatal-errors -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers"
}
}

@ -0,0 +1 @@
../../../../source

@ -16,14 +16,3 @@ framework = espidf
monitor_speed = 115200
board_build.f_cpu = 240000000L
src_build_flags =
-DESP32 -Dd_m3LogOutput=false
-O3 -Wfatal-errors
-flto
-Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
#-foptimize-sibling-calls
#-fomit-frame-pointer
#-fverbose-asm -save-temps=obj

@ -1 +0,0 @@
../../../source

@ -11,10 +11,10 @@
#include <time.h>
#include <unistd.h>
#include "m3/wasm3.h"
#include "m3/m3_env.h"
#include "wasm3.h"
#include "m3_env.h"
#include "m3/extra/fib32.wasm.h"
#include "extra/fib32.wasm.h"
#define FATAL(msg, ...) { printf("Fatal: " msg "\n", ##__VA_ARGS__); return; }

@ -0,0 +1,45 @@
set(srcs
"m3_api_libc.c"
"m3_api_meta_wasi.c"
"m3_api_wasi.c"
"m3_bind.c"
"m3_code.c"
"m3_compile.c"
"m3_core.c"
"m3_emit.c"
"m3_env.c"
"m3_exec.c"
"m3_info.c"
"m3_module.c"
"m3_optimize.c"
"m3_parse.c"
)
add_library(m3 STATIC ${srcs})
target_include_directories(m3 PUBLIC .)
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
# add MSVC specific flags here
else()
# Flags common for GCC and Clang
# FIXME: cast to 'void *' from smaller integer type 'i32'
set_source_files_properties(m3_emit.c PROPERTIES COMPILE_FLAGS -Wno-int-to-pointer-cast)
# FIXME: comparison of integers of different signs: 'u32' and 'i32'
set_source_files_properties(m3_env.c PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
if (WASIENV)
# FIXME: declaration of 'struct sigaction' will not be visible outside of this function
target_compile_options(m3 PUBLIC -Wno-visibility)
# FIXME incompatible pointer types passing 'u32 *' to parameter of type 'char **'
set_source_files_properties(m3_api_meta_wasi.c PROPERTIES COMPILE_FLAGS -Wno-incompatible-pointer-types)
endif()
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
# Clang specific flags here
else()
# GCC specific flags here
endif()
endif()

@ -220,8 +220,12 @@ typedef int8_t i8;
# include <c_types.h>
# define op_section //ICACHE_FLASH_ATTR
# elif defined (ESP32)
# include "esp_system.h"
# define op_section IRAM_ATTR
# if defined(M3_IN_IRAM) // the interpreter is in IRAM, attribute not needed
# define op_section
# else
# include "esp_system.h"
# define op_section IRAM_ATTR
# endif
# elif defined (FOMU)
# define op_section __attribute__((section(".ramtext")))
# endif

Loading…
Cancel
Save