Skip to content

Commit 015c0f9

Browse files
committed
examples: reorganize crates into TA and CA workspaces
* Split the examples into dedicated TA and CA Cargo workspaces and consolidate the protocol definitions into a single proto crate. * Centralize the workspace build rules, relocate plugin assets, and update tests, documentation, license exclusions, and cargo-optee paths for the new layout. * Reuse workspace build artifacts across cargo-optee CI builds, report their disk usage, and clean them after the complete build.
1 parent f76348c commit 015c0f9

454 files changed

Lines changed: 5412 additions & 7517 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ Cargo.lock
2424

2525
rust/
2626

27-
# Allow tracking Cargo.lock in std examples
28-
!examples/message_passing_interface-rs/ta/Cargo.lock
29-
!examples/secure_db_abstraction-rs/ta/Cargo.lock
30-
!examples/serde-rs/ta/Cargo.lock
31-
!examples/tls_client-rs/ta/Cargo.lock
32-
!examples/tls_server-rs/ta/Cargo.lock
27+
# Allow tracking the consolidated examples workspace lock files
28+
!examples/ta/Cargo.lock
29+
!examples/ca/Cargo.lock
3330
!projects/web3/eth_wallet/ta/Cargo.lock
3431

3532
# Allow tracking Cargo.lock for cargo-optee tool

.licenserc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ header:
3030
- 'KEYS'
3131
- 'DISCLAIMER'
3232
- '**/*.json'
33-
- 'examples/tls_server-rs/ta/test-ca/**'
33+
- 'examples/ta/tls_server-rs/test-ca/**'
3434
- '**/uuid.txt'
3535
- '**/plugin_uuid.txt'
3636
- '**/ta_uuid.txt'

LICENSE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@
202202
limitations under the License.
203203

204204
-------------------------------------------------------------------------------
205-
This product includes the following third-party code:
206-
The code in `examples/tls_client-rs/ta/src/main.rs` is modified based on
205+
This product includes the following third-party code:
206+
The code in `examples/ta/tls_client-rs/src/main.rs` is modified based on
207207
Rustls (Apache License, Version 2.0).
208-
The code in `examples/mnist-rs/ta/train/src/trainer.rs` and
209-
`examples/mnist-rs/ta/common/src/model.rs` is either copied from or inspired by
208+
The code in `examples/ta/mnist-rs/train/src/trainer.rs` and
209+
`examples/ta/mnist-rs/common/src/model.rs` is either copied from or inspired by
210210
the Burn library (Apache License, Version 2.0).
211211

212212
For the full text of the licenses, see the `licenses/` directory.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ std-examples no-std-examples:
7373
install: examples
7474
$(echo) ' INSTALL ${out-dir}/lib/optee_armtz'
7575
$(q)mkdir -p ${out-dir}/lib/optee_armtz
76-
$(q)find examples/*/ta/target/$(TARGET_TA)/ -name *.ta -exec cp {} ${out-dir}/lib/optee_armtz \;
76+
$(q)find examples/ta/target/$(TARGET_TA)/ -name *.ta -exec cp {} ${out-dir}/lib/optee_armtz \;
7777
$(echo) ' INSTALL ${out-dir}${bindir}'
7878
$(q)mkdir -p ${out-dir}${bindir}
79-
$(q)cp examples/*/host/target/$(TARGET_HOST)/release/*-rs ${out-dir}${bindir}
79+
$(q)cp examples/ca/target/$(TARGET_HOST)/release/*-rs ${out-dir}${bindir}
8080
$(echo) ' INSTALL ${out-dir}${libdir}/tee-supplicant/plugins/'
8181
$(q)mkdir -p ${out-dir}${libdir}/tee-supplicant/plugins/
82-
$(q)find examples/*/plugin/target/$(TARGET_HOST)/ -name *.plugin.so -exec cp {} ${out-dir}${libdir}/tee-supplicant/plugins/ \;
82+
$(q)find examples/ca/target/$(TARGET_HOST)/ -name *.plugin.so -exec cp {} ${out-dir}${libdir}/tee-supplicant/plugins/ \;
8383

8484
clean: examples-clean out-clean
8585

@@ -96,4 +96,4 @@ help:
9696
@echo " no-std-examples - Build no-std examples (no-std-only + common)"
9797
@echo " install - Install built examples to out directory"
9898
@echo " clean - Clean all examples and output directory"
99-
@echo ""
99+
@echo ""

ci/build.sh

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,6 @@ for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
249249
fi
250250

251251
CURRENT=$((CURRENT + 1))
252-
EXAMPLE_DIR="$EXAMPLES_DIR/$EXAMPLE_NAME"
253-
254-
if [ ! -d "$EXAMPLE_DIR" ]; then
255-
echo "ERROR: Example directory not found: $EXAMPLE_DIR"
256-
FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME"
257-
continue
258-
fi
259-
260252
echo ""
261253
echo "=========================================="
262254
echo "[$CURRENT] Building: $EXAMPLE_NAME ($CATEGORY)"
@@ -311,8 +303,6 @@ for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
311303
--arch "$ARCH_TA" \
312304
$TA_STD_FLAG; then
313305
echo " ✓ TA installed successfully"
314-
# Clean up build artifacts
315-
$CARGO_OPTEE clean
316306
else
317307
echo " ✗ ERROR: Failed to install TA: $TA_DIR"
318308
FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($TA_DIR)"
@@ -358,8 +348,6 @@ for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
358348
--optee-client-export "$OPTEE_CLIENT_EXPORT" \
359349
--arch "$ARCH_HOST"; then
360350
echo " ✓ CA installed successfully"
361-
# Clean up build artifacts
362-
$CARGO_OPTEE clean
363351
else
364352
echo " ✗ ERROR: Failed to install CA: $CA_DIR"
365353
FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($CA_DIR)"
@@ -404,8 +392,6 @@ for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
404392
--optee-client-export "$OPTEE_CLIENT_EXPORT" \
405393
--arch "$ARCH_HOST"; then
406394
echo " ✓ Plugin installed successfully"
407-
# Clean up build artifacts
408-
$CARGO_OPTEE clean
409395
else
410396
echo " ✗ ERROR: Failed to install Plugin: $PLUGIN_DIR"
411397
FAILED_EXAMPLES="$FAILED_EXAMPLES\n - $EXAMPLE_NAME ($PLUGIN_DIR)"
@@ -423,6 +409,31 @@ for EXAMPLE_NAME in "${ALL_EXAMPLES[@]}"; do
423409
echo "✓ Example $EXAMPLE_NAME completed successfully"
424410
done
425411

412+
echo ""
413+
echo "==========================================="
414+
echo " WORKSPACE TARGET DISK USAGE"
415+
echo "==========================================="
416+
417+
TARGET_DIRS=()
418+
if [ -d "$EXAMPLES_DIR/ta/target" ]; then
419+
TARGET_DIRS+=("$EXAMPLES_DIR/ta/target")
420+
fi
421+
if [ -d "$EXAMPLES_DIR/ca/target" ]; then
422+
TARGET_DIRS+=("$EXAMPLES_DIR/ca/target")
423+
fi
424+
425+
if [ "${#TARGET_DIRS[@]}" -gt 0 ]; then
426+
du -sch "${TARGET_DIRS[@]}"
427+
else
428+
echo "No workspace target directories were created."
429+
fi
430+
431+
echo ""
432+
echo "Cleaning workspace build artifacts..."
433+
cargo clean --manifest-path "$EXAMPLES_DIR/ta/Cargo.toml"
434+
cargo clean --manifest-path "$EXAMPLES_DIR/ca/Cargo.toml"
435+
echo "Workspace build artifacts cleaned successfully."
436+
426437
# Summary
427438
echo ""
428439
echo "==========================================="
@@ -448,4 +459,3 @@ else
448459
echo "✅ ALL EXAMPLES INSTALLED SUCCESSFULLY!"
449460
echo ""
450461
fi
451-

docs/building-rust-ca-as-android-elf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ clean:
6363
7. build:
6464

6565
```
66-
$ make -C examples/hello_world-rs/host
66+
$ make -C examples/ca/hello_world-rs
6767
```

docs/debugging-optee-ta.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ D/LD: ldelf:168 ELF (133af0ca-bdab-11eb-9130-43bf7873bf67) at 0x40014000
4646

4747
Then, you can load symbols from TA file (in debug build) to the address.
4848
```sh
49-
(gdb) add-symbol-file /path/to/examples/hello_world-rs/ta/target/aarch64-unknown-linux-gnu/debug/ta 0x40014000
49+
(gdb) add-symbol-file /path/to/examples/ta/target/aarch64-unknown-linux-gnu/debug/ta 0x40014000
5050
```
5151
Now, you can add breakpoints according to your own needs in the corresponding
5252
functions or addresses.

docs/writing-rust-tas-using-optee-utee-build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ include!(concat!(env!("OUT_DIR"), "/user_ta_header.rs"));
4949

5050
After that, everything finished, we can start building the TA now.
5151

52-
For full codes, you can check the [`hello_world-rs example`](https://github.com/apache/teaclave-trustzone-sdk/tree/main/examples/hello_world-rs/ta)
52+
For full codes, you can check the [`hello_world-rs example`](https://github.com/apache/teaclave-trustzone-sdk/tree/main/examples/ta/hello_world-rs)
5353

5454
## Explaination of Minimal Example
5555

examples/Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ TARGET_TA ?= $(TARGET)
2525
FEATURES ?=
2626
CARGO_FLAGS ?=
2727

28+
# All CA crates and all TA crates now share their respective workspace target
29+
# directories. Do not run multiple per-example Cargo commands concurrently,
30+
# because they may link or clean the same workspace artifacts at the same time.
31+
# Cargo still parallelizes compilation within each individual invocation.
32+
.NOTPARALLEL:
33+
2834
# Define example categories based on std/no-std support
2935
# STD-only examples (require STD=y to build)
3036
STD_ONLY_EXAMPLES = \
@@ -83,20 +89,23 @@ common-examples: $(COMMON_EXAMPLES)
8389

8490
# Individual example build rules
8591
$(STD_ONLY_EXAMPLES) $(NO_STD_ONLY_EXAMPLES) $(COMMON_EXAMPLES):
86-
$(q)make -C $@ TARGET_HOST=$(TARGET_HOST) \
87-
TARGET_TA=$(TARGET_TA) \
88-
CROSS_COMPILE_HOST=$(CROSS_COMPILE_HOST) \
89-
CROSS_COMPILE_TA=$(CROSS_COMPILE_TA) \
92+
$(q)make -C ca/$@ TARGET=$(TARGET_HOST) \
93+
CROSS_COMPILE=$(CROSS_COMPILE_HOST) \
94+
OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT)
95+
$(q)make -C ta/$@ TARGET=$(TARGET_TA) \
96+
CROSS_COMPILE=$(CROSS_COMPILE_TA) \
9097
TA_DEV_KIT_DIR=$(TA_DEV_KIT_DIR) \
91-
OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT) \
9298
FEATURES="$(FEATURES)" \
9399
CARGO_FLAGS="$(CARGO_FLAGS)"
100+
$(if $(filter supp_plugin-rs,$@),$(q)make -C ca/supp_plugin-rs-plugin TARGET=$(TARGET_HOST) CROSS_COMPILE=$(CROSS_COMPILE_HOST) OPTEE_CLIENT_EXPORT=$(OPTEE_CLIENT_EXPORT))
94101

95102
# Clean targets
96103
clean: $(STD_ONLY_EXAMPLES_CLEAN) $(NO_STD_ONLY_EXAMPLES_CLEAN) $(COMMON_EXAMPLES_CLEAN)
97104

98105
$(STD_ONLY_EXAMPLES_CLEAN) $(NO_STD_ONLY_EXAMPLES_CLEAN) $(COMMON_EXAMPLES_CLEAN):
99-
$(q)make -C $(@:-clean=) clean
106+
$(q)make -C ca/$(@:-clean=) clean
107+
$(q)make -C ta/$(@:-clean=) clean
108+
$(if $(filter supp_plugin-rs-clean,$@),$(q)make -C ca/supp_plugin-rs-plugin clean)
100109

101110
# Help target
102111
help:

examples/acipher-rs/Makefile

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)