Skip to content

Commit 251e63f

Browse files
authored
Enable specifying out-of-source platform configuration cmake file (#1941)
Resolve #1935, enable specifying out-of-source platform folder with `cmake .. -DWAMR_BUILD_PLATFORM=new-os -DSHARED_PLATFORM_CONFIG=/path/to/new-os/shared_platform.cmake`
1 parent f3c1ad4 commit 251e63f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

build-scripts/runtime_lib.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ endif ()
1919
if (NOT DEFINED DEPS_DIR)
2020
set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
2121
endif ()
22+
if (NOT DEFINED SHARED_PLATFORM_CONFIG)
23+
# CMake file for platform configuration. The PLATFORM_SHARED_SOURCE varable
24+
# should point to a list of platform-specfic source files to compile.
25+
set (SHARED_PLATFORM_CONFIG ${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
26+
endif ()
2227

2328
if (DEFINED EXTRA_SDK_INCLUDE_PATH)
2429
message(STATUS, "EXTRA_SDK_INCLUDE_PATH = ${EXTRA_SDK_INCLUDE_PATH} ")
@@ -165,7 +170,7 @@ LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
165170

166171
enable_language (ASM)
167172

168-
include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
173+
include (${SHARED_PLATFORM_CONFIG})
169174
include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
170175
include (${IWASM_DIR}/common/iwasm_common.cmake)
171176
include (${SHARED_DIR}/utils/shared_utils.cmake)

doc/port_wamr.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,43 @@ This document describes how to port WAMR to a new platform "**new-os**"
1010
# Step 1: Implement platform API layer
1111

1212
-------------------------
13-
Firstly create the folder **`core/shared/platform/new-os`** for platform API layer implementations. In the folder you just created, you must provide the following files:
13+
Firstly create the folder for platform API layer implementations:
14+
* for common platforms, create a folder in **`core/shared/platform/new-os`** in WAMR repository folder, so the implementation can be upstreamed
15+
* 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)
1416

15-
- `platform_internal.h`: It can be used for any platform specific definitions such as macros, data types and internal APIs.
17+
In the folder you just created, you must provide the following files:
18+
19+
- `platform_internal.h`: It can be used for any platform-specific definitions such as macros, data types and internal APIs.
1620

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

1923
- ```cmake
2024
add_definitions(-DBH_PLATFORM_YOUR_NAME)
2125
```
2226
23-
Then go to implement the APIs defined in following header files for the platform abstraction layer:
27+
Then go to implement the APIs defined in the following header files for the platform abstraction layer:
2428
25-
- [`platform_api_vmcore.h`](../core/shared/platform/include/platform_api_vmcore.h): mandatory for building mini-product (vmcore only). Part of APIs are needed only for Ahead of Time compilation support.
29+
- [`platform_api_vmcore.h`](../core/shared/platform/include/platform_api_vmcore.h): mandatory for building mini-product (vmcore only). Part of the APIs is needed only for Ahead of Time compilation support.
2630
- [`platform_api_extension.h`](../core/shared/platform/include/platform_api_extension.h): 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`.
2731
2832
2933
3034
**common/posix:**
3135
32-
There is posix based implementation of the platform API located in the `platform/common/posix` folder. You can include it if your platform support posix API. refer to platform linux implementation.
36+
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.
3337
3438
3539
3640
**common/math:**
3741
38-
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`.
42+
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`.
3943
4044
4145
4246
# Step 2: Create the mini product for the platform
4347
4448
-------------------------
45-
You can build a mini WAMR product which is only the vmcore for you 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.
49+
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.
4650
4751
4852
@@ -55,9 +59,14 @@ You should set cmake variable `WAMR_BUILD_PLATFORM` to your platform name while
5559
```
5660
mkdir build
5761
cd build
58-
cmake .. -DWAMR_BUILD_PLATFORM=new-os
62+
cmake .. -DWAMR_BUILD_PLATFORM=new-os
5963
```
6064
65+
For platform implementations that are outside of the WAMR repository (e.g. internal platforms), you also need to provide `SHARED_PLATFORM_CONFIG` path:
66+
67+
```
68+
cmake .. -DWAMR_BUILD_PLATFORM=new-os -DSHARED_PLATFORM_CONFIG=/path/to/new-os/shared_platform.cmake
69+
```
6170
6271
6372
Refer to [build_wamr.md](./build_wamr.md) for the building configurations and parameters.

0 commit comments

Comments
 (0)