Upgrade WAMR-IDE (#1313)

Upgrade WAMR-IDE: test-tools/wamr-ide folder
- add `wamr-sdk` to include libc-builtin-sysroot header files
- add `prettier` check and apply script in `package.json`
- update `wasm-toolchain` dockerfile and resource
- enhance `build | run | debug` process to clean up the container
- enhance the change workspace
- enhance `wasm` type project check before building, running and debugging
- format the project_compilation.json
- update documents
This commit is contained in:
Wang Ning 2022-07-29 08:12:36 +08:00 committed by GitHub
parent efc8bc10a9
commit 653b926d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 1675 additions and 648 deletions

2
test-tools/wamr-ide/.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Convert to LF line endings on checkout.
*.sh text eol=lf

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -2,177 +2,221 @@
## Introduction
The WAMR-IDE is an Integrated Development Environment to develop WebAssembly application with coding, compiling and source debugging support. It contains 3 components: `VSCode extension`, `WASM-toolchain-provider docker image` and `WASM source debug server docker image`.
The WAMR-IDE is an Integrated Development Environment to develop WebAssembly application with coding, compiling and source debugging support. It contains 3 components: `VSCode extension`, `wasm-toolchain docker image` and `wasm-debug-server docker image`.
- `VSCode extension` is an extension which can be installed in `vscode`, with which user can build and manage projects, develop `wasm application`, including `building`, `running` and `debugging`.
- `VSCode extension` is an `vscode` extension, with which user can build and manage projects, develop `wasm application`, including `building`, `running` and `debugging`.
- `WASM-toolchain-provider` is a docker image which provides building environment for wasm.
- `WASM-toolchain` is a docker image which provides building environment for wasm.
- `WASM source debug server` is a docker image which provides running and source debugging environment for wasm application.
- `WASM source debug server` is a docker image which provides running and source debugging environment for wasm application.
---
## How to setup WAMR IDE
1. Install `VSCode` on host.
#### 1. Install `VSCode` on host.
- make sure the version of [vscode](https://code.visualstudio.com/Download) you installed is at least _1.59.0_
- make sure the version of [vscode](https://code.visualstudio.com/Download) you installed is at least _1.59.0_
2. Install `Docker` on host.
#### 2. Install `Docker` on host.
1. [Windows: Docker Desktop](https://docs.docker.com/desktop/windows/install/)
2. [Ubuntu: Docker Engine](https://docs.docker.com/engine/install/ubuntu)
```xml
OS requirements:
To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:
- Ubuntu Impish 21.10
- Ubuntu Hirsute 21.04
- Ubuntu Focal 20.04(LTS)
- Ubuntu Bionic 18.04(LTS)
```
```xml
OS requirements:
To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:
- Ubuntu Impish 21.10
- Ubuntu Hirsute 21.04
- Ubuntu Focal 20.04(LTS)
- Ubuntu Bionic 18.04(LTS)
```
3. Build docker images
#### 3. Build docker images
We have 2 docker images which should be built or loaded on your host, `wasm-toolchain-provider` and `wamr-debug-server`. To build these 2 images, please enter the `WASM_Source_Debug_Server/Docker` & `WASM_Toolchain/Docker`, then execute the `build_docker_image` script respectively.
We have 2 docker images which should be built or loaded on your host, `wasm-toolchain` and `wasm-debug-server`. To build these 2 images, please enter the `WASM_Source_Debug_Server/Docker` & `WASM_Toolchain/Docker`, then execute the `build_docker_image` script respectively.
```shell
$ cd WASM_Toolchain/Docker
$ ./build_docker_image.bat # or ./build_docker_image.sh on linux
$ cd WASM_Source_Debug_Server/Docker
$ ./build_docker_image.bat # or ./build_docker_image.sh on linux
```
Windows (powershell):
4. Generate wamride extension package file
```batch
$ cd .\WASM-Toolchain\Docker
$ ./build_docker_image.bat
$ cd .\WASM-Source-Debug-Server\Docker
$ ./build_docker_image.bat
```
`wamride-0.0.1.vsix` can be packaged by [`npm vsce`](https://code.visualstudio.com/api/working-with-extensions/publishing-extension).
Linux:
> Note that patched `lldb` should be built and put into the `VSCode_Extension/resource/debug` folder before your package or extension debug process if you want to enable `source debugging` feature. Please follow this [instruction](../../doc/source_debugging.md#debugging-with-interpreter) to build `lldb`.
>
> **You can also debug the extension directly follow this [instruction](./VSCode_Extension/README.md) without packing the extension.**
```shell
$ cd ./WASM-Toolchain/Docker
$ ./build_docker_image.sh
$ cd ./WASM-Debug-Server/Docker
$ ./build_docker_image.sh
```
5. Install extension from vsix
#### After building, you can find `wasm-toolchain` and `wasm-debug-server` docker images on your local
![install_from_vsix](./Media/install_from_vsix.png "install wamr-ide from vsix")
![docker-images](./Media/docker_images.png)
and select `wamride-0.0.1.vsix` which you have saved on your host.
#### If building docker images fail during the process
Sometimes building the Docker images may fail due to bad network conditions. If the `wasm-toolchain` and `wasm-debug-server` images do not exist after building, please build them manually. Fix the proxy setting if needed and execute the following command to build docker images.
![docker-engine-config](./Media/docker_config.jpg)
> Note: please correctly replace example proxy address with your own before you run manually.
```xml
$ cd .\docker_images\wasm-debug-server
$ docker build --no-cache --build-arg http_proxy=http://proxy-example.com:1234
--build-arg https_proxy=http://proxy-example.com:1234 -t wasm-debug-server:1.0 .
```
```xml
$ cd .\docker_images\wasm-toolchain
$ docker build --no-cache --build-arg http_proxy=http://proxy-example.com:1234
--build-arg https_proxy=http://proxy-example.com:1234 -t wasm-toolchain:1.0 .
```
#### If you encounter the problem `failed to solve with frontend dockerfile.v0: failed to create LLB definition`, please config your docker desktop
![docker-engine-config](./Media/docker_engine_config.png)
#### Points To Remember
- Make sure that the `wasm-toolchain:1.0` and `wasm-debug-server:1.0` docker images are both successfully built before using `WAMR IDE`, otherwise `Build`, `Run` and `Debug` will not work.
#### 4. Generate wamride extension package file
`wamride-1.0.0.vsix` can be packaged by [`npm vsce`](https://code.visualstudio.com/api/working-with-extensions/publishing-extension).
> Note that patched `lldb` should be built and put into the `VSCode_Extension/resource/debug` folder before your package or extension debug process if you want to enable `source debugging` feature. Please follow this [instruction](../../doc/source_debugging.md#debugging-with-interpreter) to build `lldb`.
>
> **You can also debug the extension directly follow this [instruction](./VSCode_Extension/README.md) without packing the extension.**
#### 5. Install extension from vsix
![install_from_vsix](./Media/install_from_vsix.png "install wamr-ide from vsix")
select `wamride-1.0.0.vsix` which you have packed on your host.
---
## How to use `wamr-ide`
#### `WAMR-IDE` extension contains 2 components as following picture showing. `Project management` and `Execution management`
#### `WAMR-IDE` extension contains 2 components as following picture showing. `WAMR IDE` for workspace and project management and `Current Project` for project's execution.
![wamr_ide_main_menu](./Media/wamr_ide_main_menu.png "wamr-ide main menu")
### Project Management
### Project Execution
1. New project
#### 1. New project
When you click `New project` button, extension will pop up a message box at the bottom right of the screen as picture showing.
When you click `New project` button, the extension will pop up a message box at the bottom right of the screen as following:
![set_up_workspace_message](./Media/set_up_workspace_message.png "set up workspace message box")
![set-up-workspace-message](./Media/set-up-workspace-message.png "set up workspace message box")
You can click `Set up now` and select the target folder to create project workspace, click `Maybe later` to close the message box.
You can click `Set up now` and select the target folder to create project workspace, or you click `Maybe later` to close the message box.
> Note that your selected workspace folder should be **empty**.
> Note that your selected workspace folder should be **empty** or the folder you have set up as workspace.
After setting up workspace, extension will prompt successful message:
After setting up workspace, extension will prompt successful message:
```xml
workspace set up successfully!
```
```xml
Workspace has been set up successfully!
```
Then click `New project` button again, a new page will show as following.
Then click `New project` button again, a new page will show as following.
![new_project_page](./Media/new_project_page.png "new project page")
![new-project-page](./Media/new_project_page.png "new project page")
Enter the `project name` and select the `template`, then click `Create` button. And a new project will be generated and opened in your current `vscode window` or in a new `vscode window`.
Enter the `Project name` and select the `Template`, then click `Create` button. A new project will be generated and opened in your current `VS Code window` or in a new `VS Code window`.
> Opening in current windows or a new one depends on whether your `vscode's explorer` is empty or not. If empty, open in current window, or open in the new vscode window.
> Opening in current windows or a new one depends on whether your `vscode's explorer` is empty or not. If empty, open in current window, or open in the new vscode window.
A new initialized project is as following picture shows.
A new initialized project is as following picture shows.
![project_template](./Media/project_template.png "default project template")
![project-template](./Media/project_template.png "default project template")
`.wamr` is the project configuration folder which contains 3 files, `CMakeLists.txt`, `project.cmake` and `compilation_config.json`. `CMakeLists.txt` is used to build `wasm target` and the `project.cmake` is included in `CMakeLists.txt`. `project.cmake` includes the user's customized configuration like those folders which should be added include path.
`.wamr` is the project configuration folder which contains 3 files, `CMakeLists.txt`, `project.cmake`, and `compilation_config.json`. `CMakeLists.txt` is used to build `wasm target` and the `project.cmake` is included in `CMakeLists.txt`. `compilation_config.json` includes the user's customized configuration such as folders which should be added in the include path.
2. Open project
#### 2. Open project
Click `Open project` button, `quick-pick-box` will show as following. All projects under your current workspace will be shown and can be selected.
Click `Open project` button, `quick-pick-box` will show as following. All projects under your current workspace will be shown and can be selected.
![configuration file](./Media/open_project_page.png "configuration file")
![configuration file](./Media/open_project_page.png "configuration file")
3. Change workspace
#### 3. Change workspace
Click `Change workspace` button, a dialog will show as following. You can select 1 folder in file system as workspace, and the new workspace path will override previous workspace, and all new created projects will be generated in the new workspace.
Click `Change workspace` button, a dialog will show as following. You can select 1 folder in file system as workspace, and the new workspace path will override previous workspace, and all new created projects will be generated in the new workspace.
![change workspace ](./Media/change_workspace_dialog.png "change workspace dialog")
![change workspace ](./Media/change_workspace_dialog.png "change workspace dialog")
4. Configuration
Click `Configuration` button, a new page will be shown as following. You can config building target with `Include paths`, `Initial & Max linear memory`, `stack size`, `exported_symbols` and `include paths`, `exclude files`.
![config building target](./Media/Config_building_target.png "config building target")
Then click `Modify` button to confirm, if configurations are modified successfully and following message will pop. Click `OK`, the page will be auto closed.
![save configuration](./Media/save_configuration.png "save configuration")
And all configuration will be saved in `.wamr/compilation_config.json`.
![configuration file](./Media/compilation_config.png "configuration file")
5. Customize `include paths` and `exclude source files`
#### 4. Customize `include paths` and `exclude source files`
Extension supports adding header file folder to `include path` and excluding source file from build.
- `Add to include path`
- `Add to include path`
- Move the cursor to the `folder` and right click, then `menus` will be shown as following. Click `Toggle state of path including`.
- Move the cursor to the `folder` and right click, then `menus` will be shown as following. Click `Toggle state of path including`.
![right click menus](./Media/right_click_menus_1.png "right click menus")
![right click menus](./Media/right_click_menus_1.png "right click menus")
- `Exclude source file from build`
- `Exclude source file from build`
- Move the cursor to the `source file` and right click, then `menus` will be shown as following. Click `Toggle state of excluding`.
- Move the cursor to the `source file` and right click, then `menus` will be shown as following. Click `Toggle state of excluding`.
![right click menus](./Media/right_click_menus_2.png "right click menus")
![right click menus](./Media/right_click_menus_2.png "right click menus")
#### After setting up `include path` and `exclude files`, the corresponding folder and files will be decorated with color and icon as following picture shows.
#### After setting up `include path` and `exclude files`, the corresponding folder and files will be decorated with color and icon as following picture shows.
![decoration for files](./Media/decoration_for_files.png "decoration for files")
![decoration for files](./Media/decoration_for_files.png "decoration for files")
At the same time, all added `include path` and `exclude files` will be saved in `.wamr/compilation_config.json` as json array.
At the same time, all added `include path` and `exclude files` will be saved in `.wamr/compilation_config.json` as json array.
![compilation config](./Media/compilation_config_2.png "compilation config")
![compilation config](./Media/compilation_config_2.png "compilation config")
> `Toggle state of path including` just shows when selecting `folder` and hides with other resources.
>
> `Toggle state of excluding` just shows when selecting `[.c | .cpp | .cxx] source files` and hides with other resources.
### Execution Management
### Current Project Management
1. `Build`
#### 1. Configuration
When you have completed coding and ready to build target, click `build` button and the `wasm-toolchain` will auto start a container and execute the building process.
Click `Configuration` button, a new page will be shown as following. You can config building target with `Include paths`, `Initial & Max linear memory`, `stack size`, `exported_symbols` and `include paths`, `exclude files`.
![build terminal output](./Media/build_terminal.png "build terminal output")
![config building target](./Media/Config_building_target.png "config building target")
After successful building execution, `build` folder will be generated in `explorer`, in which `${output_file_name}.wasm` is exist.
Then click `Modify` button to confirm, if configurations are modified successfully and following message will pop. Click `OK`, the page will be auto closed.
![build folder](./Media/build_folder.png "build folder")
![save configuration](./Media/save_configuration.png "save configuration")
> Note that to start `docker service` firstly.
And all configuration will be saved in `.wamr/compilation_config.json`.
2. `Run`
![configuration file](./Media/compilation_config.png "configuration file")
Click `Run` button and `wasm-debug-server` docker image will auto start a container and execute the running process.
#### 2. `Build`
![run](./Media/run.png "run wasm")
When you have completed coding and ready to build target, click `build` button and the `wasm-toolchain` will auto start a container and execute the building process.
3. `Debug`
![build terminal output](./Media/build_terminal.png "build terminal output")
Click `Debug` button will trigger start ip `wamr-debug-server` docker image, and boot up `lldb debug server` inside of iwasm. Then start a debugging session with configuration to connect. Tap `F11` or click `step into` to start debugging.
After successful building execution, `build` folder will be generated in `explorer`, in which `${output_file_name}.wasm` is exist.
![debug](./Media/debug.png "source debugging")
![build folder](./Media/build_folder.png "build folder")
> Docker containers will be auto stopped and removed after the execution.
> Note that to start `docker service` firstly.
#### 3. Run
Click `Run` button and `wasm-debug-server` docker image will auto start a container and execute the running process.
![run](./Media/run.png "run wasm")
#### 4. Debug
Click `Debug` button will trigger start ip `wamr-debug-server` docker image, and boot up `lldb debug server` inside of iwasm. Then start a debugging session with configuration to connect. Tap `F11` or click `step into` to start debugging.
![debug](./Media/debug.png "source debugging")
> Docker containers will be auto stopped and removed after the execution.

View File

@ -0,0 +1,41 @@
@REM Copyright (C) 2019 Intel Corporation. All rights reserved.
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
set DIR_ROOT=%cd%\..
echo "=== Verify the vscode status ==="
call code --version
IF %ERRORLEVEL%==0 (
echo "vscode is ready."
) ELSE (
echo "VSCode is not installed, please install firstly."
exit /b 1
)
echo "=== Verify the docker status ==="
call docker --version
IF %ERRORLEVEL%==0 (
echo "docker is ready."
) ELSE (
echo "Docker is not installed, please install firstly."
exit /b 1
)
cd %DIR_ROOT%\WASM-Debug-Server\Docker
call docker build -t wasm-debug-server:1.0 .
IF %ERRORLEVEL%==0 (
echo "wasm-debug-server image is ready."
) ELSE (
echo "build wasm-debug-server image failed."
exit /b 1
)
cd %DIR_ROOT%\WASM-Toolchain\Docker
call docker build -t wasm-toolchain:1.0 .
IF %ERRORLEVEL%==0 (
echo "wasm-toolchain image is ready."
) ELSE (
echo "build wasm-toolchain image failed."
exit /b 1
)

View File

@ -0,0 +1,46 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
# 1. verify the environment: vscode & docker
# 1.1 if docker is installed, config docker command execution without sudo, promp if not installed and exit.
# 1.2 if vscode is not installed, promp and exit.
# 2. build wasm-toolchain & wasm-debug-server docker image
DIR_ROOT=$(pwd)/..
echo "=== Verify the vscode status ==="
if [ "$(code --version)" ]; then
echo "VSCode is ready."
else
echo "VSCode is not installed, please install firstly."
exit 1
fi
echo "=== Verify the docker status ==="
if [ "$(docker --version)" ]; then
echo "Docker is ready."
else
echo "Docker is not installed, please install firstly."
exit 1
fi
# setup docker command exectuion without sudo permission
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo service docker restart
# create new group and execute the rest commands
newgrp - docker << REST
# 2. build wasm-debug-server docker image
cd ${DIR_ROOT}/WASM-Debug-Server/Docker
docker build -t wasm-debug-server:1.0 .
# 3. build wasm-toolchain docker image
cd ${DIR_ROOT}/WASM-Toolchain/Docker
docker pull ubuntu:20.04
docker build -t wasm-toolchain:1.0 .
REST

View File

@ -1,11 +1,10 @@
.gitignore
.yarnrc
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map

View File

@ -21,5 +21,14 @@ File -> Open Folder -> select `VSCode_Extension`
# Code Format
`prettier` is recommended and `.prettierrc.json` has been provided in workspace.
More details and usage guidance please refer
[prettier](https://prettier.io/docs/en/install.html)
More details and usage guidance please refer [prettier](https://prettier.io/docs/en/install.html)
You can run following commands in current extension directory to check and apply
```shell
# install prettier firstly
npm install --save-dev prettier
# check format
npm run prettier-format-check
# apply
npm run prettier-format-apply
```

View File

@ -1,9 +1,12 @@
{
"name": "wamride",
"publisher": "wamr",
"repository": {
"url": "https://github.com/bytecodealliance/wasm-micro-runtime/tree/main/test-tools/wamr-ide"
},
"displayName": "WAMR-IDE",
"description": "An Integrated Development Environment for WASM",
"version": "0.0.1",
"version": "1.0.0",
"engines": {
"vscode": "^1.59.0"
},
@ -75,11 +78,11 @@
"viewsWelcome": [
{
"view": "wamride.views.welcome",
"contents": "[ Project Management ]\n[$(project)New project](command:wamride.newProject)\n[$(files)Open project](command:wamride.openFolder)\n[$(book)Change workspace](command:wamride.changeWorkspace)\n[$(pencil)Configuration](command:wamride.targetConfig)"
"contents": "[ WAMR IDE ]\n[$(project)New project](command:wamride.newProject)\n[$(files)Open project](command:wamride.openFolder)\n[$(book)Change workspace](command:wamride.changeWorkspace)"
},
{
"view": "wamride.views.welcome",
"contents": "[ Execution Management ]\n[$(gear)Build](command:wamride.build)\n[$(run)Run](command:wamride.run)\n[$(debug-alt) Debug](command:wamride.debug)",
"contents": "[ Current Project ]\n[$(pencil)Configuration](command:wamride.targetConfig)\n[$(gear)Build](command:wamride.build)\n[$(run)Run](command:wamride.run)\n[$(debug-alt) Debug](command:wamride.debug)",
"enablement": "ext.isWasmProject"
}
],
@ -208,6 +211,11 @@
}
}
}
],
"taskDefinitions": [
{
"type": "wasm"
}
]
},
"scripts": {
@ -216,7 +224,9 @@
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"prettier-format-check": "prettier --config .prettierrc.json 'src/**/*.ts' --check",
"prettier-format-apply": "prettier --config .prettierrc.json 'src/**/*.ts' --write"
},
"devDependencies": {
"@types/glob": "^7.1.3",

View File

@ -7,26 +7,19 @@ project(Main)
include(${CMAKE_CURRENT_SOURCE_DIR}/project.cmake)
set (CMAKE_SYSROOT /opt/wamr-sdk/app/libc-builtin-sysroot)
set (CMAKE_C_FLAGS " -nostdlib -g -Wno-unused-command-line-argument " CACHE INTERNAL "")
set (CMAKE_CXX_FLAGS " -nostdlib -g" CACHE INTERNAL "")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wno-unused-command-line-argument " CACHE INTERNAL "")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=${STACK_SIZE}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdebug-prefix-map=/mnt='$ENV{PROJ_PATH}'")
set (CMAKE_EXE_LINKER_FLAGS
"-Wl,--initial-memory=${INIT_MEM_SIZE},--max-memory=${MAX_MEM_SIZE}, \
-Wl,--no-entry,")
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--initial-memory=${INIT_MEM_SIZE},--max-memory=${MAX_MEM_SIZE},")
set (CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} \
${EXPORTED_SYMBOLS},")
set (CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} \
-Wl,--allow-undefined-file=${CMAKE_SYSROOT}/share/defined-symbols.txt" CACHE INTERNAL "")
set (SRC_LIST
${PROJECT_SRC_LIST})
@ -37,4 +30,3 @@ set (HEADER_LIST
include_directories(${HEADER_LIST})
add_executable (${OUTPUT_FILE_NAME} ${SRC_LIST})

View File

@ -2,13 +2,13 @@
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
set target_name=%1
docker run -it --name=wasm-debug-server-ctr ^
-v "%cd%":/mnt ^
-p 1234:1234 ^
wasm-debug-server:1.0 ^
/bin/bash -c "./debug.sh %target_name%"
/bin/bash -c "./debug.sh %1"
@REM stop and remove wasm-debug-server-container
docker stop wasm-debug-server-ctr && docker rm wasm-debug-server-ctr
docker stop wasm-debug-server-ctr>nul 2>nul
docker rm wasm-debug-server-ctr>nul 2>nul

View File

@ -3,12 +3,11 @@
#!/bin/bash
target_name=$1
docker run -it --name=wasm-debug-server-ctr \
-v $(pwd):/mnt \
-v "$(pwd)":/mnt \
-p 1234:1234 \
wasm-debug-server:1.0 \
/bin/bash -c "./debug.sh ${target_name}"
/bin/bash -c "./debug.sh $1"
docker stop wasm-debug-server-ctr && docker rm wasm-debug-server-ctr
docker stop wasm-debug-server-ctr>/dev/null
docker rm wasm-debug-server-ctr>/dev/null

View File

@ -2,13 +2,14 @@
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
set AoT_Binary_Name=%1
@REM start a container, mount current project path to container/mnt
docker run --name=wasm-toolchain-provider-ctr ^
-it -v %cd%:/mnt ^
wasm-toolchain-provider:1.0 ^
/bin/bash -c "./build_wasm.sh %AoT_Binary_Name%"
docker run --name=wasm-toolchain-ctr ^
-it -v "%cd%":/mnt ^
--env=PROJ_PATH="%cd%" ^
wasm-toolchain:1.0 ^
/bin/bash -c "./build_wasm.sh %1"
@REM stop and remove wasm-toolchain-ctr container
docker stop wasm-toolchain-provider-ctr && docker rm wasm-toolchain-provider-ctr
docker stop wasm-toolchain-ctr>nul 2>nul
docker rm wasm-toolchain-ctr>nul 2>nul

View File

@ -3,17 +3,11 @@
#!/bin/bash
AoT_Binary_Name=$1
docker run --name=wasm-toolchain-ctr \
-it -v "$(pwd)":/mnt \
--env=PROJ_PATH="$(pwd)" \
wasm-toolchain:1.0 \
/bin/bash -c "./build_wasm.sh $1"
# start & run docker image and build wasm
if test ! -z "$(docker ps -a | grep wasm-toolchain-ctr)"; then
sudo docker rm wasm-toolchain-ctr
fi
sudo docker run --name=wasm-toolchain-provider-ctr \
-it -v $(pwd):/mnt \
wasm-toolchain-provider:1.0 \
/bin/bash -c "./build_wasm.sh $AoT_Binary_Name"
# stop and remove wasm-toolchain-ctr container
sudo docker stop wasm-toolchain-provider-ctr && sudo docker rm wasm-toolchain-provider-ctr
docker stop wasm-toolchain-ctr>/dev/null
docker rm wasm-toolchain-ctr>/dev/null

View File

@ -0,0 +1,38 @@
@REM Copyright (C) 2019 Intel Corporation. All rights reserved.
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
call docker --version>nul 2>nul
IF %ERRORLEVEL% GTR 0 (
echo "Docker is not installed, please install docker desktop firstly."
echo
exit /b 1
)
call docker images>nul 2>nul
IF %ERRORLEVEL% GTR 0 (
echo "Docker is not ready, please lanuch docker desktop firstly."
echo
exit /b 2
)
echo "Prepare to clean up the docker containers..."
call docker inspect wasm-toolchain-ctr>nul 2>nul
IF %ERRORLEVEL% EQU 0 (
echo "Stopping and removing wasm-toolchain-ctr container..."
docker stop wasm-toolchain-ctr>nul 2>nul
docker rm wasm-toolchain-ctr>nul 2>nul
echo "Done."
)
call docker inspect wasm-debug-server-ctr>nul 2>nul
IF %ERRORLEVEL% EQU 0 (
echo "Stopping and removing wasm-debug-server-ctr container..."
docker stop wasm-debug-server-ctr>nul 2>nul
docker rm wasm-debug-server-ctr>nul 2>nul
echo "Done."
)
echo "Clean up docker containers successfully."

View File

@ -0,0 +1,34 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
docker -v>/dev/null
if [ $? -ne 0 ]; then
echo "\nDocker is not installed, please install docker firstly.\n"
exit 1
fi
docker images>/dev/null
if [ $? -ne 0 ]; then
echo "\nDocker service is not running, please start your docker service firstly.\n"
exit 2
fi
echo "Prepare to clean up the docker containers..."
if test ! -z "$(docker ps -a | grep wasm-toolchain-ctr)"; then
echo "Stopping and removing wasm-toolchain-ctr container..."
docker stop wasm-toolchain-ctr>/dev/null
docker rm wasm-toolchain-ctr>/dev/null
echo "Done."
fi
if test ! -z "$(docker ps -a | grep wasm-debug-server-ctr)"; then
echo "Stopping and removing wasm-debug-server-ctr container..."
docker stop wasm-debug-server-ctr>/dev/null
docker rm wasm-debug-server-ctr>/dev/null
echo "Done."
fi
echo "Clean up docker containers successfully."

View File

@ -2,12 +2,12 @@
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
set target_name=%1
docker run -it --name=wasm-executor-ctr ^
docker run -it --name=wasm-debug-server-ctr ^
-v "%cd%":/mnt ^
wasm-debug-server:1.0 ^
/bin/bash -c "./run.sh %target_name%"
/bin/bash -c "./run.sh %1"
@REM stop and remove wasm-executor-ctr
docker stop wasm-executor-ctr && docker rm wasm-executor-ctr
@REM stop and remove wasm-debug-server-ctr
docker stop wasm-debug-server-ctr>nul 2>nul
docker rm wasm-debug-server-ctr>nul 2>nul

View File

@ -2,11 +2,11 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
target_name=$1
docker run -it --name=wasm-debug-server-ctr \
-v $(pwd):/mnt \
-v "$(pwd)":/mnt \
wasm-debug-server:1.0 \
/bin/bash -c "./run.sh ${target_name}"
/bin/bash -c "./run.sh $1"
docker stop wasm-debug-server-ctr && docker rm wasm-debug-server-ctr
docker stop wasm-debug-server-ctr>/dev/null
docker rm wasm-debug-server-ctr>/dev/null

View File

@ -0,0 +1,17 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_ASSERT_H
#define _WAMR_LIBC_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_CTYPE_H
#define _WAMR_LIBC_CTYPE_H
#ifdef __cplusplus
extern "C" {
#endif
int
isupper(int c);
int
isalpha(int c);
int
isspace(int c);
int
isgraph(int c);
int
isprint(int c);
int
isdigit(int c);
int
isxdigit(int c);
int
tolower(int c);
int
toupper(int c);
int
isalnum(int c);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,17 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_ERRNO_H
#define _WAMR_LIBC_ERRNO_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,17 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_FCNTL_H
#define _WAMR_LIBC_FCNTL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_INTTYPES_H
#define _WAMR_LIBC_INTTYPES_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_LIMITS_H
#define _WAMR_LIBC_LIMITS_H
#ifdef __cplusplus
extern "C" {
#endif
#define CHAR_BIT 8
#define SCHAR_MIN -128
#define SCHAR_MAX 127
#define UCHAR_MAX 255
#define CHAR_MIN 0
#define CHAR_MAX 127
#define MB_LEN_MAX 1
#define SHRT_MIN -32768
#define SHRT_MAX +32767
#define USHRT_MAX 65535
#define INT_MIN -32768
#define INT_MAX +32767
#define UINT_MAX 65535
#define LONG_MIN -2147483648
#define LONG_MAX +2147483647
#define ULONG_MAX 4294967295
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,91 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIB_PTHREAD_H
#define _WAMR_LIB_PTHREAD_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/* Data type define of pthread, mutex, cond and key */
typedef unsigned int pthread_t;
typedef unsigned int pthread_mutex_t;
typedef unsigned int pthread_cond_t;
typedef unsigned int pthread_key_t;
/* Thread APIs */
int
pthread_create(pthread_t *thread, const void *attr,
void *(*start_routine)(void *), void *arg);
int
pthread_join(pthread_t thread, void **retval);
int
pthread_detach(pthread_t thread);
int
pthread_cancel(pthread_t thread);
pthread_t
pthread_self(void);
void
pthread_exit(void *retval);
/* Mutex APIs */
int
pthread_mutex_init(pthread_mutex_t *mutex, const void *attr);
int
pthread_mutex_lock(pthread_mutex_t *mutex);
int
pthread_mutex_unlock(pthread_mutex_t *mutex);
int
pthread_mutex_destroy(pthread_mutex_t *mutex);
/* Cond APIs */
int
pthread_cond_init(pthread_cond_t *cond, const void *attr);
int
pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int
pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
uint64_t useconds);
int
pthread_cond_signal(pthread_cond_t *cond);
int
pthread_cond_broadcast(pthread_cond_t *cond);
int
pthread_cond_destroy(pthread_cond_t *cond);
/* Pthread key APIs */
int
pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
int
pthread_setspecific(pthread_key_t key, const void *value);
void *
pthread_getspecific(pthread_key_t key);
int
pthread_key_delete(pthread_key_t key);
#ifdef __cplusplus
}
#endif
#endif /* end of _WAMR_LIB_PTHREAD_H */

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STDARG_H
#define _WAMR_LIBC_STDARG_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _VA_LIST
typedef __builtin_va_list va_list;
#define _VA_LIST
#endif
#define va_start(ap, param) __builtin_va_start(ap, param)
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap, type) __builtin_va_arg(ap, type)
#define __va_copy(d, s) __builtin_va_copy(d, s)
#ifdef __cplusplus
}
#endif
#endif /* end of _WAMR_LIBC_STDARG_H */

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STDBOOL_H
#define _WAMR_LIBC_STDBOOL_H
#define __bool_true_false_are_defined 1
#ifndef __cplusplus
#define bool _Bool
#define false 0
#define true 1
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STDINT_H
#define _WAMR_LIBC_STDINT_H
#ifdef __cplusplus
extern "C" {
#endif
/* clang-format off */
typedef char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long long int int64_t;
/* Unsigned. */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
/* Minimum of signed integral types. */
# define INT8_MIN (-128)
# define INT16_MIN (-32767-1)
# define INT32_MIN (-2147483647-1)
# define INT64_MIN (-__INT64_C(9223372036854775807)-1)
/* Maximum of signed integral types. */
# define INT8_MAX (127)
# define INT16_MAX (32767)
# define INT32_MAX (2147483647)
# define INT64_MAX (__INT64_C(9223372036854775807))
/* Maximum of unsigned integral types. */
# define UINT8_MAX (255)
# define UINT16_MAX (65535)
# define UINT32_MAX (4294967295U)
# define UINT64_MAX (__UINT64_C(18446744073709551615))
/* clang-format on */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STDIO_H
#define _WAMR_LIBC_STDIO_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
typedef unsigned long size_t;
int
printf(const char *format, ...);
int
putchar(int c);
int
snprintf(char *str, size_t size, const char *format, ...);
int
sprintf(char *str, const char *format, ...);
int
puts(char *string);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STDLIB_H
#define _WAMR_LIBC_STDLIB_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long size_t;
int
atoi(const char *s);
void
exit(int status);
long
strtol(const char *nptr, char **endptr, register int base);
unsigned long
strtoul(const char *nptr, char **endptr, register int base);
void *
malloc(size_t size);
void *
calloc(size_t n, size_t size);
void
free(void *ptr);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STRING_H
#define _WAMR_LIBC_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long size_t;
int
memcmp(const void *s1, const void *s2, size_t n);
void *
memcpy(void *dest, const void *src, size_t n);
void *
memmove(void *dest, const void *src, size_t n);
void *
memset(void *s, int c, size_t n);
void *
memchr(const void *s, int c, size_t n);
int
strncasecmp(const char *s1, const char *s2, size_t n);
size_t
strspn(const char *s, const char *accept);
size_t
strcspn(const char *s, const char *reject);
char *
strstr(const char *s, const char *find);
char *
strchr(const char *s, int c);
int
strcmp(const char *s1, const char *s2);
char *
strcpy(char *dest, const char *src);
size_t
strlen(const char *s);
int
strncmp(const char *str1, const char *str2, size_t n);
char *
strncpy(char *dest, const char *src, unsigned long n);
char *
strdup(const char *s);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,17 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WAMR_LIBC_STRINGS_H
#define _WAMR_LIBC_STRINGS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -7,15 +7,15 @@ import * as vscode from 'vscode';
import * as os from 'os';
export class WasmDebugConfigurationProvider
implements vscode.DebugConfigurationProvider {
implements vscode.DebugConfigurationProvider
{
constructor() {}
/* default port set as 1234 */
private port = 1234;
private hostPath!: string;
private providerPromise:
| Thenable<vscode.DebugConfiguration>
| undefined = undefined;
private providerPromise: Thenable<vscode.DebugConfiguration> | undefined =
undefined;
private wasmDebugConfig!: vscode.DebugConfiguration;
@ -43,7 +43,6 @@ export class WasmDebugConfigurationProvider
['attachCommands']: [
'process connect -p wasm connect://127.0.0.1:' + port + '',
],
['sourceMap']: [['/mnt', hostPath]],
};
} else if (os.platform() === 'linux') {
this.wasmDebugConfig = {
@ -54,7 +53,6 @@ export class WasmDebugConfigurationProvider
['attachCommands']: [
'process connect -p wasm connect://127.0.0.1:' + port + '',
],
['sourceMap']: [['/mnt', hostPath]],
};
}
}

View File

@ -4,7 +4,7 @@
*/
import * as vscode from 'vscode';
import { ReadFromFile } from '../utilities/directoryUtilities';
import { ReadFromFile } from './utilities/directoryUtilities';
import * as path from 'path';
import * as os from 'os';

View File

@ -12,27 +12,29 @@ import { WasmTaskProvider } from './taskProvider';
import { TargetConfigPanel } from './view/TargetConfigPanel';
import { NewProjectPanel } from './view/NewProjectPanel';
import {
CheckIfDirectoryExist,
WriteIntoFile,
ReadFromFile,
WriteIntoFileAsync,
} from './utilities/directoryUtilities';
import { decorationProvider } from './explorer/decorationProvider';
import { WasmDebugConfigurationProvider } from './debug/debugConfigurationProvider';
import { decorationProvider } from './decorationProvider';
import { WasmDebugConfigurationProvider } from './debugConfigurationProvider';
let wasmTaskProvider: WasmTaskProvider;
let wasmDebugConfigProvider: WasmDebugConfigurationProvider;
var currentPrjDir = '';
var extensionPath = '';
var isWasmProject = false;
export async function activate(context: vscode.ExtensionContext) {
var OS_PLATFORM = '',
buildScript = '',
runScript = '',
debugScript = '',
destroyScript = '',
buildScriptFullPath = '',
runScriptFullPath = '',
debugScriptFullPath = '',
destroyScriptFullPath = '',
typeMap = new Map(),
/* include paths array used for written into config file */
includePathArr = new Array(),
@ -55,32 +57,35 @@ export async function activate(context: vscode.ExtensionContext) {
buildScript = scriptPrefix.concat('build.bat');
runScript = scriptPrefix.concat('run.bat');
debugScript = scriptPrefix.concat('boot_debugger_server.bat');
destroyScript = scriptPrefix.concat('destroy.bat');
} else if (OS_PLATFORM === 'linux') {
buildScript = scriptPrefix.concat('build.sh');
runScript = scriptPrefix.concat('run.sh');
debugScript = scriptPrefix.concat('boot_debugger_server.sh');
destroyScript = scriptPrefix.concat('destroy.sh');
}
/* get extension's path, and set scripts' absolute path */
extensionPath = context.extensionPath;
buildScriptFullPath = path.join(extensionPath, buildScript);
runScriptFullPath = path.join(extensionPath, runScript);
debugScriptFullPath = path.join(extensionPath, debugScript);
destroyScriptFullPath = path.join(extensionPath, destroyScript);
scriptMap.set('buildScript', buildScriptFullPath);
scriptMap.set('runScript', runScriptFullPath);
scriptMap.set('debugScript', debugScriptFullPath);
scriptMap.set('destroyScript', destroyScriptFullPath);
typeMap.set('Build', 'Build');
typeMap.set('Run', 'Run');
typeMap.set('Debug', 'Debug');
typeMap.set('Destroy', 'Destroy');
wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap);
vscode.tasks.registerTaskProvider('wasm', wasmTaskProvider);
/* set current project directory */
if (vscode.workspace.workspaceFolders?.[0]) {
if (OS_PLATFORM === 'win32') {
currentPrjDir = vscode.workspace.workspaceFolders?.[0].uri
@ -89,25 +94,70 @@ export async function activate(context: vscode.ExtensionContext) {
currentPrjDir = vscode.workspace.workspaceFolders?.[0].uri
.path as string;
}
}
/**
* check whether current project opened in vscode workspace is wasm project
* it not, `build`, `run` and `debug` will be disabled
*/
if (currentPrjDir !== '') {
let wamrFolder = fileSystem
.readdirSync(currentPrjDir, {
withFileTypes: true,
})
.filter(folder => folder.isDirectory() && folder.name === '.wamr');
/**
* check whether current project opened in vscode workspace is wasm project
* it not, `build`, `run` and `debug` will be disabled
*/
if (currentPrjDir !== '') {
let wamrFolder = fileSystem
.readdirSync(currentPrjDir, {
withFileTypes: true,
})
.filter(
folder => folder.isDirectory() && folder.name === '.wamr'
);
if (wamrFolder.length !== 0) {
vscode.commands.executeCommand(
'setContext',
'ext.isWasmProject',
true
);
if (wamrFolder.length !== 0) {
isWasmProject = true;
vscode.commands.executeCommand(
'setContext',
'ext.isWasmProject',
isWasmProject
);
if (
vscode.workspace
.getConfiguration()
.has('C_Cpp.default.systemIncludePath')
) {
let newIncludeInCppArr: string[] | undefined | null;
newIncludeInCppArr = vscode.workspace
.getConfiguration()
.get('C_Cpp.default.systemIncludePath');
let LibcBuiltinHeaderPath = path.join(
extensionPath,
'resource/wamr-sdk/libc-builtin-sysroot/include'
);
if (newIncludeInCppArr !== undefined) {
/* in case the configuration has not been set up, push directly */
if (newIncludeInCppArr === null) {
newIncludeInCppArr = new Array();
newIncludeInCppArr.push(LibcBuiltinHeaderPath);
} else {
/* if the configuration has been set up, check the condition */
if (
/* include libc-builtin-sysroot */
newIncludeInCppArr.indexOf(
LibcBuiltinHeaderPath
) < 0
) {
newIncludeInCppArr.push(LibcBuiltinHeaderPath);
}
}
vscode.workspace
.getConfiguration()
.update(
'C_Cpp.default.systemIncludePath',
newIncludeInCppArr,
vscode.ConfigurationTarget.Workspace
);
}
}
}
}
}
@ -163,6 +213,30 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}
});
} else if (!CheckIfDirectoryExist(curWorkspace as string)) {
vscode.window
.showWarningMessage(
'Invalid workspace:',
{
modal: true,
detail:
'' +
vscode.workspace
.getConfiguration()
.get('WAMR-IDE.configWorkspace') +
'',
},
_ok
)
.then(item => {
if (item === _ok) {
vscode.commands.executeCommand(
'wamride.changeWorkspace'
);
} else {
return;
}
});
} else {
NewProjectPanel.render(context);
}
@ -203,59 +277,220 @@ export async function activate(context: vscode.ExtensionContext) {
});
/* update workspace value to vscode global settings */
await vscode.workspace
.getConfiguration()
.update(
'WAMR-IDE.configWorkspace',
Workspace.trim(),
vscode.ConfigurationTarget.Global
)
.then(
success => {
vscode.window.showInformationMessage(
'Workspace has been set up successfully!'
);
},
error => {
vscode.window.showErrorMessage(
'Set up Workspace failed!'
);
}
);
if (Workspace !== '' && Workspace !== undefined) {
await vscode.workspace
.getConfiguration()
.update(
'WAMR-IDE.configWorkspace',
Workspace.trim(),
vscode.ConfigurationTarget.Global
)
.then(
success => {
vscode.window.showInformationMessage(
'Workspace has been set up successfully!'
);
},
error => {
vscode.window.showErrorMessage(
'Set up Workspace failed!'
);
}
);
}
}
);
let disposableBuild = vscode.commands.registerCommand(
'wamride.build',
() => {
generateCMakeFile(includePathArr, excludeFileArr);
if (!isWasmProject) {
vscode.window.showErrorMessage('Build failed', {
modal: true,
detail: 'Current project is not wasm project, please open wasm project and try again.',
});
return;
}
return vscode.commands.executeCommand(
'workbench.action.tasks.runTask',
'Build: Wasm'
);
generateCMakeFile(includePathArr, excludeFileArr);
/* destroy the wasm-toolchain-ctr if it exists */
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Destroy: Wasm-Container-Before-Build'
)
.then(() => {
let disposable = vscode.tasks.onDidEndTaskProcess(t => {
if (
t.execution.task.name ===
'Wasm-Container-Before-Build'
) {
if (t.exitCode !== 0) {
disposable.dispose();
return;
}
/* execute the build task */
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Build: Wasm'
)
.then(() => {
/* destroy the wasm-toolchain-ctr after building */
let disposable_aft =
vscode.tasks.onDidEndTask(a => {
if (
a.execution.task.name ===
'Wasm' &&
a.execution.task.source ===
'Build'
) {
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Destroy: Wasm-Container-After-Build'
)
.then(() => {
/* dispose the event after this building process
*/
disposable_aft.dispose();
});
}
});
});
/* dispose the event after this building process */
disposable.dispose();
}
});
});
}
);
let disposableDebug = vscode.commands.registerCommand(
'wamride.debug',
() => {
if (!isWasmProject) {
vscode.window.showErrorMessage('debug failed', {
modal: true,
detail: 'Current project is not wasm project, please open wasm project and try again.',
});
return;
}
/* refuse to debug if build process failed */
if (!checkIfBuildSuccess()) {
vscode.window.showErrorMessage('Debug failed', {
modal: true,
detail: 'Can not find WASM binary, please build WASM firstly.',
});
return;
}
/* show debug view */
vscode.commands.executeCommand('workbench.view.debug');
/* should destroy the wasm-debug-server-ctr before debugging */
vscode.commands
.executeCommand('workbench.action.tasks.runTask', 'Debug: Wasm')
.executeCommand(
'workbench.action.tasks.runTask',
'Destroy: Wasm-Container-Before-Debug'
)
.then(() => {
vscode.debug.startDebugging(
undefined,
wasmDebugConfigProvider.getDebugConfig()
);
/* execute the debug task when destroy task finish */
let disposable_bfr = vscode.tasks.onDidEndTask(t => {
if (
t.execution.task.name ===
'Wasm-Container-Before-Debug'
) {
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Debug: Wasm'
)
.then(() => {
vscode.debug
.startDebugging(
undefined,
wasmDebugConfigProvider.getDebugConfig()
)
.then(() => {
/* register to listen debug session finish event */
let dispose_aft =
vscode.debug.onDidTerminateDebugSession(
s => {
if (
s.type !==
'wamr-debug'
) {
return;
}
/* execute the task to destroy
* wasm-debug-server-ctr */
vscode.commands.executeCommand(
'workbench.action.tasks.runTask',
'Destroy: Wasm-Container-After-Debug'
);
/* execute the task to kill the terminal */
vscode.commands.executeCommand(
'workbench.action.terminal.kill',
'Debug: Wasm'
);
dispose_aft.dispose();
}
);
});
});
}
disposable_bfr.dispose();
});
});
}
);
let disposableRun = vscode.commands.registerCommand('wamride.run', () => {
return vscode.commands.executeCommand(
'workbench.action.tasks.runTask',
'Run: Wasm'
);
if (!isWasmProject) {
vscode.window.showErrorMessage('run failed', {
modal: true,
detail: 'Current project is not wasm project, please open wasm project and try again.',
});
return;
}
/* refuse to debug if build process failed */
if (!checkIfBuildSuccess()) {
vscode.window.showErrorMessage('Debug failed', {
modal: true,
detail: 'Can not find WASM binary, please build WASM firstly.',
});
return;
}
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Destroy: Wasm-Container-Before-Run'
)
.then(() => {
let dispose_bfr = vscode.tasks.onDidEndTaskProcess(e => {
if (e.execution.task.name === 'Wasm-Container-Before-Run') {
/* make sure that run wasm task will be executed after destroy task finish */
vscode.commands
.executeCommand(
'workbench.action.tasks.runTask',
'Run: Wasm'
)
.then(() => {
if (e.exitCode !== 0) {
dispose_bfr.dispose();
return;
}
});
dispose_bfr.dispose();
}
});
});
});
let disposableToggleIncludePath = vscode.commands.registerCommand(
@ -322,8 +557,10 @@ export async function activate(context: vscode.ExtensionContext) {
let disposableOpenFolder = vscode.commands.registerCommand(
'wamride.openFolder',
() => {
/* get projects list under current workspace */
let _ok = 'Set up now';
let _cancle = 'Maybe later';
let _create = 'Create now';
let curWorkspace = vscode.workspace
.getConfiguration()
.get('WAMR-IDE.configWorkspace') as string;
@ -345,6 +582,30 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}
});
} else if (!CheckIfDirectoryExist(curWorkspace as string)) {
vscode.window
.showWarningMessage(
'Invalid workspace:',
{
modal: true,
detail:
'' +
vscode.workspace
.getConfiguration()
.get('WAMR-IDE.configWorkspace') +
'',
},
_ok
)
.then(item => {
if (item === _ok) {
vscode.commands.executeCommand(
'wamride.changeWorkspace'
);
} else {
return;
}
});
} else {
/* get all directories within directory, ignore files */
let directoryArrDirent, directoryArr;
@ -354,7 +615,7 @@ export async function activate(context: vscode.ExtensionContext) {
});
} catch (err) {
vscode.window.showErrorMessage(
'Read from current workspace failed, please check.'
'Read projects from current workspace failed.'
);
}
@ -363,27 +624,52 @@ export async function activate(context: vscode.ExtensionContext) {
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
vscode.window
.showQuickPick(directoryArr, {
title: 'Select project',
placeHolder: 'Please select project',
})
.then(option => {
if (!option) {
return;
}
let projFilesArr = directoryArr.filter(obj => {
if (checkIfWasmProj(path.join(curWorkspace, obj))) {
return true;
}
});
let _path = curWorkspace.concat(
OS_PLATFORM === 'win32'
? '\\'
: OS_PLATFORM === 'linux'
? '/'
: '',
option
);
if (projFilesArr.length === 0) {
vscode.window
.showWarningMessage(
'Current workspace is empty, please create your project firstly.',
_create,
_cancle
)
.then(item => {
if (item === _create) {
vscode.commands.executeCommand(
'wamride.newProject'
);
} else {
return;
}
});
} else {
vscode.window
.showQuickPick(projFilesArr, {
title: 'Select project',
placeHolder: 'Please select project',
})
.then(option => {
if (!option) {
return;
}
openWindoWithSituation(vscode.Uri.file(_path));
});
let _path = curWorkspace.concat(
OS_PLATFORM === 'win32'
? '\\'
: OS_PLATFORM === 'linux'
? '/'
: '',
option
);
/* open the selected wasm project */
openWindoWithSituation(vscode.Uri.file(_path));
});
}
}
}
}
@ -438,11 +724,15 @@ export function writeIntoConfigFile(
excludeFileArr: string[],
buildArgs?: BuildArgs
) {
let jsonStr = JSON.stringify({
include_paths: includePathArr,
exclude_files: excludeFileArr,
build_args: buildArgs ? buildArgs : '{}',
});
let jsonStr = JSON.stringify(
{
include_paths: includePathArr,
exclude_files: excludeFileArr,
build_args: buildArgs ? buildArgs : '{}',
},
null,
'\t'
);
let prjConfigDir = path.join(currentPrjDir, '.wamr');
let configFilePath = path.join(prjConfigDir, 'compilation_config.json');
@ -595,3 +885,44 @@ function getAllSrcFiles(_path: string) {
vscode.window.showErrorMessage(error as string);
}
}
function checkIfBuildSuccess(): Boolean {
try {
let wasmExist = false;
const entries = fileSystem.readdirSync(
path.join(currentPrjDir, 'build'),
{
withFileTypes: true,
}
);
entries.map(e => {
if (e.name.match('(.wasm)$')) {
wasmExist = true;
}
});
return wasmExist;
} catch {
return false;
}
}
function checkIfWasmProj(_path: string): Boolean {
try {
let isWasmProj = false;
const entries = fileSystem.readdirSync(_path, {
withFileTypes: true,
});
entries.map(e => {
if (e.isDirectory() && e.name === '.wamr') {
isWasmProj = true;
}
});
return isWasmProj;
} catch {
return false;
}
}

View File

@ -7,13 +7,6 @@ import * as vscode from 'vscode';
import * as os from 'os';
import { TargetConfigPanel } from './view/TargetConfigPanel';
interface WasmTaskDefinition extends vscode.TaskDefinition {
/**
* The build flavor.
*/
flavor: string;
}
export interface OwnShellOption {
cmd: string;
options: vscode.ShellExecutionOptions;
@ -28,115 +21,189 @@ export class WasmTaskProvider implements vscode.TaskProvider {
buildShellOption: OwnShellOption | undefined;
runShellOption: OwnShellOption | undefined;
debugShellOption: OwnShellOption | undefined;
destroyShellOption: OwnShellOption | undefined;
private wasmPromise: Thenable<vscode.Task[]> | undefined = undefined;
public provideTasks(): Thenable<vscode.Task[]> | undefined {
let targetName =
TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
if (!this.wasmPromise) {
/* target name is used for generated aot target */
let targetName =
TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
if (os.platform() === 'linux') {
/* build */
this.buildShellOption = {
cmd: 'bash',
options: {
executable: this._script.get('buildScript'),
shellArgs: [targetName],
},
};
if (os.platform() === 'linux' || os.platform() === 'win32') {
/* build */
this.buildShellOption = {
cmd:
os.platform() === 'linux'
? 'bash'
: (this._script.get('buildScript') as string),
options: {
executable: this._script.get('buildScript'),
shellArgs: [targetName, os.platform()],
},
};
/* debug */
this.debugShellOption = {
cmd: 'bash',
options: {
executable: this._script.get('debugScript'),
shellArgs: [targetName],
},
};
/* debug */
this.debugShellOption = {
cmd:
os.platform() === 'linux'
? 'bash'
: (this._script.get('debugScript') as string),
options: {
executable: this._script.get('debugScript'),
shellArgs: [targetName],
},
};
/* run */
this.runShellOption = {
cmd: 'bash',
options: {
executable: this._script.get('runScript'),
shellArgs: [targetName],
},
};
} else if (os.platform() === 'win32') {
this.buildShellOption = {
cmd: this._script.get('buildScript') as string,
options: {
executable: this._script.get('buildScript'),
shellArgs: [targetName],
},
};
/* debug */
this.debugShellOption = {
cmd: this._script.get('debugScript') as string,
options: {
executable: this._script.get('debugScript'),
shellArgs: [targetName],
},
};
/* run */
this.runShellOption = {
cmd: this._script.get('runScript') as string,
options: {
executable: this._script.get('runScript'),
shellArgs: [targetName],
},
};
} else {
this.buildShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
/* run */
this.runShellOption = {
cmd:
os.platform() === 'linux'
? 'bash'
: (this._script.get('runScript') as string),
options: {
executable: this._script.get('runScript'),
shellArgs: [targetName],
},
};
this.debugShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
/* destroy */
/* run */
this.destroyShellOption = {
cmd:
os.platform() === 'linux'
? 'bash'
: (this._script.get('destroyScript') as string),
options: {
executable: this._script.get('destroyScript'),
shellArgs: [targetName],
},
};
} else {
this.buildShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
this.runShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
this.debugShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
this.runShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
this.destroyShellOption = {
cmd: "echo 'os platform is not supported yet'",
options: {},
};
}
this.wasmPromise = Promise.resolve([
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Build') as string,
new vscode.ShellExecution(
this.buildShellOption.cmd,
this.buildShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Run') as string,
new vscode.ShellExecution(
this.runShellOption.cmd,
this.runShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Debug') as string,
new vscode.ShellExecution(
this.debugShellOption.cmd,
this.debugShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-Before-Build',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-Before-Debug',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-Before-Run',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-After-Build',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-After-Debug',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm-Container-After-Run',
this._type.get('Destroy') as string,
new vscode.ShellExecution(
this.destroyShellOption.cmd,
this.destroyShellOption.options
)
),
]);
}
this.wasmPromise = Promise.resolve([
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Build') as string,
new vscode.ShellExecution(
this.buildShellOption.cmd,
this.buildShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Run') as string,
new vscode.ShellExecution(
this.runShellOption.cmd,
this.runShellOption.options
)
),
new vscode.Task(
{ type: 'wasm' },
vscode.TaskScope.Workspace,
'Wasm',
this._type.get('Debug') as string,
new vscode.ShellExecution(
this.debugShellOption.cmd,
this.debugShellOption.options
)
),
]);
return this.wasmPromise;
}

View File

@ -81,3 +81,16 @@ export function WriteIntoFileAsync(
return;
}
}
export function CheckIfDirectoryExist(path: string): boolean {
try {
if (fileSystem.existsSync(path)) {
return true;
} else {
return false;
}
} catch (err) {
vscode.window.showErrorMessage(err as string);
return false;
}
}

View File

@ -6,7 +6,6 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import { readFromConfigFile, writeIntoConfigFile } from '../extension';
import { getUri } from '../utilities/getUri';
@ -151,26 +150,6 @@ export class TargetConfigPanel {
'configbuildtarget.js',
]);
/* get config build target values and set into webview page */
let configData, buildArgObj;
let _output_file_name,
_init_memory_size,
_max_memory_size,
_stack_size,
_exported_symbols;
if (readFromConfigFile() !== '') {
configData = JSON.parse(readFromConfigFile());
buildArgObj = configData['build_args'];
if (buildArgObj !== undefined) {
_output_file_name = buildArgObj['output_file_name'];
_init_memory_size = buildArgObj['init_memory_size'];
_max_memory_size = buildArgObj['max_memory_size'];
_stack_size = buildArgObj['stack_size'];
_exported_symbols = buildArgObj['exported_symbols'];
}
}
const resourcePath = path.join(extensionUri.fsPath, templatePath);
let html = fs.readFileSync(resourcePath, 'utf-8');
html = html
@ -179,23 +158,23 @@ export class TargetConfigPanel {
.replace(/(\${styleUri})/, styleUri.toString())
.replace(
/(\${output_file_val})/,
_output_file_name === undefined ? '' : _output_file_name
TargetConfigPanel.BUILD_ARGS.output_file_name
)
.replace(
/(\${initial_mem_size_val})/,
_init_memory_size === undefined ? '' : _init_memory_size
TargetConfigPanel.BUILD_ARGS.init_memory_size
)
.replace(
/(\${max_mem_size_val})/,
_max_memory_size === undefined ? '' : _max_memory_size
TargetConfigPanel.BUILD_ARGS.max_memory_size
)
.replace(
/(\${stack_size_val})/,
_stack_size === undefined ? '' : _stack_size
TargetConfigPanel.BUILD_ARGS.stack_size
)
.replace(
/(\${exported_symbols_val})/,
_exported_symbols === undefined ? '' : _exported_symbols
TargetConfigPanel.BUILD_ARGS.exported_symbols
);
return html;

View File

@ -0,0 +1,21 @@
### Build Docker Image
- Linux
```shell
chmod +x resource/*
./build_docker_image.sh
```
- Windows
```shell
./build_docker_image.bat
```
### Resource Details
- `Dockerflie` is the source file to build `wasm-debug-server` docker image
- `resource/debug.sh` is the script to execute the wasm app in debug mod, will start up the debugger server inside of the `iwasm` and hold to wait for connecting.
- `resource/run.sh` is the script to execute the wasm app directly.

View File

@ -5,4 +5,4 @@
docker build -t wasm-debug-server:1.0 .
@REM delete intermediate docker image
sudo docker image prune -f
docker image prune -f

View File

@ -5,4 +5,4 @@
docker build -t wasm-debug-server:1.0 .
# delete intermediate docker image
sudo docker image prune -f
docker image prune -f

View File

@ -1,15 +0,0 @@
### Build Docker Image
- execute `build_docker_image.bat` on `Windows`
- execute `build_docker_image.sh` on `Linux`
```shell
chmod +x resource/*
./build_docker_image.sh
```
### Resource Details
- `Dockerflie` is the source file to build `wasm-debug-server` docker image
- `resource/debug.sh` is the script to execute the `/mnt/build/${target}.wasm` in debug mode, will start up the debugger server inside of the `iwasm` and hold to wait for connecting.
- `resource/run.sh` is the script to execute the `/mnt/build/${target}.wasm` directly.

View File

@ -1,4 +0,0 @@
# move unnecessary files here to save build time cost and image size
*.md
*.sh
*.bat

View File

@ -1,71 +0,0 @@
# WASM Toolchain Provider Introduction
## Files on HOST
#### Dockerfile
- ubuntu : 20.04
- set up the necessary toolchains
- WASI-SDK (version: 12.0)
- WAMR-SDK
- repo: bytecode-alliance/wasm-micro-runtime
- branch: main
- LLVM (latest repo build)
- CMake (version: 3.21.1)
#### build_docker_image.sh
- the script to build docker image for Linux platform
- tag: 1.0
#### build_docker_image.bat
- the script to build docker image for windows platform
- tag: 1.0
#### run_container.sh
- the script to start and run the docker container for Linux platform
- mount `host directory` and `container directory`
- temporally using `$(pwd)/host_mnt_test` in **host** and `/mnt` in **container**
- set docker container name with `--name`
- temporally set to _wasm-toolchain-ctr_
#### run_container.bat
- the script to start and run the docker container for windows platform
## Files inside docker
### `wamrc`
### `wasi-sdk`
# Build Docker Image
- Linux
```shell
chmod +x resource/*
./build_docker_image.sh
```
- Windows
```shell
./build_docker_image.bat
```
# Run Docker Container
- Linux
```shell
./run_container.sh
```
- Windows
```shell
./run_container.bat
```

View File

@ -1,24 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
export CC=/opt/wasi-sdk/bin/clang
export CXX=/opt/wasi-sdk/bin/clang++
if [ -d /mnt/build ];then
rm -fr /mnt/build
fi
mkdir -p /mnt/build
cd /mnt/build/
echo "========> compile wasm with wasi-sdk"
cmake ../.wamr && make
echo && echo
echo "========> compile wasm to AoT with wamrc"
# target name will be provided:
# - user input the target name in IDE
# - generated wasm binary name will be set as user's input target name
# - aot binary name should be the same as wasm binary name
# - target name will be provided through 1st parameter
wamrc -o $1.aot $1.wasm

View File

@ -1,16 +0,0 @@
@REM Copyright (C) 2019 Intel Corporation. All rights reserved.
@REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@echo off
@REM # create mount directory on host
if not exist host_mnt (
md host_mnt
)
docker run -it ^
-v %cd%\host_mnt:/mnt ^
--name wasm-toolchain-provider-ctr ^
wasm-toolchain-provider:1.0 ^
/bin/bash

View File

@ -1,15 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
set -x
# create mount directory on host
if [ ! -d host_mnt ];then
mkdir host_mnt
fi
sudo docker run --name=wasm-toolchain-provider-ctr \
-it -v $(pwd)/host_mnt:/mnt \
wasm-toolchain-provider:1.0 \
/bin/bash

View File

@ -0,0 +1,4 @@
# remove unnecessary files here to save build time cost and image size
*.md
*.sh
*.bat

View File

@ -1,7 +1,7 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
## Build docker image that consists of gcc, cmake, wasi-sdk
## Build docker image that consists of gcc, cmake, wasi-sdk & zephyr sdk
FROM gcc:9.3.0 AS BASE
## set work directory
@ -9,11 +9,6 @@ WORKDIR /root/
COPY resource /root/
## set compilation environment for wamrc
# - cmake
# - wasi-sdk
# - wamr-sdk
## - download cmake with wget and set up
RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-linux-x86_64.tar.gz \
&& tar -zxvf cmake-3.21.1-linux-x86_64.tar.gz \
@ -22,15 +17,22 @@ RUN wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1
&& ln -s /opt/cmake/bin/cmake /bin/cmake \
&& apt-get install make
## - download wasi-sdk with wget and set up to /opt/wasi-sdk
RUN wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz \
&& tar -zxvf wasi-sdk-12.0-linux.tar.gz \
&& rm -f wasi-sdk-12.0-linux.tar.gz
## set compilation environment for wamrc
# - wamr repo
# - cmake
# - wasi-sdk
# - wamr-sdk
## - download wasi-sdk with wget and set up to /opt/wasi-sdk
RUN wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-14/wasi-sdk-14.0-linux.tar.gz \
&& tar -zxvf wasi-sdk-14.0-linux.tar.gz \
&& mv wasi-sdk-14.0 /opt/wasi-sdk/ \
&& rm -f wasi-sdk-14.0-linux.tar.gz
## - clone wamr repo
RUN git clone -b main --depth=1 https://github.com/bytecodealliance/wasm-micro-runtime.git \
&& cd /root/wasm-micro-runtime/wamr-compiler \
&& ./build_llvm.sh \
# - build wamrc
&& cd /root/wasm-micro-runtime/wamr-compiler \
&& mkdir build \
&& cd build \
@ -38,26 +40,31 @@ RUN git clone -b main --depth=1 https://github.com/bytecodealliance/wasm-micro-r
&& make \
# - copy the wamrc to /root
&& cp /root/wasm-micro-runtime/wamr-compiler/build/wamrc /root/wamrc \
&& mkdir -p /opt/wamr-sdk/app \
&& cp -r /root/wasm-micro-runtime/wamr-sdk/app/libc-builtin-sysroot /opt/wamr-sdk/app/ \
&& mkdir -p /opt/wamr-sdk \
&& cp -r /root/wasm-micro-runtime/wamr-sdk/app /opt/wamr-sdk/ \
&& mv /root/wamr_toolchain.cmake /opt/wamr-sdk/app \
# - remove the wamr repo to save the size
&& rm -fr /root/wasm-micro-runtime
## STAGE 2
# ## STAGE 2
FROM ubuntu:20.04
ENV HOME_DIR=/home/wasm-toolchain
RUN mkdir -p /opt/wasi-sdk \
&& mkdir -p /opt/cmake \
&& mkdir -p /opt/wamr-sdk/app
&& mkdir -p /opt/cmake \
&& mkdir -p /opt/wamr-sdk/app \
&& mkdir -p /home/wasm-toolchain
# COPY files from BASE image
COPY --from=BASE /opt/cmake/ /opt/cmake/
COPY --from=BASE /opt/wamr-sdk/app/ /opt/wamr-sdk/app/
COPY --from=BASE /root/wasi-sdk-12.0/ /opt/wasi-sdk/
COPY --from=BASE /root/wamrc /root
COPY --from=BASE /root/build_wasm.sh /root
COPY --from=BASE /opt/wasi-sdk /opt/wasi-sdk/
COPY --from=BASE /root/wamrc ${HOME_DIR}
COPY --from=BASE /root/build_wasm.sh ${HOME_DIR}
RUN ln -s /opt/cmake/bin/cmake /usr/bin/cmake \
&& ln -s /root/wamrc /usr/bin/wamrc
&& ln -s ${HOME_DIR}/wamrc /usr/bin/wamrc
RUN apt-get update && apt-get install make
WORKDIR /root
WORKDIR ${HOME_DIR}

View File

@ -0,0 +1,19 @@
### Build Docker Image
- Linux
```shell
chmod +x resource/*
./build_docker_image.sh
```
- Windows
```shell
./build_docker_image.bat
```
### Resource Details
- `Dockerflie` is the source file to build `wasm-debug-server` docker image.
- `resource/build_wasm.sh` is the script to compile the wasm app with `wasi-sdk`.

View File

@ -6,7 +6,7 @@
@REM pull gcc and ubuntu image firstly no matter whether exist or not.
docker pull gcc:9.3.0
docker pull ubuntu:20.04
docker build -t wasm-toolchain-provider:1.0 .
docker build -t wasm-toolchain:1.0 .
@REM delete intermediate docker image
sudo docker image prune -f
docker image prune -f

View File

@ -2,9 +2,9 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
sudo docker pull gcc:9.3.0
sudo docker pull ubuntu:20.04
sudo docker build -t wasm-toolchain-provider:1.0 .
docker pull gcc:9.3.0
docker pull ubuntu:20.04
docker build -t wasm-toolchain:1.0 .
# delete intermediate docker image
sudo docker image prune -f
docker image prune -f

View File

@ -0,0 +1,25 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/bin/bash
export CC=/opt/wasi-sdk/bin/clang
export CXX=/opt/wasi-sdk/bin/clang++
cd /mnt
if [ -d build ];then
rm -fr build
fi
mkdir -p build && cd build
echo "========> compile wasm with wasi-sdk"
cmake -DWASI_SDK_DIR=/opt/wasi-sdk -DCMAKE_TOOLCHAIN_FILE=/opt/wamr-sdk/app/wamr_toolchain.cmake ../.wamr && make
if [ $? -eq 0 ]; then
echo "========> compile wasm to AoT with wamrc"
# target name will be provided:
# - user input the target name in IDE
# - generated wasm binary name will be set as user's input target name
# - aot binary name should be the same as wasm binary name
# - target name will be provided through 1st parameter
wamrc -o $1.aot $1.wasm
fi

View File

@ -0,0 +1,33 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
SET (CMAKE_SYSTEM_NAME Linux)
SET (CMAKE_SYSTEM_PROCESSOR wasm32)
SET (CMAKE_SYSROOT ${CMAKE_CURRENT_LIST_DIR}/libc-builtin-sysroot)
IF (NOT (DEFINED WASI_SDK_DIR OR DEFINED CACHE{WASI_SDK_DIR}))
SET (WASI_SDK_DIR "/opt/wasi-sdk")
ELSE ()
MESSAGE (STATUS "WASI_SDK_DIR=${WASI_SDK_DIR}")
LIST (APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES "WASI_SDK_DIR")
ENDIF ()
SET (CMAKE_C_FLAGS "-nostdlib" CACHE INTERNAL "")
SET (CMAKE_C_COMPILER_TARGET "wasm32")
SET (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
SET (CMAKE_CXX_FLAGS "-nostdlib" CACHE INTERNAL "")
SET (CMAKE_CXX_COMPILER_TARGET "wasm32")
SET (CMAKE_CXX_COMPILER "${WASI_SDK_DIR}/bin/clang++")
SET (CMAKE_EXE_LINKER_FLAGS
"-Wl,--no-entry,--fatal-warnings" CACHE INTERNAL "")
SET (CMAKE_LINKER "${WASI_SDK_DIR}/bin/wasm-ld" CACHE INTERNAL "")
SET (CMAKE_AR "${WASI_SDK_DIR}/bin/llvm-ar" CACHE INTERNAL "")
SET (CMAKE_NM "${WASI_SDK_DIR}/bin/llvm-nm" CACHE INTERNAL "")
SET (CMAKE_OBJDUMP "${WASI_SDK_DIR}/bin/llvm-dwarfdump" CACHE INTERNAL "")
SET (CMAKE_RANLIB "${WASI_SDK_DIR}/bin/llvm-ranlib" CACHE INTERNAL "")
SET (CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS},--allow-undefined-file=${CMAKE_SYSROOT}/share/defined-symbols.txt" CACHE INTERNAL "")