• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Compilation and Building \(for Mini and Small Systems\)<a name="EN-US_TOPIC_0000001130006475"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5-   [Usage](#section1312121216216)
6    -   [Usage Guidelines](#section129654513264)
7
8-   [Repositories Involved](#section1371113476307)
9
10## Introduction<a name="section11660541593"></a>
11
12The compilation and building subsystem is a build framework based on Generate Ninja \(GN\) and Ninja, which supports component-based OpenHarmony development. This subsystem can be used to:
13
14-   Build products.
15
16-   Build chipset vendor components independently.
17-   Build a single component independently.
18
19It is considered best practice to learn the following basic concepts before you start development and build:
20
21-   **Component**
22
23    A component is a reusable software unit that can contain source code, configuration files, resource files, and build scripts.
24
25-   **GN**
26
27    GN is short for Generate Ninja, which is a build system used to generate Ninja files.
28
29-   **Ninja**
30
31    Ninja is a small high-speed build system.
32
33
34**Build Process**
35
36The following figure shows the build process.
37
38**Figure  1**  Build process<a name="fig1531311552204"></a>
39![](figures/build-process.jpg "build-process")
40
411.  **hb set**: Set the OpenHarmony source code directory and the product to build.
422.  **hb build**: Build the product, development board, or component. The process to build the solution is as follows:
43    -   **Reading configuration**: Read the development board configuration, which covers the toolchain, linking commands, and build options.
44    -   **Running gn**: Run the  **gn gen**  command to read the product configuration \(related to the development board, kernel, and system components\) and generate the  **out**  directory and  **ninja**  files for the solution.
45    -   **Running Ninja**: Run  **ninja -C out/company/product**  to start build.
46    -   **Packaging**: Package the build result to create a file system image.
47
48
49## Directory Structure<a name="section161941989596"></a>
50
51```
52build/lite                      # Primary directory
53├── components                  # Component description file
54├── hb                          # hb pip installation package
55├── make_rootfs                 # make script for the file system
56├── config                      # Build configuration items
57│   ├── component               # Definitions of component-related templates, including static libraries, dynamic libraries, extension components, and emulator libraries
58│   ├── kernel                  # Build configuration parameters of the kernel
59│   └── subsystem               # Subsystem template
60├── ndk                          # NDK-related build scripts and configuration parameters
61└── toolchain                   # Build toolchain, which contain the compiler directories, build options, and linking options
62```
63
64## Usage<a name="section1312121216216"></a>
65
66### Usage Guidelines<a name="section129654513264"></a>
67
681.  **Prerequisites**
69    -   Server and OS version: Linux server running 64-bit Ubuntu 16.04 or later
70    -   Python version: 3.7.4 or later
71    -   Repository:  **build\_lite**  of OpenHarmony source code
72
732.  **Installing hb**
74    -   Run the following command in the root directory of the source code:
75
76        ```
77        python3 -m pip install --user build/lite
78        ```
79
80    -   Run the  **hb -h**  command. If the following information is displayed, the installation is successful:
81
82        ```
83        usage: hb
84
85        OHOS build system
86
87        positional arguments:
88          {build,set,env,clean}
89            build               Build source code
90            set                 OHOS build settings
91            env                 Show OHOS build env
92            clean               Clean output
93
94        optional arguments:
95          -h, --help            Show this help message and exit
96        ```
97
98    -   **Uninstalling hb**
99
100        Run the following command to uninstall hb:
101
102        ```
103        python3 -m pip uninstall ohos-build
104        ```
105
106
1073.  **Build Commands**
108    1.  **hb set**
109
110        ```
111        hb set -h
112        usage: hb set [-h] [-root [ROOT_PATH]] [-p]
113
114        optional arguments:
115          -h, --help            Show this help message and exit.
116          -root [ROOT_PATH], --root_path [ROOT_PATH]
117                                Set OHOS root path.
118          -p, --product         Set OHOS board and kernel.
119        ```
120
121        -   If you run  **hb set**  with no argument, the default setting process starts.
122        -   You can run  **hb set -root** _\[ROOT\_PATH\]_  to set the root directory of the source code.
123        -   **hb set -p --product**  is used to set the product to build.
124
125    2.  **hb env**
126
127        View the current configuration.
128
129        ```
130        hb env
131        [OHOS INFO] root path: xxx
132        [OHOS INFO] board: hispark_taurus
133        [OHOS INFO] kernel: liteos
134        [OHOS INFO] product: ipcamera
135        [OHOS INFO] product path: xxx/vendor/hisilicon/ipcamera
136        [OHOS INFO] device path: xxx/device/hisilicon/hispark_taurus/sdk_linux_4.19
137        ```
138
139    3.  **hb build**
140
141        ```
142        hb build -h
143        usage: hb build [-h] [-b BUILD_TYPE] [-c COMPILER] [-t [TEST [TEST ...]]]
144                        [--dmverity] [-p PRODUCT] [-f] [-n]
145                        [component [component ...]]
146
147        positional arguments:
148          component             Name of the component.
149
150        optional arguments:
151          -h, --help            Show this help message and exit.
152          -b BUILD_TYPE, --build_type BUILD_TYPE
153                                Release or debug version.
154          -c COMPILER, --compiler COMPILER
155                                Specify compiler.
156          -t [TEST [TEST ...]], --test [TEST [TEST ...]]
157                                Compile test suit.
158          --dmverity            Enable dmverity.
159          -p PRODUCT, --product PRODUCT
160                                Build a specified product with
161                                {product_name}@{company}, eg: ipcamera@hisilcon.
162          -f, --full            Full code compilation.
163          -T [TARGET [TARGET ...]], --target [TARGET [TARGET ...]]
164                                Compile single target
165        ```
166
167        -   If you run  **hb build**  with no argument, the previously configured code directory, product, and options are used for build.
168        -   You can run  **hb build** _\{component\}_  to build product components separately based on the development board and kernel set for the product, for example,  **hb build kv\_store**.
169        -   You can run  **hb build -p PRODUCT**  to skip the setting step and build the product directly.
170        -   You can run  **hb build**  in  **device/device\_company/board**  to select the kernel and start build based on the current development board and the selected kernel to generate an image that contains the kernel and driver only.
171
172    4.  **hb clean**
173
174        Clear the build result of the product in the  **out**  directory, and leave the  **args.gn**  and  **build.log**  files only. To clear files in a specified directory, add the directory parameter to the command, for example,  **hb clean** _xxx_**/out/**_xxx_.
175
176        ```
177        hb clean
178        usage: hb clean [-h] [out_path]
179
180        positional arguments:
181          out_path    Clean a specified path.
182
183        optional arguments:
184          -h, --help  Show this help message and exit.
185        ```
186
187
188
189## Repositories Involved<a name="section1371113476307"></a>
190
191Compilation and building subsystem
192
193**[build\_lite](https://gitee.com/openharmony/build_lite)**