tree: fe4a360ed568529382b77b8916aae747eb006afd [path history] [tgz]
  1. fidl/
  2. rust/
  3. BUILD.gn
  4. README.md
examples/fidl/calculator/README.md

Calculator example

Reviewed on 2022-05-12

This directory contains the necessary Fuchsia components to run a client/server implementation of a calculator.

The main goals of this example are to:

  • Demonstrate communicating between Fuchsia components using FIDL.
  • Demonstrate FIDL best practices.
  • Be realistic, even if it means more complex code.

Building

The build steps differ slightly depending on if you‘re using the rust or c++ version of the code. Both are functionally the same, so use the language you’re most familiar with or interested in.

Rust

To add this project to your build, append the following to your fx set invocation:

fx set workstation.qemu-x64\
    --with //examples/fidl/calculator:all\
    --with //examples/fidl/calculator:tests

and then build:

fx build

C++

TODO(fxbug.dev/103280)

Running

Start the emulator and package server.

  1. start the emulator:
ffx emu start --headless workstation.qemu-x64
  1. start the package server:
fx serve-updates

After the emulator & package server are running, the instructions differ based on language.

Rust

Between, client, server, fidl, and realm, all necessary services are provided to run a simple calculator on Fuchsia.

To run these components together add calculator-example-rust to the ffx-laboratory:

ffx component create /core/ffx-laboratory:calculator-example-rust \
    fuchsia-pkg://fuchsia.com/calculator-example-rust#meta/realm.cm

and then start the component:

ffx component start /core/ffx-laboratory:calculator-example-rust
ffx component start /core/ffx-laboratory:calculator-example-rust/client

To see the output, use ffx log:

ffx log --filter calculator

Testing

There are tests for both the client and server. The command for running tests differs slightly depending on the language used.

Rust

Client

To run the client tests, ensure you have an available Fuchsia target (ex: ffx emu start) and are serving packages (ex: fx serve-updates) then run the following:

fx test calculator-client-rust-unittests

Server

To run the server tests, ensure you have an available Fuchsia target (ex: ffx emu start) and are serving packages (ex: fx serve-updates) then run the following:

fx test calculator-server-rust-unittests

C++

TODO

Source Layout

The source is split into four parts:

  1. fidl - defines the calculator FIDL protocol.
  2. [realm] - wires up the FIDL, client, and server components together.
  3. client - connects to a calculator FIDL protocol implementation and sends requests.
  1. server - implements the calculator FIDL protocol and receives requests.