Add IDE helper script (#539)
diff --git a/docs/development-tips.md b/docs/development-tips.md
index ea1b199..afa2f76 100644
--- a/docs/development-tips.md
+++ b/docs/development-tips.md
@@ -19,14 +19,23 @@
ways to workaround and let the analyzer understand the project structures.
When developing SGX enclaves and corresponding dependent crates, you need to
-prepare a `Cargo.toml` in the root directory to help the analyzer. This
-`Cargo.toml` file can be copied from our build system:
-`cmake/tomls/Cargo.sgx_trusted_lib.toml`. Similarly, when developing the app
-parts, you can copy the `cmake/tomls/Cargo.sgx_untrusted_lib.toml` file to the
-root directory as `Cargo.toml`. For standalone Rust applications such as CLI, no
-`Cargo.toml` is needed. After the preparation of `Cargo.toml` in root,
-RLS/rust-analyzer can understand the projects finally. You will see type hints
-and cross references using IDEs with extensions.
+prepare set of cargo files in the root directory to help the analyzer. This
+includes `Cargo.toml` which can be copied from our build system:
+`cmake/tomls/Cargo.sgx_trusted_lib.toml`; `Cargo.lock` which can be copied from
+`third_party/crates-sgx/Cargo.lock`; `.cargo/config` which can be copied from
+`third_party/crates-sgx/config`. Similarly, when developing the app parts, you
+can copy the `cmake/tomls/Cargo.sgx_untrusted_lib.toml` file to the root
+directory as `Cargo.toml`, and `.cargo/config` and `Cargo.lock` files can be
+found in `third_party/crates-io/` directory. For standalone Rust applications
+such as CLI, no `Cargo.toml` is needed. After the preparation of `Cargo.toml` in
+root, RLS/rust-analyzer can understand the projects finally. You will see type
+hints and cross references using IDEs with extensions.
+
+::: tip NOTE
+You can also simply use the script `scripts/ide.sh <trusted|untrusted|clean>`
+to prepare a IDE-friendly developing environment for trusted
+part, untrusetd part, or remove the files generated by this script.
+:::
## Logging
diff --git a/scripts/ide.sh b/scripts/ide.sh
new file mode 100755
index 0000000..7794322
--- /dev/null
+++ b/scripts/ide.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+TRUSTED_TOML="cmake/tomls/Cargo.sgx_trusted_lib.toml"
+UNTRUSTED_TOML="cmake/tomls/Cargo.sgx_untrusted_app.toml"
+TOML_DEST="Cargo.toml"
+
+TRUSTED_LOCK="third_party/crates-sgx/Cargo.lock"
+UNTRUSTED_LOCK="third_party/crates-io/Cargo.lock"
+LOCK_DEST="Cargo.lock"
+
+TRUSTED_CONFIG="third_party/crates-sgx/config"
+UNTRUSTED_CONFIG="third_party/crates-io/config"
+CONFIG_DEST=".cargo/config"
+
+script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
+teaclave_root=${script_dir}/..
+
+copy() {
+ # $1: TOML
+ # $2: LOCK
+ # $3: CONFIG
+ mkdir ${teaclave_root}/.cargo
+ cp $1 ${teaclave_root}/${TOML_DEST}
+ cp $2 ${teaclave_root}/${LOCK_DEST}
+ cp $3 ${teaclave_root}/${CONFIG_DEST}
+}
+
+clean() {
+ # clean the IDE helper files for Rust
+ rm ${teaclave_root}/${TOML_DEST}
+ rm ${teaclave_root}/${LOCK_DEST}
+ rm ${teaclave_root}/${CONFIG_DEST}
+ rm -r ${teaclave_root}/.cargo
+}
+
+main() {
+
+ if [ $1 = "trusted" ]; then
+ clean 2>/dev/null
+ copy $TRUSTED_TOML $TRUSTED_LOCK $TRUSTED_CONFIG
+ elif [ $1 = "untrusted" ]; then
+ clean 2>/dev/null
+ copy $UNTRUSTED_TOML $UNTRUSTED_LOCK $UNTRUSTED_CONFIG
+ elif [ $1 = "clean" ]; then
+ clean
+ else
+ echo "Usage: ./ide.sh <trusted|untrusted|clean>"
+ return 1
+ fi
+
+ return 0
+}
+
+main $*