|
1 | | -# Rust SGX - Template project |
2 | | -================================== |
| 1 | +# NTC - WASM component |
3 | 2 |
|
4 | | -### This is a template project to start developing with the Rust SGX SDK (https://github.com/apache/incubator-teaclave-sgx-sdk/) easily. |
| 3 | +### Requirements |
5 | 4 |
|
6 | | -You will find in its template: |
7 | | -- Makefiles to build your project easily, and link the ```SGX EDL C``` generated files to your Rust SGX projects |
8 | | -- The file ```buildenv.mk``` that contains compilation rules when building enclave. No need to specify anymore where this file is located. |
9 | | -- The file ```build.rs``` already configured to build the app/host part properly. |
10 | | -- The file rust-toolchain, so we can force the use of one specific toolchain (```nightly-2020-10-25``` in this case) |
11 | | -- ```Cargo/Xargo.toml``` files to set up your project easily. All the dependencies you might need has been added. |
| 5 | +- Operating system: |
| 6 | + - Recommended: Ubuntu 20.04 (LTS) |
| 7 | +- Packages: |
| 8 | + - `make` |
| 9 | + - `clang` (recommended) or `gcc` |
| 10 | + - `cmake` |
| 11 | + - `autoconf` |
| 12 | + - `libtool` |
| 13 | +- Snaps: |
| 14 | + - `docker` |
| 15 | +- Rust toolchain: |
| 16 | + - See [#rust-ecosystem] |
12 | 17 |
|
13 | | -You can find those files in this template: |
| 18 | +### Rust ecosystem |
14 | 19 |
|
| 20 | +Install `rustup` as described at [rustup.rs](https://rustup.rs/). If you did |
| 21 | +not explicitly select `nightly` as your default toolchain then do so now |
15 | 22 | ``` |
16 | | -|-- app/ |
17 | | -| |-- src/ |
18 | | -| |-- main.rs |
19 | | -| |-- Cargo.toml |
20 | | -| |-- Makefile |
21 | | -| |-- build.rs |
22 | | -| +-- rust-toolchain |
23 | | -|-- enclave/ |
24 | | -| |-- src/ |
25 | | -| |-- lib.rs |
26 | | -| |-- Cargo.toml |
27 | | -| |-- Enclave.config.xml |
28 | | -| |-- Enclave.edl |
29 | | -| |-- Enclave.lds |
30 | | -| |-- Makefile |
31 | | -| |-- Xargo.toml |
32 | | -| +-- rust-toolchain |
33 | | -|-- Makefile |
34 | | -+-- buildenv.mk |
| 23 | +$ rustup install nightly |
| 24 | +``` |
| 25 | +followed by |
| 26 | +``` |
| 27 | +$ rustup default nightly |
35 | 28 | ``` |
36 | 29 |
|
37 | | -## Setting up your project |
| 30 | +You will now have the `cargo` build tool, as well as the nigtly `rustc` compiler |
| 31 | +installed on your system and may now continue setting up your environment. |
38 | 32 |
|
39 | | -You need to follow a few steps to use this template properly: |
40 | | -- Add your ```.rs``` files to the ```src/``` folders (```lib.rs``` / your enclave source code goes in ```enclave/src```, your host/app source code goes in ```app/src```), or modify the ```.rs``` files already included with the project |
41 | | -- Add your own ```Enclave.edl``` file, or modify the one joined in the project. |
42 | | -- Change the ```Cargo.toml (or/and Xargo.toml if you want to use Xargo)``` files depending on of your needs (adding/removing dependencies). |
43 | | - - Be careful if you want to change the library name on the ```Cargo.toml``` file (enclave part), you will need to reflect this change on the enclave ```Makefile```, more specifically on the ```ENCLAVE_CARGO_LIB``` variable, and on the ```lib.rs``` file. |
44 | | - - If you need to change the app/host name, please make sure to edit the host ```Makefile```, and change the variable ```APP_U```. |
| 33 | +### Environment |
45 | 34 |
|
46 | | -## Build your project |
| 35 | +**NOTE:** If you opted to install `gcc` as your compiler, make sure you run |
| 36 | +``` |
| 37 | +export CC=gcc; export CXX=g++ |
| 38 | +``` |
| 39 | +Otherwise you may safely continue. |
47 | 40 |
|
48 | | -### Before starting the building process, please make sure you downloaded the Rust SGX SDK repository, we're going to need the EDL and headers files joined in the SDK. |
| 41 | +The Rust and Intel SGX SDKs need to be installed and the |
| 42 | +relevant environment variables need to be set. In order to facilitate this, we |
| 43 | +use the convenience scripts provided at [rust-sgx-sdk-env]. |
49 | 44 |
|
50 | | -Once you downloaded the Rust SGX SDK, you have multiple ways to start the building process: |
51 | | -- Run this command: ```CUSTOM_EDL_PATH=~/teaenclave/edl CUSTOM_COMMON_PATH=~/teaenclave/common make``` (replace ```~/teaenclave``` by the actual SDK location) |
52 | | -- You can also run the command export (```export CUSTOM_EDL_PATH=~/teaenclave/edl```), and specify the variables before calling make. It is advised to add this command on your ```.bashrc``` file (if you use bash), or your favorite shell configuration file. |
| 45 | +1. Make sure the `docker` daemon is running, otherwise start it with |
| 46 | + ``` |
| 47 | + $ systemctl start snap.docker.dockerd |
| 48 | + ``` |
| 49 | +2. In order to run the scripts as a non-root user, follow the |
| 50 | + [docker-postinstall](post-installation instructions) set out in the Docker |
| 51 | + documentation (note, in particular, that a restart may be necessary). |
| 52 | +3. Clone the repository at [rust-sgx-sdk-env] |
| 53 | + ``` |
| 54 | + $ git clone https://github.com/PiDelport/rust-sgx-sdk-dev-env |
| 55 | + ``` |
| 56 | + and `cd` into it. |
| 57 | +4. Run the latest "prepare" script: |
| 58 | + ``` |
| 59 | + $ ./prepare-1.1.14-intel-2.15.1.sh |
| 60 | + ``` |
| 61 | +5. Finally, assuming `bash` is the current shell, source the environment file in |
| 62 | + the top level of the repository: |
| 63 | + ``` |
| 64 | + $ source environment |
| 65 | + ``` |
53 | 66 |
|
54 | | -### By default, your project will be compiled in hardware mode. If you wish to compile your project in software/simulation mode, you will need to specify it, either by adding ```SGX_MODE=SW``` before make, or by setting the SGX_MODE variable environment to SW. |
| 67 | +### Instructions |
55 | 68 |
|
56 | | -### Cargo is used by default when compiling, but you can also use Xargo either by adding ```XARGO_SGX=1``` before make, or by setting the XARGO_SGX variable environment to 1. You will also need to specify Xargo library path with XARGO_PATH. |
| 69 | +1. Before proceeding, make sure your [environment is set up](#environment) |
| 70 | + properly. |
| 71 | +2. Clone the project repository |
| 72 | + ``` |
| 73 | + $ git clone https://github.com/ntls-io/wasm-exec-sgx |
| 74 | + ``` |
| 75 | + and `cd` into it. |
| 76 | +3. Run `make all` to compile the entire project. |
| 77 | +4. To run the main application, change to bin/ and execute the following: |
| 78 | + ``` |
| 79 | + ./app |
| 80 | + ``` |
| 81 | +5. In order to test the provided Wasm binary, change the current directory to |
| 82 | + the `wasmi-impl` subdirectory and execute the following: |
| 83 | + ``` |
| 84 | + cargo test |
| 85 | + ``` |
57 | 86 |
|
58 | | -### The makefile has those commands available: |
59 | | -- make (will compile everything) |
60 | | -- make host (will only compile the host part) |
61 | | -- make enclave (will only compile the enclave part) |
62 | | -- make clean (will clean the objects/C edl files generated) |
63 | | -- make clean_host (will clean the objects/C edl files generated for the host only) |
64 | | -- make clean_enclave (will clean the objects/C edl files generated for the enclave only) |
65 | | -- make fclean (will clean objects/C edl files and the binaries, plus calling cargo clean for everything) |
66 | | -- make fclean_host (will clean objects/C edl files and the binaries, plus calling cargo clean for the host only) |
67 | | -- make fclean_enclave (will clean objects/C edl files and the binaries, plus calling cargo clean for the enclave only) |
68 | | -- make re (re as relink, will clean everything then compile everything again) |
69 | | -- make re_host (re as relink, will clean the host part then compile it again) |
70 | | -- make re_enclave (re as relink, will clean the enclave part then compile it again) |
| 87 | +[docker-postinstall]: https://docs.docker.com/engine/install/linux-postinstall/ |
| 88 | +[rust-sgx-sdk-env]: https://github.com/PiDelport/rust-sgx-sdk-dev-env |
0 commit comments