Skip to content

Conversation

@DemesneGH
Copy link
Contributor

This PR reorganizes the Makefiles under examples/.

Currently, we have 26 examples (and more in the future). Updating each example's Makefile individually makes maintenance and review difficult. Since most Makefile logic is shared, this PR centralizes common definitions under examples/mk/:

  • examples-root.mk
  • host.mk — for CAs and plugins
  • common-ta.mk
  • std-ta.mk
  • no-std-ta.mk

The Makefiles design is suitable for this directory layout of each example:

example/
├── host/
│   ├── host1/
│   │   └── Makefile    # includes host.mk
│   └── host2/
│       └── Makefile
├── plugin/              # example with one plugin app, can be multiple apps like in the host/
│   ├── src/
│   └── Makefile         # includes host.mk
├── ta/
│   ├── ta1/
│   │   └── Makefile     # includes common-ta.mk or std-ta.mk or no-std-ta.mk
│   └── ta2/
│       └── Makefile
├── Makefile              # includes examples-root.mk
└── uuid.txt              # TA UUID

Our all examples are fit for this structure: Most of examples have one host and one TA;
Some examples (e.g., supp_plugin-rs, mnist-rs) override certain variables (such as location of uuid.txt) to fit specific needs. The Makefile variables are designed to be easily overridden for such cases.

Please pay special attention when reviewing the examples/mk/*, supp_plugin-rs and mnist-rs.

Future Work

This is the first step in cleaning up and unifying our Makefile structure.
With this reorganization, future Makefile updates can be made more consistently and reviewed more easily.

In the dev docker environment, the examples/mk path can be written as a constant include path used by each separate examples.

@ivila
Copy link
Contributor

ivila commented Oct 22, 2025

Instead of struggling with Makefiles, I suggest replacing them entirely with something integrated into the Cargo ecosystem — something that feels more “Rust-like.”

Currently, the Makefile helps us accomplish the following:

  1. Build the binary with a specific linker (ARM or AArch64, for both CA and TA).
  2. Build the binary with a specific builder (cargo or xargo, for TA only).
  3. Occasionally build the binary with extra flags.
  4. Strip the output binary (for both CA and TA — though I think it’s unnecessary for CA since it runs in the REE, where code size doesn’t really matter).
  5. Sign the TA (for TA only).

I’ve considered replacing it with tools like cargo-make or cargo-xtask, but neither feels elegant enough:

  • cargo-make requires writing a Makefile.toml, which is essentially the same as what we’re already doing, but worse.
  • cargo-xtask needs a config.toml under each project, which also feels cumbersome.

So I started thinking: maybe we could introduce a new binary that handles the entire workflow seamlessly.
For example, we could create a cargo-teaclave-trustzone crate that provides a cargo teaclave-trustzone command.

Then, developers could use it like this:

  1. When building the CA
    Developers simply run cargo teaclave-trustzone ca build.
    This would automatically build the CA with the appropriate linker.
    If they want to strip the binary, they can use an option like cargo teaclave-trustzone ca build --strip.
  2. When building the TA
    Developers run cargo teaclave-trustzone ta build.
    For STD builds, they could add a flag such as cargo teaclave-trustzone ta build --std.

@m4sterchain
Copy link
Contributor

Instead of struggling with Makefiles, I suggest replacing them entirely with something integrated into the Cargo ecosystem — something that feels more “Rust-like.”

Currently, the Makefile helps us accomplish the following:

  1. Build the binary with a specific linker (ARM or AArch64, for both CA and TA).

  2. Build the binary with a specific builder (cargo or xargo, for TA only).

  3. Occasionally build the binary with extra flags.

  4. Strip the output binary (for both CA and TA — though I think it’s unnecessary for CA since it runs in the REE, where code size doesn’t really matter).

  5. Sign the TA (for TA only).

I’ve considered replacing it with tools like cargo-make or cargo-xtask, but neither feels elegant enough:

  • cargo-make requires writing a Makefile.toml, which is essentially the same as what we’re already doing, but worse.

  • cargo-xtask needs a config.toml under each project, which also feels cumbersome.

So I started thinking: maybe we could introduce a new binary that handles the entire workflow seamlessly.

For example, we could create a cargo-teaclave-trustzone crate that provides a cargo teaclave-trustzone command.

Then, developers could use it like this:

  1. When building the CA

    Developers simply run cargo teaclave-trustzone ca build.

    This would automatically build the CA with the appropriate linker.

    If they want to strip the binary, they can use an option like cargo teaclave-trustzone ca build --strip.

  2. When building the TA

    Developers run cargo teaclave-trustzone ta build.

    For STD builds, they could add a flag such as cargo teaclave-trustzone ta build --std.

This might be helpful. Please take a look and take into comparison.
https://crates.io/crates/cargo-sgx

@DemesneGH
Copy link
Contributor Author

Thanks for all the input! I think it makes sense to replace the current make setup with a Cargo-based tool (e.g. named as cargo-optee). Let's start experimenting with this approach.

We can introduce a few subcommands, for example:

  • cargo optee new — create a example template

  • cargo optee build — build CA and TA with appropriate parameters

  • cargo optee emulate — sync outputs to the emulator’s shared directory

We can start by experimenting with one example and try to implement the build command at the first stage.

@DemesneGH
Copy link
Contributor Author

I've opened a draft PR: #245 about this, please feel free to share the feedback, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants