Add the echo sample

Change-Id: Icbeb44fa8af3788d276365087b964116fd8e0b57
9 files changed
tree: 896194d511730bb55be23cad4c29bef23e67d299
  1. src/
  2. third_party/
  3. tools/
  4. .bazelrc
  5. .gitignore
  6. .gitmodules
  7. AUTHORS
  8. CONTRIBUTING.md
  9. LICENSE
  10. OWNERS
  11. PATENTS
  12. README.md
  13. WORKSPACE.bazel
README.md

Fuchsia samples using the Fuchsia SDK

This repository contains instructions and source code to build, package and run Fuchsia samples using only the Fuchsia SDK.

Requirements

  1. Install Bazel version 4.x or later by following the instructions at https://bazel.build/install. In some Linux distributions, sudo apt-get install bazel should be enough.

  2. Make sure this repository has the required submodules:

    git submodule update --recursive --init
    
  3. Ensure that there are Fuchsia SSH keys in your host machine. You will need them for running the Fuchsia emulator.

     [[ -f "${HOME}/.ssh/fuchsia_ed25519" ]] || ssh-keygen -P "" -t ed25519 -f "${HOME}/.ssh/fuchsia_ed25519" -C "${USER}@$(hostname -f) Shared SSH Key for Fuchsia"
    
     [[ -f "${HOME}/.ssh/fuchsia_authorized_keys" ]] || ssh-keygen -y -f "${HOME}/.ssh/fuchsia_ed25519" > "${HOME}/.ssh/fuchsia_authorized_keys"
    

Build, run and test the samples

Now the repository is ready to build the samples.

  1. Build the samples:

    bazel build --config=fuchsia_x64 src:samples_repository
    

    This command will build all the samples and make them available as packages on a local Fuchsia repository.

  2. Fetch an emulator image and start an emulator

    tools/ffx product-bundle get workstation.qemu-x64
    tools/ffx emu start --net tap workstation.qemu-x64
    

    Note: product-bundle currently does not download the ephemeral packages, including the test_manager package that is needed to run tests. Temporarily, you need to perform the extra instructions below:

    mkdir -p product_bundle_pkgs && gsutil cat gs://fuchsia/development/$(tools/ffx sdk version)/packages/workstation.qemu-x64-release.tar.gz | tar xzf - -C product_bundle_pkgs
    tools/ffx repository add-from-pm -r fuchsia.com product_bundle_pkgs/amber-files
    tools/ffx target repository register -r fuchsia.com
    
  3. Register the samples package repository

    tools/ffx repository add-from-pm -r fuchsiasamples.com bazel-bin/src/fuchsiasamples.com.repo
    tools/ffx target repository register -r fuchsiasamples.com
    
  4. (optional) watch the device log in a separate window

    tools/ffx log
    
  5. Run a hello world component

    tools/ffx component run fuchsia-pkg://fuchsiasamples.com/hello_world#meta/hello_world.cm --recreate
    

    Watch in the log that the message “Hello, World!” is printed. Modify the Hello world message in src/hello_world/hello_world.cc, repeat steps 1 and 3, and see that the log shows the new message.

  6. Run the echo sample

    tools/ffx component run fuchsia-pkg://fuchsiasamples.com/echo-example#meta/echo.cm --recreate
    

    Watch in the log that the message “Hello, Alice, Bob, Spot!” is printed. Modify the FAVORITE_ANIMAL environment variable in src/echo/meta/echo.cml, repeat steps 1 and 3 and see that the log shows the new message.

  7. Run tests

    tools/ffx test run fuchsia-pkg://fuchsiasamples.com/hello_test#meta/hello_test.cm