blob: 5899ebd10663bcf1a62d202352207c02625ae965 [file] [log] [blame] [view]
# Hello World Example
The Hello, World sample introduces a Fuchsia component that prints "Hello, world"
messages to the system log.
The `BUILD.gn` file contains rules that demonstrate building a single binar
with shared and static libraries as dependencies.
## Source layout
- `hello.cc`: Main entrypoint for the component binary
- `hello_shared`: Shared library exposing functions to retrieve a greeting
- `hello_static`: Static library exposing functions to retrieve a greeting
## Before you begin
1. Start an emulator instance:
```
$ ./third_party/fuchsia-sdk/tools/x64/ffx product-bundle get workstation_eng.qemu-x64
$ ./third_party/fuchsia-sdk/tools/x64/ffx emu start workstation_eng.qemu-x64
```
1. Start a local package repository instance:
```
$ ./third_party/fuchsia-sdk/tools/x64/fserve --image workstation_eng.qemu-x64-release
```
## Build the sample
1. Run the build script to compile and package the sample:
```
$ ./scripts/build.sh
```
1. Publish the FAR packages to your local package repository:
```
$ ./third_party/fuchsia-sdk/tools/x64/fpublish out/x64/hello_world.far
$ ./third_party/fuchsia-sdk/tools/x64/fpublish out/x64/hello_world_test.far
```
## Run the sample
1. Launch the sample component using `ffx component run`. This resolves the
component from the package repository and starts it:
```
$ ./third_party/fuchsia-sdk/tools/x64/ffx component run fuchsia-pkg://fuchsia.com/hello_world#meta/hello_world.cm
```
1. View the greeting messages in the system log using `ffx log`:
```
$ ./third_party/fuchsia-sdk/tools/x64/ffx log --filter hello_world
...
[hello_world][I] pthreads: hello
[hello_world][I] Hello, world
[hello_world][I] cppthreads: hello
```
## Run the unit tests
1. Execute the unit test suite using `ffx test run`. This resolves the
component from the package repository and executes the tests:
```
$ ./third_party/fuchsia-sdk/tools/x64/ffx test run fuchsia-pkg://fuchsia.com/hello_world_test#meta/hello_world_test.cm
```
1. Verify that the test cases pass:
```
Running test 'fuchsia-pkg://fuchsia.com/hello_world_test#meta/hello_world_test.cm'
[RUNNING] HelloWorldTest.True
[stdout - HelloWorldTest.True]
Running main() from ../../third_party/googletest/src/googletest/src/gtest_main.cc
[PASSED] HelloWorldTest.True
1 out of 1 tests passed...
fuchsia-pkg://fuchsia.com/hello_world_test#meta/hello_world_test.cm completed with result: PASSED
```