commit | 1c5d81135779aaee128bc588d067f076b9209771 | [log] [tgz] |
---|---|---|
author | Renato Mangini Dias <mangini@google.com> | Tue Mar 29 00:40:32 2022 +0000 |
committer | Renato Mangini Dias <mangini@google.com> | Fri Apr 01 22:55:56 2022 +0000 |
tree | 896194d511730bb55be23cad4c29bef23e67d299 | |
parent | 98a7ae21a154433081fe94dd259321101da42149 [diff] |
Add the echo sample Change-Id: Icbeb44fa8af3788d276365087b964116fd8e0b57
This repository contains instructions and source code to build, package and run Fuchsia samples using only the Fuchsia SDK.
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.
Make sure this repository has the required submodules:
git submodule update --recursive --init
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"
Now the repository is ready to build the samples.
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.
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
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
(optional) watch the device log in a separate window
tools/ffx log
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.
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.
Run tests
tools/ffx test run fuchsia-pkg://fuchsiasamples.com/hello_test#meta/hello_test.cm