1*61c4878aSAndroid Build Coastguard Worker.. _docs-get-started-upstream: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker============================================= 4*61c4878aSAndroid Build Coastguard WorkerGet started with upstream Pigweed development 5*61c4878aSAndroid Build Coastguard Worker============================================= 6*61c4878aSAndroid Build Coastguard WorkerThis guide will walk you through the typical upstream development workflow. 7*61c4878aSAndroid Build Coastguard Worker"Upstream development" means that you're contributing to the main Pigweed 8*61c4878aSAndroid Build Coastguard Workerrepository, ``https://pigweed.googlesource.com/pigweed/pigweed``. See 9*61c4878aSAndroid Build Coastguard Worker:ref:`docs-get-started` if you're looking for instructions on how to use 10*61c4878aSAndroid Build Coastguard WorkerPigweed in your own project. 11*61c4878aSAndroid Build Coastguard Worker 12*61c4878aSAndroid Build Coastguard Worker.. _prerequisites: 13*61c4878aSAndroid Build Coastguard Worker 14*61c4878aSAndroid Build Coastguard WorkerPrerequisites 15*61c4878aSAndroid Build Coastguard Worker============= 16*61c4878aSAndroid Build Coastguard WorkerIf you haven't already, :ref:`docs-first-time-setup`. 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard Worker------------- 19*61c4878aSAndroid Build Coastguard WorkerExpress setup 20*61c4878aSAndroid Build Coastguard Worker------------- 21*61c4878aSAndroid Build Coastguard WorkerIf you'd like to skip the detailed explanations, below is the shorter version 22*61c4878aSAndroid Build Coastguard Workerof getting setup for Pigweed. If you run into trouble, ensure you've followed 23*61c4878aSAndroid Build Coastguard Workerall the steps to :ref:`docs-first-time-setup`. The express setup 24*61c4878aSAndroid Build Coastguard Workerconfigures Pigweed's watcher for three targets to give a taste of Pigweed: 25*61c4878aSAndroid Build Coastguard Worker 26*61c4878aSAndroid Build Coastguard Worker#. **Host** - Mac, Linux, or Windows. Builds and runs tests 27*61c4878aSAndroid Build Coastguard Worker#. **Device/STM32F429** - Build only; Optionally, the STM32F429I-DISC1 kit to 28*61c4878aSAndroid Build Coastguard Worker follow along later in the guide to run tests directly on said device(s) 29*61c4878aSAndroid Build Coastguard Worker#. **Docs** - Builds the Pigweed docs 30*61c4878aSAndroid Build Coastguard Worker 31*61c4878aSAndroid Build Coastguard WorkerTo get setup: 32*61c4878aSAndroid Build Coastguard Worker 33*61c4878aSAndroid Build Coastguard Worker#. Make sure you have Git and Python installed and on your path. 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard Worker#. Clone Pigweed and bootstrap the environment (compiler setup & more). **Be 36*61c4878aSAndroid Build Coastguard Worker patient, this step downloads ~1GB of LLVM, GCC, and other tooling**. 37*61c4878aSAndroid Build Coastguard Worker 38*61c4878aSAndroid Build Coastguard Worker .. code-block:: bash 39*61c4878aSAndroid Build Coastguard Worker 40*61c4878aSAndroid Build Coastguard Worker $ cd ~ 41*61c4878aSAndroid Build Coastguard Worker $ git clone https://pigweed.googlesource.com/pigweed/pigweed 42*61c4878aSAndroid Build Coastguard Worker ... 43*61c4878aSAndroid Build Coastguard Worker $ cd pigweed 44*61c4878aSAndroid Build Coastguard Worker $ source ./bootstrap.sh (On Linux & Mac) 45*61c4878aSAndroid Build Coastguard Worker $ bootstrap.bat (On Windows) 46*61c4878aSAndroid Build Coastguard Worker ... 47*61c4878aSAndroid Build Coastguard Worker 48*61c4878aSAndroid Build Coastguard Worker .. tip:: 49*61c4878aSAndroid Build Coastguard Worker 50*61c4878aSAndroid Build Coastguard Worker If you use the `Fish shell <https://fishshell.com/>`_ run `source 51*61c4878aSAndroid Build Coastguard Worker ./bootstrap.fish` instead. 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard Worker#. Configure the GN build. 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker .. code-block:: bash 56*61c4878aSAndroid Build Coastguard Worker 57*61c4878aSAndroid Build Coastguard Worker $ gn gen out 58*61c4878aSAndroid Build Coastguard Worker Done. Made 1047 targets from 91 files in 114ms 59*61c4878aSAndroid Build Coastguard Worker 60*61c4878aSAndroid Build Coastguard Worker#. Start the watcher. The watcher will invoke Ninja to build all the targets 61*61c4878aSAndroid Build Coastguard Worker 62*61c4878aSAndroid Build Coastguard Worker .. code-block:: bash 63*61c4878aSAndroid Build Coastguard Worker 64*61c4878aSAndroid Build Coastguard Worker $ pw watch 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄ 67*61c4878aSAndroid Build Coastguard Worker ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌ 68*61c4878aSAndroid Build Coastguard Worker ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌ 69*61c4878aSAndroid Build Coastguard Worker ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌ 70*61c4878aSAndroid Build Coastguard Worker ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀ 71*61c4878aSAndroid Build Coastguard Worker 72*61c4878aSAndroid Build Coastguard Worker 20200707 17:24:06 INF Starting Pigweed build watcher 73*61c4878aSAndroid Build Coastguard Worker 20200707 17:24:06 INF Will build [1/1]: out 74*61c4878aSAndroid Build Coastguard Worker 20200707 17:24:06 INF Attaching filesystem watcher to $HOME/wrk/pigweed/... 75*61c4878aSAndroid Build Coastguard Worker 20200707 17:24:06 INF Triggering initial build... 76*61c4878aSAndroid Build Coastguard Worker ... 77*61c4878aSAndroid Build Coastguard Worker 78*61c4878aSAndroid Build Coastguard Worker#. **Congratulations, you're ready to go!** Now take Pigweed for a spin by 79*61c4878aSAndroid Build Coastguard Worker making a test fail. 80*61c4878aSAndroid Build Coastguard Worker 81*61c4878aSAndroid Build Coastguard Worker#. With the watcher running in a separate window, edit 82*61c4878aSAndroid Build Coastguard Worker ``pw_status/status_test.cc`` to make an expectation fail; for example, add 83*61c4878aSAndroid Build Coastguard Worker ``EXPECT_EQ(0, 1);`` in a test. 84*61c4878aSAndroid Build Coastguard Worker 85*61c4878aSAndroid Build Coastguard Worker#. Save the file. Observe the watcher rebuild & retest, and fail. Restore the 86*61c4878aSAndroid Build Coastguard Worker test if you feel like it. 87*61c4878aSAndroid Build Coastguard Worker 88*61c4878aSAndroid Build Coastguard Worker#. Open the generated docs in ``out/docs/gen/docs/html/index.html`` in your 89*61c4878aSAndroid Build Coastguard Worker browser. 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard Worker#. Edit ``docs/getting_started.rst`` (this file!) and make any change. Save. 92*61c4878aSAndroid Build Coastguard Worker See the watcher rebuild the docs. Reload your browser, and see the changes. 93*61c4878aSAndroid Build Coastguard Worker 94*61c4878aSAndroid Build Coastguard WorkerSee below for equivalent Windows commands, and for more details on what each 95*61c4878aSAndroid Build Coastguard Workerpart does. 96*61c4878aSAndroid Build Coastguard Worker 97*61c4878aSAndroid Build Coastguard Worker**Note:** After running bootstrap once, use ``source ./activate.sh`` (or 98*61c4878aSAndroid Build Coastguard Worker``activate.bat`` on Windows) to re-activate the environment without 99*61c4878aSAndroid Build Coastguard Workerre-bootstrapping. 100*61c4878aSAndroid Build Coastguard Worker 101*61c4878aSAndroid Build Coastguard Worker--------- 102*61c4878aSAndroid Build Coastguard WorkerBootstrap 103*61c4878aSAndroid Build Coastguard Worker--------- 104*61c4878aSAndroid Build Coastguard WorkerOnce you satisfied the prerequisites, you will be able to clone Pigweed and 105*61c4878aSAndroid Build Coastguard Workerrun the bootstrap that initializes the Pigweed virtual environment. The 106*61c4878aSAndroid Build Coastguard Workerbootstrap may take several minutes to complete, so please be patient. 107*61c4878aSAndroid Build Coastguard Worker 108*61c4878aSAndroid Build Coastguard Worker**Linux & macOS** 109*61c4878aSAndroid Build Coastguard Worker 110*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 111*61c4878aSAndroid Build Coastguard Worker 112*61c4878aSAndroid Build Coastguard Worker $ git clone https://pigweed.googlesource.com/pigweed/pigweed pigweed 113*61c4878aSAndroid Build Coastguard Worker $ cd pigweed 114*61c4878aSAndroid Build Coastguard Worker $ source ./bootstrap.sh 115*61c4878aSAndroid Build Coastguard Worker 116*61c4878aSAndroid Build Coastguard Worker**Windows** 117*61c4878aSAndroid Build Coastguard Worker 118*61c4878aSAndroid Build Coastguard Worker.. code-block:: batch 119*61c4878aSAndroid Build Coastguard Worker 120*61c4878aSAndroid Build Coastguard Worker :: Run git commands from the shell you set up to use with Git during install. 121*61c4878aSAndroid Build Coastguard Worker > git clone https://pigweed.googlesource.com/pigweed/pigweed %HOMEPATH%\pigweed 122*61c4878aSAndroid Build Coastguard Worker > cd %HOMEPATH%\pigweed 123*61c4878aSAndroid Build Coastguard Worker > bootstrap.bat 124*61c4878aSAndroid Build Coastguard Worker 125*61c4878aSAndroid Build Coastguard WorkerBelow is a real-time demo with roughly what you should expect to see as output: 126*61c4878aSAndroid Build Coastguard Worker 127*61c4878aSAndroid Build Coastguard Worker.. image:: https://storage.googleapis.com/pigweed-media/pw_env_setup_demo.gif 128*61c4878aSAndroid Build Coastguard Worker :width: 800 129*61c4878aSAndroid Build Coastguard Worker :alt: build example using pw watch 130*61c4878aSAndroid Build Coastguard Worker 131*61c4878aSAndroid Build Coastguard WorkerCongratulations, you are now set up to start using Pigweed! 132*61c4878aSAndroid Build Coastguard Worker 133*61c4878aSAndroid Build Coastguard Worker.. _activate-pigweed-environment: 134*61c4878aSAndroid Build Coastguard Worker 135*61c4878aSAndroid Build Coastguard Worker--------------------------------- 136*61c4878aSAndroid Build Coastguard WorkerActivate your Pigweed environment 137*61c4878aSAndroid Build Coastguard Worker--------------------------------- 138*61c4878aSAndroid Build Coastguard WorkerAfter going through the initial setup process, your current terminal will be in 139*61c4878aSAndroid Build Coastguard Workerthe Pigweed development environment that provides all the tools you should need 140*61c4878aSAndroid Build Coastguard Workerto develop on Pigweed. If you leave that session, you can activate the 141*61c4878aSAndroid Build Coastguard Workerenvironment in a new session with the following command: 142*61c4878aSAndroid Build Coastguard Worker 143*61c4878aSAndroid Build Coastguard Worker**Linux & macOS** 144*61c4878aSAndroid Build Coastguard Worker 145*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 146*61c4878aSAndroid Build Coastguard Worker 147*61c4878aSAndroid Build Coastguard Worker $ source ./activate.sh 148*61c4878aSAndroid Build Coastguard Worker 149*61c4878aSAndroid Build Coastguard Worker**Windows** 150*61c4878aSAndroid Build Coastguard Worker 151*61c4878aSAndroid Build Coastguard Worker.. code-block:: batch 152*61c4878aSAndroid Build Coastguard Worker 153*61c4878aSAndroid Build Coastguard Worker > activate.bat 154*61c4878aSAndroid Build Coastguard Worker 155*61c4878aSAndroid Build Coastguard WorkerSome major changes may require triggering the bootstrap again, so if you run 156*61c4878aSAndroid Build Coastguard Workerinto host tooling changes after a pull it may be worth re-running bootstrap. 157*61c4878aSAndroid Build Coastguard Worker 158*61c4878aSAndroid Build Coastguard Worker---------------------- 159*61c4878aSAndroid Build Coastguard WorkerBuild Pigweed for host 160*61c4878aSAndroid Build Coastguard Worker---------------------- 161*61c4878aSAndroid Build Coastguard WorkerPigweed's primary build system is GN/Ninja based. There are CMake and Bazel 162*61c4878aSAndroid Build Coastguard Workerbuilds in-development, but they are incomplete and don't have feature parity 163*61c4878aSAndroid Build Coastguard Workerwith the GN build. We strongly recommend you stick to the GN build system. 164*61c4878aSAndroid Build Coastguard Worker 165*61c4878aSAndroid Build Coastguard WorkerGN (Generate Ninja) just does what it says on the tin; GN generates 166*61c4878aSAndroid Build Coastguard Worker`Ninja <https://ninja-build.org/>`_ build files. 167*61c4878aSAndroid Build Coastguard Worker 168*61c4878aSAndroid Build Coastguard WorkerThe default GN configuration generates build files that allow you to build host 169*61c4878aSAndroid Build Coastguard Workerbinaries, device binaries, and upstream documentation all in one Ninja 170*61c4878aSAndroid Build Coastguard Workerinvocation. 171*61c4878aSAndroid Build Coastguard Worker 172*61c4878aSAndroid Build Coastguard WorkerRun GN as seen below: 173*61c4878aSAndroid Build Coastguard Worker 174*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 175*61c4878aSAndroid Build Coastguard Worker 176*61c4878aSAndroid Build Coastguard Worker $ gn gen out 177*61c4878aSAndroid Build Coastguard Worker 178*61c4878aSAndroid Build Coastguard Worker.. note:: 179*61c4878aSAndroid Build Coastguard Worker ``out`` is simply the directory the build files are saved to. Unless 180*61c4878aSAndroid Build Coastguard Worker this directory is deleted or you desire to do a clean build, there's no need 181*61c4878aSAndroid Build Coastguard Worker to run GN again; just rebuild using Ninja directly. 182*61c4878aSAndroid Build Coastguard Worker 183*61c4878aSAndroid Build Coastguard Worker.. warning:: 184*61c4878aSAndroid Build Coastguard Worker Unless your build directory (the ``out`` in ``gn gen out``) is exactly one 185*61c4878aSAndroid Build Coastguard Worker directory away from the project root directory (the Pigweed repo root in this 186*61c4878aSAndroid Build Coastguard Worker case), there will be issues finding source files while debugging and while 187*61c4878aSAndroid Build Coastguard Worker generating coverage reports. This is due an issue in upstream LLVM reordering 188*61c4878aSAndroid Build Coastguard Worker debug and coverage path mappings (tracked by 189*61c4878aSAndroid Build Coastguard Worker `b/278898014 <https://issuetracker.google.com/278898014>`_ and 190*61c4878aSAndroid Build Coastguard Worker `b/278906020 <https://issuetracker.google.com/278906020>`_). **Stick to 191*61c4878aSAndroid Build Coastguard Worker simple, single directory build directories for now.** 192*61c4878aSAndroid Build Coastguard Worker 193*61c4878aSAndroid Build Coastguard WorkerNow that we have build files, it's time to build Pigweed! 194*61c4878aSAndroid Build Coastguard Worker 195*61c4878aSAndroid Build Coastguard WorkerNow you *could* manually invoke the host build using ``ninja -C out`` every 196*61c4878aSAndroid Build Coastguard Workertime you make a change, but that's tedious. Instead, let's use ``pw_watch``. 197*61c4878aSAndroid Build Coastguard Worker 198*61c4878aSAndroid Build Coastguard WorkerGo ahead and start ``pw_watch``: 199*61c4878aSAndroid Build Coastguard Worker 200*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 201*61c4878aSAndroid Build Coastguard Worker 202*61c4878aSAndroid Build Coastguard Worker $ pw watch 203*61c4878aSAndroid Build Coastguard Worker 204*61c4878aSAndroid Build Coastguard WorkerWhen ``pw_watch`` starts up, it will automatically build the directory we 205*61c4878aSAndroid Build Coastguard Workergenerated in ``out``. Additionally, ``pw_watch`` watches source code files for 206*61c4878aSAndroid Build Coastguard Workerchanges, and triggers a Ninja build whenever it notices a file has been saved. 207*61c4878aSAndroid Build Coastguard WorkerYou might be surprised how much time it can save you! 208*61c4878aSAndroid Build Coastguard Worker 209*61c4878aSAndroid Build Coastguard WorkerWith ``pw watch`` running, try modifying 210*61c4878aSAndroid Build Coastguard Worker``pw_status/public/pw_status/status.h`` and watch the build re-trigger when you 211*61c4878aSAndroid Build Coastguard Workersave the file. 212*61c4878aSAndroid Build Coastguard Worker 213*61c4878aSAndroid Build Coastguard WorkerSee below for a demo of this in action: 214*61c4878aSAndroid Build Coastguard Worker 215*61c4878aSAndroid Build Coastguard Worker.. image:: https://storage.googleapis.com/pigweed-media/pw_watch_build_demo.gif 216*61c4878aSAndroid Build Coastguard Worker :width: 800 217*61c4878aSAndroid Build Coastguard Worker :alt: build example using pw watch 218*61c4878aSAndroid Build Coastguard Worker 219*61c4878aSAndroid Build Coastguard Worker------------------ 220*61c4878aSAndroid Build Coastguard WorkerRunning unit tests 221*61c4878aSAndroid Build Coastguard Worker------------------ 222*61c4878aSAndroid Build Coastguard WorkerFun fact, you've been running the unit tests already! Ninja builds targeting 223*61c4878aSAndroid Build Coastguard Workerthe host automatically build and run the unit tests. Unit tests err on the side 224*61c4878aSAndroid Build Coastguard Workerof being quiet in the success case, and only output test results when there's a 225*61c4878aSAndroid Build Coastguard Workerfailure. 226*61c4878aSAndroid Build Coastguard Worker 227*61c4878aSAndroid Build Coastguard WorkerTo see a test failure, modify ``pw_status/status_test.cc`` to fail by changing 228*61c4878aSAndroid Build Coastguard Workerone of the strings in the "KnownString" test. 229*61c4878aSAndroid Build Coastguard Worker 230*61c4878aSAndroid Build Coastguard Worker.. image:: https://storage.googleapis.com/pigweed-media/pw_watch_test_demo.gif 231*61c4878aSAndroid Build Coastguard Worker :width: 800 232*61c4878aSAndroid Build Coastguard Worker :alt: example test failure using pw watch 233*61c4878aSAndroid Build Coastguard Worker 234*61c4878aSAndroid Build Coastguard WorkerRunning tests as part of the build isn't particularly expensive because GN 235*61c4878aSAndroid Build Coastguard Workercaches passing tests. Each time you build, only the tests that are affected 236*61c4878aSAndroid Build Coastguard Worker(whether directly or transitively) by the code changes since the last build 237*61c4878aSAndroid Build Coastguard Workerwill be re-built and re-run. 238*61c4878aSAndroid Build Coastguard Worker 239*61c4878aSAndroid Build Coastguard WorkerTry running the ``pw_status`` test manually: 240*61c4878aSAndroid Build Coastguard Worker 241*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 242*61c4878aSAndroid Build Coastguard Worker 243*61c4878aSAndroid Build Coastguard Worker $ ./out/pw_strict_host_{clang,gcc}_debug/obj/pw_status/test/status_test 244*61c4878aSAndroid Build Coastguard Worker 245*61c4878aSAndroid Build Coastguard WorkerDepending on your host OS, the compiler will default to either ``clang`` or 246*61c4878aSAndroid Build Coastguard Worker``gcc``. 247*61c4878aSAndroid Build Coastguard Worker 248*61c4878aSAndroid Build Coastguard Worker--------------------- 249*61c4878aSAndroid Build Coastguard WorkerBuilding for a device 250*61c4878aSAndroid Build Coastguard Worker--------------------- 251*61c4878aSAndroid Build Coastguard WorkerA Pigweed "target" is a build configuration that includes a toolchain, default 252*61c4878aSAndroid Build Coastguard Workerlibrary configurations, and more to result in binaries that run natively on the 253*61c4878aSAndroid Build Coastguard Workertarget. With the default build invocation, you're already building for a device 254*61c4878aSAndroid Build Coastguard Workertarget (the STMicroelectronics STM32F429I-DISC1) in parallel with the host 255*61c4878aSAndroid Build Coastguard Workerbuild! 256*61c4878aSAndroid Build Coastguard Worker 257*61c4878aSAndroid Build Coastguard WorkerIf you want to build JUST for the device, you can kick of watch with: 258*61c4878aSAndroid Build Coastguard Worker 259*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 260*61c4878aSAndroid Build Coastguard Worker 261*61c4878aSAndroid Build Coastguard Worker $ pw watch stm32f429i 262*61c4878aSAndroid Build Coastguard Worker 263*61c4878aSAndroid Build Coastguard WorkerThis is equivalent to the following Ninja invocation: 264*61c4878aSAndroid Build Coastguard Worker 265*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 266*61c4878aSAndroid Build Coastguard Worker 267*61c4878aSAndroid Build Coastguard Worker $ ninja -C out stm32f429i 268*61c4878aSAndroid Build Coastguard Worker 269*61c4878aSAndroid Build Coastguard Worker------------------------- 270*61c4878aSAndroid Build Coastguard WorkerRunning tests on a device 271*61c4878aSAndroid Build Coastguard Worker------------------------- 272*61c4878aSAndroid Build Coastguard WorkerWhile tests run automatically on the host, it takes a few more steps to get 273*61c4878aSAndroid Build Coastguard Workertests to run automatically on a device, too. Even though we've verified tests 274*61c4878aSAndroid Build Coastguard Workerpass on the host, it's crucial to verify the same with on-device testing. We've 275*61c4878aSAndroid Build Coastguard Workerencountered some unexpected bugs that can only be found by running the unit 276*61c4878aSAndroid Build Coastguard Workertests directly on the device. 277*61c4878aSAndroid Build Coastguard Worker 278*61c4878aSAndroid Build Coastguard Worker1. Connect device(s) 279*61c4878aSAndroid Build Coastguard Worker==================== 280*61c4878aSAndroid Build Coastguard WorkerConnect any number of STM32F429I-DISC1 boards to your computer using the mini 281*61c4878aSAndroid Build Coastguard WorkerUSB port on the board (**not** the micro USB). Pigweed will automatically 282*61c4878aSAndroid Build Coastguard Workerdetect the boards and distribute the tests across the devices. More boards = 283*61c4878aSAndroid Build Coastguard Workerfaster tests! Keep in mind that you may have to make some environment specific 284*61c4878aSAndroid Build Coastguard Workerupdates to ensure you have permissions to use the USB device. For example, on 285*61c4878aSAndroid Build Coastguard WorkerLinux you may need to update your udev rules and ensure you're in the plugdev 286*61c4878aSAndroid Build Coastguard Workerand dialout groups. 287*61c4878aSAndroid Build Coastguard Worker 288*61c4878aSAndroid Build Coastguard Worker.. image:: https://storage.googleapis.com/pigweed-media/stm32f429i-disc1_connected.jpg 289*61c4878aSAndroid Build Coastguard Worker :width: 800 290*61c4878aSAndroid Build Coastguard Worker :alt: development boards connected via USB 291*61c4878aSAndroid Build Coastguard Worker 292*61c4878aSAndroid Build Coastguard Worker2. Launch test server 293*61c4878aSAndroid Build Coastguard Worker===================== 294*61c4878aSAndroid Build Coastguard WorkerTo allow Ninja to run tests on an arbitrary number of devices, Ninja will send 295*61c4878aSAndroid Build Coastguard Workertest requests to a server running in the background. Launch the server in 296*61c4878aSAndroid Build Coastguard Workeranother window using the command below (remember, you'll need to activate the 297*61c4878aSAndroid Build Coastguard WorkerPigweed environment first). 298*61c4878aSAndroid Build Coastguard Worker 299*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 300*61c4878aSAndroid Build Coastguard Worker 301*61c4878aSAndroid Build Coastguard Worker $ stm32f429i_disc1_test_server 302*61c4878aSAndroid Build Coastguard Worker 303*61c4878aSAndroid Build Coastguard Worker**Note:** If you attach or detach any more boards to your workstation you'll 304*61c4878aSAndroid Build Coastguard Workerneed to relaunch this server. 305*61c4878aSAndroid Build Coastguard Worker 306*61c4878aSAndroid Build Coastguard Worker3. Configure GN 307*61c4878aSAndroid Build Coastguard Worker=============== 308*61c4878aSAndroid Build Coastguard WorkerTell GN to use the testing server by enabling a build arg specific to the 309*61c4878aSAndroid Build Coastguard Workerstm32f429i-disc1 target. 310*61c4878aSAndroid Build Coastguard Worker 311*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 312*61c4878aSAndroid Build Coastguard Worker 313*61c4878aSAndroid Build Coastguard Worker $ gn args out 314*61c4878aSAndroid Build Coastguard Worker # Append this line to the file that opens in your editor to tell GN to run 315*61c4878aSAndroid Build Coastguard Worker # on-device unit tests. 316*61c4878aSAndroid Build Coastguard Worker pw_use_test_server = true 317*61c4878aSAndroid Build Coastguard Worker 318*61c4878aSAndroid Build Coastguard WorkerDone! 319*61c4878aSAndroid Build Coastguard Worker===== 320*61c4878aSAndroid Build Coastguard WorkerWhenever you make code changes and trigger a build, all the affected unit tests 321*61c4878aSAndroid Build Coastguard Workerwill be run across the attached boards! 322*61c4878aSAndroid Build Coastguard Worker 323*61c4878aSAndroid Build Coastguard WorkerSee the demo below for an example of what this all looks like put together: 324*61c4878aSAndroid Build Coastguard Worker 325*61c4878aSAndroid Build Coastguard Worker.. image:: https://storage.googleapis.com/pigweed-media/pw_watch_on_device_demo.gif 326*61c4878aSAndroid Build Coastguard Worker :width: 800 327*61c4878aSAndroid Build Coastguard Worker :alt: pw watch running on-device tests 328*61c4878aSAndroid Build Coastguard Worker 329*61c4878aSAndroid Build Coastguard Worker-------------------------- 330*61c4878aSAndroid Build Coastguard WorkerBuilding the documentation 331*61c4878aSAndroid Build Coastguard Worker-------------------------- 332*61c4878aSAndroid Build Coastguard WorkerIn addition to the markdown documentation, Pigweed has a collection of 333*61c4878aSAndroid Build Coastguard Workerinformation-rich RST files that are used to generate HTML documentation. All 334*61c4878aSAndroid Build Coastguard Workerthe docs are hosted at https://pigweed.dev/, and are built as a part of the 335*61c4878aSAndroid Build Coastguard Workerdefault build invocation. This makes it easier to make changes and see how they 336*61c4878aSAndroid Build Coastguard Workerturn out. Once built, you can find the rendered HTML documentation at 337*61c4878aSAndroid Build Coastguard Worker``out/docs/gen/docs/html``. 338*61c4878aSAndroid Build Coastguard Worker 339*61c4878aSAndroid Build Coastguard WorkerYou can explicitly build just the documentation with the command below. 340*61c4878aSAndroid Build Coastguard Worker 341*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 342*61c4878aSAndroid Build Coastguard Worker 343*61c4878aSAndroid Build Coastguard Worker $ ninja -C out docs 344*61c4878aSAndroid Build Coastguard Worker 345*61c4878aSAndroid Build Coastguard WorkerThis concludes the introduction to developing for upstream Pigweed. 346*61c4878aSAndroid Build Coastguard Worker 347*61c4878aSAndroid Build Coastguard Worker--------------------------- 348*61c4878aSAndroid Build Coastguard WorkerBuilding tests individually 349*61c4878aSAndroid Build Coastguard Worker--------------------------- 350*61c4878aSAndroid Build Coastguard WorkerSometimes it's faster to incrementally build a single test target rather than 351*61c4878aSAndroid Build Coastguard Workerwaiting for the whole world to build and all tests to run. GN has a built-in 352*61c4878aSAndroid Build Coastguard Workertool, ``gn outputs``, that will translate a GN build step into a Ninja build 353*61c4878aSAndroid Build Coastguard Workerstep. In order to build and run the right test, it's important to explicitly 354*61c4878aSAndroid Build Coastguard Workerspecify which target to build the test under (e.g. host, SM32F529I-DISC1). 355*61c4878aSAndroid Build Coastguard WorkerThis can be done by appending the GN path to the target toolchain in parenthesis 356*61c4878aSAndroid Build Coastguard Workerafter the desired GN build step label as seen in the example below. 357*61c4878aSAndroid Build Coastguard Worker 358*61c4878aSAndroid Build Coastguard Worker.. code-block:: none 359*61c4878aSAndroid Build Coastguard Worker 360*61c4878aSAndroid Build Coastguard Worker $ gn outputs out "//pw_status:status_test.run(//targets/host/pigweed_internal:pw_strict_host_clang_debug)" 361*61c4878aSAndroid Build Coastguard Worker pw_strict_host_clang_debug/obj/pw_status/status_test.run.pw_pystamp 362*61c4878aSAndroid Build Coastguard Worker 363*61c4878aSAndroid Build Coastguard Worker $ ninja -C out pw_strict_host_clang_debug/obj/pw_status/status_test.run.pw_pystamp 364*61c4878aSAndroid Build Coastguard Worker ninja: Entering directory `out' 365*61c4878aSAndroid Build Coastguard Worker [4/4] ACTION //pw_status:status_test.run(//targets/host/pigweed_internal:pw_strict_host_clang_debug) 366*61c4878aSAndroid Build Coastguard Worker 367*61c4878aSAndroid Build Coastguard WorkerThe ``.run`` following the test target name is a sub-target created as part of 368*61c4878aSAndroid Build Coastguard Workerthe ``pw_test`` GN template. If you remove ``.run``, the test will build but 369*61c4878aSAndroid Build Coastguard Workernot attempt to run. 370*61c4878aSAndroid Build Coastguard Worker 371*61c4878aSAndroid Build Coastguard WorkerIn macOS and Linux, ``xargs`` can be used to turn this into a single command: 372*61c4878aSAndroid Build Coastguard Worker 373*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 374*61c4878aSAndroid Build Coastguard Worker 375*61c4878aSAndroid Build Coastguard Worker $ gn outputs out "//pw_status:status_test.run(//targets/host/pigweed_internal:pw_strict_host_clang_debug)" | xargs ninja -C out 376*61c4878aSAndroid Build Coastguard Worker 377*61c4878aSAndroid Build Coastguard Worker---------- 378*61c4878aSAndroid Build Coastguard WorkerNext steps 379*61c4878aSAndroid Build Coastguard Worker---------- 380*61c4878aSAndroid Build Coastguard Worker 381*61c4878aSAndroid Build Coastguard WorkerQuickstarts 382*61c4878aSAndroid Build Coastguard Worker=========== 383*61c4878aSAndroid Build Coastguard WorkerVisit :ref:`docs-get-started` to learn how to set up a new Bazel-based 384*61c4878aSAndroid Build Coastguard Workerproject, how to add Pigweed to an existing Bazel-based project, and more. 385*61c4878aSAndroid Build Coastguard Worker 386*61c4878aSAndroid Build Coastguard WorkerOther modules 387*61c4878aSAndroid Build Coastguard Worker============= 388*61c4878aSAndroid Build Coastguard WorkerIf you'd like to see more of what Pigweed has to offer, dive into the 389*61c4878aSAndroid Build Coastguard Worker:ref:`docs-module-guides`. 390*61c4878aSAndroid Build Coastguard Worker 391*61c4878aSAndroid Build Coastguard WorkerThe :ref:`docs-kudzu` repo demonstrates how to use Pigweed in your own project. 392*61c4878aSAndroid Build Coastguard WorkerNote that there are many ways to leverage Pigweed and Kudzu is just one 393*61c4878aSAndroid Build Coastguard Workerapproach. 394*61c4878aSAndroid Build Coastguard Worker 395*61c4878aSAndroid Build Coastguard WorkerEditor setup 396*61c4878aSAndroid Build Coastguard Worker============ 397*61c4878aSAndroid Build Coastguard WorkerCheck out the :ref:`module-pw_ide` for setting up editor configurations or run 398*61c4878aSAndroid Build Coastguard Workerthe following for a quick setup: 399*61c4878aSAndroid Build Coastguard Worker 400*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 401*61c4878aSAndroid Build Coastguard Worker 402*61c4878aSAndroid Build Coastguard Worker pw ide sync 403*61c4878aSAndroid Build Coastguard Worker 404*61c4878aSAndroid Build Coastguard WorkerHackaday Supercon talk about Pigweed 405*61c4878aSAndroid Build Coastguard Worker==================================== 406*61c4878aSAndroid Build Coastguard WorkerWe gave a talk at Hackaday's 2021 supercon, `Give Pigweed a Whirl 407*61c4878aSAndroid Build Coastguard Worker<https://hackaday.com/2021/01/13/remoticon-video-pigweed-brings-embedded-unit-testing-library-integration-to-commandline/>`_ 408*61c4878aSAndroid Build Coastguard Worker 409*61c4878aSAndroid Build Coastguard WorkerWe've made improvements since we gave the talk; for example, we now have RTOS 410*61c4878aSAndroid Build Coastguard Workerprimitives. 411*61c4878aSAndroid Build Coastguard Worker 412*61c4878aSAndroid Build Coastguard WorkerGet help 413*61c4878aSAndroid Build Coastguard Worker======== 414*61c4878aSAndroid Build Coastguard WorkerDropping into our `chat room <https://discord.gg/M9NSeTA>`_ is the most 415*61c4878aSAndroid Build Coastguard Workerimmediate way to get help from the Pigweed team. 416