commit | ed8280dbc64c8d15b4ab07355717e62ad7e7d7c3 | [log] [tgz] |
---|---|---|
author | Renato Mangini Dias <mangini@google.com> | Fri Dec 02 00:57:29 2022 +0000 |
committer | Renato Mangini Dias <mangini@google.com> | Fri Dec 02 00:57:29 2022 +0000 |
tree | 07f00749b2a6de1cb239143afcc35b6bca578f28 | |
parent | b5fe47c0bf66d60f861cb6ea18c432ffbef2e723 [diff] |
Add platform selection to .bazelrc based on --config In recent CLs, if_fuchsia was changed to rely on the platform definition, which works fine if the target has a platform transition like fuchsia_package or fuchsia_cc_binary, or if the user explicitly specifies `--platforms=@rules_fuchsia//fuchsia/constraints/platforms:fuchsia_x64` However, we have not fully migrated to platforms, and specifying the crosstool_top and cpu is still required. So, in order to build a target that does not go through a forced transition, the user would need to specify both `--config=fuchsia_*` and `--platforms=...`, which is very verbose. This CL adds the appropriate `--platforms=` to .bazelrc, so `--config=fuchsia_x64` sets both cpu, crosstool and platforms. It is not ideal though because AFAICT it makes it impossible to build for the host while using these --config options, unless if the target has a platform transition. But since our focus on the sdk-samples for now is to build for the Fuchsia target, I believe this should be ok until we fully transition to platform and remove the requirement of using cpu and crosstool. Fixed: 116517 Change-Id: I1fbc255887a57bcaa4719aa7e6785c549991d57e Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-samples/getting-started/+/769587 Reviewed-by: Chase Latta <chaselatta@google.com> Reviewed-by: Wayne Piekarski <waynepie@google.com> Reviewed-by: Renato Mangini Dias <mangini@google.com>
This repository contains instructions and source code to build, package and run Fuchsia samples using only the Fuchsia SDK.
Make sure this repository has the required submodules:
git submodule update --recursive --init
Run the bootstrap script that downloads the appropriate Bazel binary:
scripts/bootstrap.sh
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.
Fetch the system images
tools/ffx product-bundle get workstation_eng.qemu-x64 --repository workstation-packages
Note: if the product-bundle command above fails with an error message that states that there are multiple product bundles with the same name, you can either specify the fully qualified URL as printed in the error message that corresponds to your SDK version (use
tools/ffx sdk version
if needed), or you can wipe out old and unused product bundles in the pbms storage, which should be located in ~/.local/share/Fuchsia/ffx/pbms on Linux, or ~/Library/Fuchsia/ffx/pbms on MacOS.
Start the emulator
tools/ffx emu start workstation_eng.qemu-x64 --headless
The product bundle comes with on-demand packages in a separate repository. Use the following command to register it with the emulator:
tools/ffx target repository register -r workstation-packages --alias fuchsia.com --alias chromium.org
(optional) watch the device log in a separate window
tools/ffx log
Run a hello world component
tools/bazel run --config=fuchsia_x64 src/hello_world:pkg.component
Watch in the log that the message “Hello, World!” is printed. Modify the Hello world message in src/hello_world/hello_world.cc, repeat this step and see that the log shows the new message.
Run the echo sample
tools/bazel run --config=fuchsia_x64 src/echo:pkg.component
Watch the message “Hello, Alice, Bob, Spot!” in the log. Modify the FAVORITE_ANIMAL environment variable in src/echo/meta/echo.cml, repeat this step and see that the log shows the new message.
Run unit tests for samples
tools/bazel test --config=fuchsia_x64 src/hello_world:test_pkg tools/bazel test --config=fuchsia_x64 src/echo:test_pkg