1e41f4b71Sopenharmony_ci# Module 2e41f4b71Sopenharmony_ci## Configuration Rules 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciThe Compilation and Building subsystem implements compilation and packaging by module, component, and product. A module is a target to build. It can be a dynamic library, static library, configuration file, or prebuilt module. A module must belong to a component and can belong to only one component. OpenHarmony provides customized GN templates to configure modules. For details about the GN basics, see [GN Reference](https://gn.googlesource.com/gn/+/main/docs/reference.md). 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciThe common templates for module configuration are as follows: 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci``` 9e41f4b71Sopenharmony_ci# C/C++ templates 10e41f4b71Sopenharmony_ciohos_shared_library 11e41f4b71Sopenharmony_ciohos_static_library 12e41f4b71Sopenharmony_ciohos_executable 13e41f4b71Sopenharmony_ciohos_source_set 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci# Prebuilt templates 16e41f4b71Sopenharmony_ciohos_prebuilt_executable 17e41f4b71Sopenharmony_ciohos_prebuilt_shared_library 18e41f4b71Sopenharmony_ciohos_prebuilt_static_library 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci# HAP templates 21e41f4b71Sopenharmony_ciohos_hap 22e41f4b71Sopenharmony_ciohos_app_scope 23e41f4b71Sopenharmony_ciohos_js_assets 24e41f4b71Sopenharmony_ciohos_resources 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci# Rust templates 27e41f4b71Sopenharmony_ciohos_rust_executable 28e41f4b71Sopenharmony_ciohos_rust_shared_library 29e41f4b71Sopenharmony_ciohos_rust_static_library 30e41f4b71Sopenharmony_ciohos_rust_proc_macro 31e41f4b71Sopenharmony_ciohos_rust_shared_ffi 32e41f4b71Sopenharmony_ciohos_rust_static_ffi 33e41f4b71Sopenharmony_ciohos_rust_cargo_crate 34e41f4b71Sopenharmony_ciohos_rust_systemtest 35e41f4b71Sopenharmony_ciohos_rust_unittest 36e41f4b71Sopenharmony_ciohos_rust_fuzztest 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci# Other templates 39e41f4b71Sopenharmony_ci# Configuration file 40e41f4b71Sopenharmony_ciohos_prebuilt_etc 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci# SA profile 43e41f4b71Sopenharmony_ciohos_sa_profile 44e41f4b71Sopenharmony_ci``` 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciYou are advised to use OpenHarmony custom templates. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci### C/C++ Template Example 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciThe path of the .gni file of the template starting with **ohos** is **openharmony/build/templates/cxx/cxx.gni**. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**ohos_shared_library** example: 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci```shell 55e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 56e41f4b71Sopenharmony_ciohos_shared_library("helloworld") { 57e41f4b71Sopenharmony_ci sources = ["file"] 58e41f4b71Sopenharmony_ci include_dirs = [] # If there are duplicate header files, the header file defined earlier takes precedence over the file defined later. 59e41f4b71Sopenharmony_ci cflags = [] # If there are duplicate or conflict settings, the settings in cflags take effect. 60e41f4b71Sopenharmony_ci cflags_c = [] 61e41f4b71Sopenharmony_ci cflags_cc = [] 62e41f4b71Sopenharmony_ci ldflags = [] # If there are duplicate or conflict definitions, the settings in ohos_template take effect. 63e41f4b71Sopenharmony_ci configs = [] 64e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci external_deps = [ # Dependent modules that belong to different components. 67e41f4b71Sopenharmony_ci "part_name:module_name", # The value is in the Component_name:Module_name format. 68e41f4b71Sopenharmony_ci ] # The dependent modules must be declared in inner_kits by the dependent component. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci output_name = [string] # Name of the module output. 71e41f4b71Sopenharmony_ci output_extension = [] # Extension name of the module. 72e41f4b71Sopenharmony_ci module_install_dir = "" # Module installation directory in /system/lib64 or /system/lib. 73e41f4b71Sopenharmony_ci relative_install_dir = "" # Relative module installation directory (relative to /system/lib64 or /system/lib). If module_install_dir is configured, the parameter does not take effect. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci part_name = "" # Component name. This parameter is mandatory. 76e41f4b71Sopenharmony_ci output_dir 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci # Sanitizer configuration. Each item is optional, and is false or left unspecified by default. 79e41f4b71Sopenharmony_ci sanitize = { 80e41f4b71Sopenharmony_ci # Sanitizer settings 81e41f4b71Sopenharmony_ci cfi = [boolean] # Whether to enable the control-flow integrity (CFI) check. 82e41f4b71Sopenharmony_ci cfi_cross_dso = [boolean] # Whether to enable the cross-DSO CFI check. 83e41f4b71Sopenharmony_ci integer_overflow = [boolean] # Whether to enable the integer overflow check. 84e41f4b71Sopenharmony_ci boundary_sanitize = [boolean] # Whether to enable the boundary check. 85e41f4b71Sopenharmony_ci ubsan = [boolean] # Whether to enable some Undefined Behavior Sanitizer (UBSAN) options. 86e41f4b71Sopenharmony_ci all_ubsan = [boolean] # Whether to enable all UBSAN options. 87e41f4b71Sopenharmony_ci ... 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci debug = [boolean] # Whether to enable the debug mode. 90e41f4b71Sopenharmony_ci blocklist = [string] # Path of the blocklist. 91e41f4b71Sopenharmony_ci } 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci testonly = [boolean] 94e41f4b71Sopenharmony_ci license_as_sources = [] 95e41f4b71Sopenharmony_ci license_file = [] # A .txt file. 96e41f4b71Sopenharmony_ci remove_configs = [] 97e41f4b71Sopenharmony_ci no_default_deps = [] 98e41f4b71Sopenharmony_ci install_images = [] 99e41f4b71Sopenharmony_ci install_enable = [boolean] 100e41f4b71Sopenharmony_ci symlink_target_name = [] 101e41f4b71Sopenharmony_ci version_script = [] 102e41f4b71Sopenharmony_ci use_exceptions = [] 103e41f4b71Sopenharmony_ci} 104e41f4b71Sopenharmony_ci``` 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci**ohos_static_library** example 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci```shell 109e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 110e41f4b71Sopenharmony_ciohos_static_library("helloworld") { 111e41f4b71Sopenharmony_ci sources = ["file"] # .c files. 112e41f4b71Sopenharmony_ci include_dirs = ["dir"] # Directories to be included. 113e41f4b71Sopenharmony_ci configs = [] # Configuration. 114e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 115e41f4b71Sopenharmony_ci part_name = "" # Component name. 116e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 117e41f4b71Sopenharmony_ci cflags = [] 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci external_deps = [ # Dependent modules that belong to different components. 120e41f4b71Sopenharmony_ci "part_name:module_name", # The value is in the Component_name:Module_name format. 121e41f4b71Sopenharmony_ci ] # The dependent modules must be declared in inner_kits by the dependent component. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci lib_dirs = [] 124e41f4b71Sopenharmony_ci public_configs = [] 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci # Sanitizer configuration. Each item is optional, and is false or left unspecified by default. 127e41f4b71Sopenharmony_ci sanitize = { 128e41f4b71Sopenharmony_ci # Sanitizer settings 129e41f4b71Sopenharmony_ci cfi = [boolean] # Whether to enable the control-flow integrity (CFI) check. 130e41f4b71Sopenharmony_ci cfi_cross_dso = [boolean] # Whether to enable the cross-DSO CFI check. 131e41f4b71Sopenharmony_ci integer_overflow = [boolean] # Whether to enable the integer overflow check. 132e41f4b71Sopenharmony_ci boundary_sanitize = [boolean] # Whether to enable the boundary check. 133e41f4b71Sopenharmony_ci ubsan = [boolean] # Whether to enable some Undefined Behavior Sanitizer (UBSAN) options. 134e41f4b71Sopenharmony_ci all_ubsan = [boolean] # Whether to enable all UBSAN options. 135e41f4b71Sopenharmony_ci ... 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci debug = [boolean] # Whether to enable the debug mode. 138e41f4b71Sopenharmony_ci blocklist = [string] # Path of the blocklist. 139e41f4b71Sopenharmony_ci } 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci remove_configs = [] 142e41f4b71Sopenharmony_ci no_default_deps = [] 143e41f4b71Sopenharmony_ci license_file = [] # A .txt file. 144e41f4b71Sopenharmony_ci license_as_sources = [] 145e41f4b71Sopenharmony_ci use_exceptions = [] 146e41f4b71Sopenharmony_ci} 147e41f4b71Sopenharmony_ci``` 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**ohos_executable** example: 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci```shell 152e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 153e41f4b71Sopenharmony_ciohos_executable("helloworld") { 154e41f4b71Sopenharmony_ci configs = [] # Configuration. 155e41f4b71Sopenharmony_ci part_name = "" # Component name. 156e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 157e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci external_deps = [ # Dependent modules that belong to different components. 160e41f4b71Sopenharmony_ci "part_name:module_name", # The value is in the Component_name:Module_name format. 161e41f4b71Sopenharmony_ci ] # The dependent modules must be declared in inner_kits by the dependent component. 162e41f4b71Sopenharmony_ci ohos_test = [] 163e41f4b71Sopenharmony_ci test_output_dir = [] 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci # Sanitizer configuration. Each item is optional, and is false or left unspecified by default. 166e41f4b71Sopenharmony_ci sanitize = { 167e41f4b71Sopenharmony_ci # Sanitizer settings 168e41f4b71Sopenharmony_ci cfi = [boolean] # Whether to enable the control-flow integrity (CFI) check. 169e41f4b71Sopenharmony_ci cfi_cross_dso = [boolean] # Whether to enable the cross-DSO CFI check. 170e41f4b71Sopenharmony_ci integer_overflow = [boolean] # Whether to enable the integer overflow check. 171e41f4b71Sopenharmony_ci boundary_sanitize = [boolean] # Whether to enable the boundary check. 172e41f4b71Sopenharmony_ci ubsan = [boolean] # Whether to enable some Undefined Behavior Sanitizer (UBSAN) options. 173e41f4b71Sopenharmony_ci all_ubsan = [boolean] # Whether to enable all UBSAN options. 174e41f4b71Sopenharmony_ci ... 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci debug = [boolean] # Whether to enable the debug mode. 177e41f4b71Sopenharmony_ci blocklist = [string] # Path of the blocklist. 178e41f4b71Sopenharmony_ci } 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci testonly = [boolean] 181e41f4b71Sopenharmony_ci license_as_sources = [] 182e41f4b71Sopenharmony_ci license_file = [] # A .txt file. 183e41f4b71Sopenharmony_ci remove_configs = [] 184e41f4b71Sopenharmony_ci static_link = [] 185e41f4b71Sopenharmony_ci install_images = [] 186e41f4b71Sopenharmony_ci module_install_dir = "" # Module installation directory, starting from system/ or vendor/. 187e41f4b71Sopenharmony_ci relative_install_dir = "" 188e41f4b71Sopenharmony_ci symlink_target_name = [] 189e41f4b71Sopenharmony_ci output_dir = [directory] # Directory in which output files are located. 190e41f4b71Sopenharmony_ci install_enable = [boolean] 191e41f4b71Sopenharmony_ci version_script = [] 192e41f4b71Sopenharmony_ci use_exceptions = [] 193e41f4b71Sopenharmony_ci} 194e41f4b71Sopenharmony_ci``` 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**ohos_source_set** example 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci```shell 199e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 200e41f4b71Sopenharmony_ciohos_source_set("helloworld") { 201e41f4b71Sopenharmony_ci sources = ["file"] # .c files. 202e41f4b71Sopenharmony_ci include_dirs = [] # Directories to be included. 203e41f4b71Sopenharmony_ci configs = [] # Configuration. 204e41f4b71Sopenharmony_ci public = [] # .h header files. 205e41f4b71Sopenharmony_ci defines = [] 206e41f4b71Sopenharmony_ci public_configs = [] 207e41f4b71Sopenharmony_ci part_name = "" # Component name. 208e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 209e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci external_deps = [ # Dependent modules that belong to different components. 212e41f4b71Sopenharmony_ci "part_name:module_name", # The value is in the Component_name:Module_name format. 213e41f4b71Sopenharmony_ci ] # The dependent modules must be declared in inner_kits by the dependent component. 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci # Sanitizer configuration. Each item is optional, and is false or left unspecified by default. 216e41f4b71Sopenharmony_ci sanitize = { 217e41f4b71Sopenharmony_ci # Sanitizer settings 218e41f4b71Sopenharmony_ci cfi = [boolean] # Whether to enable the control-flow integrity (CFI) check. 219e41f4b71Sopenharmony_ci cfi_cross_dso = [boolean] # Whether to enable the cross-DSO CFI check. 220e41f4b71Sopenharmony_ci integer_overflow = [boolean] # Whether to enable the integer overflow check. 221e41f4b71Sopenharmony_ci boundary_sanitize = [boolean] # Whether to enable the boundary check. 222e41f4b71Sopenharmony_ci ubsan = [boolean] # Whether to enable some Undefined Behavior Sanitizer (UBSAN) options. 223e41f4b71Sopenharmony_ci all_ubsan = [boolean] # Whether to enable all UBSAN options. 224e41f4b71Sopenharmony_ci ... 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci debug = [boolean] # Whether to enable the debug mode. 227e41f4b71Sopenharmony_ci blocklist = [string] # Path of the blocklist. 228e41f4b71Sopenharmony_ci } 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci testonly = [boolean] 231e41f4b71Sopenharmony_ci license_as_sources = [] 232e41f4b71Sopenharmony_ci license_file = [] 233e41f4b71Sopenharmony_ci remove_configs = [] 234e41f4b71Sopenharmony_ci no_default_deps = [] 235e41f4b71Sopenharmony_ci license_file = [] # A .txt file. 236e41f4b71Sopenharmony_ci license_as_sources = [] 237e41f4b71Sopenharmony_ci use_exceptions = [] 238e41f4b71Sopenharmony_ci} 239e41f4b71Sopenharmony_ci``` 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci> **NOTE** 242e41f4b71Sopenharmony_ci> 243e41f4b71Sopenharmony_ci> - Only **sources** and **part_name** are mandatory. 244e41f4b71Sopenharmony_ci> - For details about the Sanitizer configuration, see [Using Sanitizer](subsys-build-reference.md#using-sanitizer). 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci### Prebuilt Template Example 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ciThe path of the .gni file of the prebuilt templates is **openharmony/build/templates/cxx/prebuilt.gni**. 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**ohos_prebuilt_executable** example 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci```shell 255e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 256e41f4b71Sopenharmony_ciohos_prebuilt_executable("helloworld") { 257e41f4b71Sopenharmony_ci source = "file" # Source. 258e41f4b71Sopenharmony_ci output = [] 259e41f4b71Sopenharmony_ci install_enable = [boolean] 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 262e41f4b71Sopenharmony_ci public_configs = [] 263e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 264e41f4b71Sopenharmony_ci part_name = "" # Component name. 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci testonly = [boolean] 267e41f4b71Sopenharmony_ci visibility = [] 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci install_images = [] 270e41f4b71Sopenharmony_ci module_install_dir = "" # Module installation directory, starting from system/ or vendor/. 271e41f4b71Sopenharmony_ci relative_install_dir = "" # Relative module installation directory (relative to system/etc). If module_install_dir is configured, the parameter does not take effect. 272e41f4b71Sopenharmony_ci symlink_target_name = [] 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci license_file = [] # A .txt file. 276e41f4b71Sopenharmony_ci license_as_sources = [] 277e41f4b71Sopenharmony_ci} 278e41f4b71Sopenharmony_ci``` 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**ohos_prebuilt_shared_library** example 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci```shell 283e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 284e41f4b71Sopenharmony_ciohos_prebuilt_shared_library("helloworld") { 285e41f4b71Sopenharmony_ci source = "file" # Source file, normally with a file name extension .so. 286e41f4b71Sopenharmony_ci output = [] 287e41f4b71Sopenharmony_ci install_enable = [boolean] 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 290e41f4b71Sopenharmony_ci public_configs = [] 291e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 292e41f4b71Sopenharmony_ci part_name = "" # Component name. 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci testonly = [boolean] 295e41f4b71Sopenharmony_ci visibility = [] 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci install_images = [] 298e41f4b71Sopenharmony_ci module_install_dir = "" # Module installation directory, starting from system/ or vendor/. 299e41f4b71Sopenharmony_ci relative_install_dir = "" # Relative module installation directory (relative to system/etc). If module_install_dir is configured, the parameter does not take effect. 300e41f4b71Sopenharmony_ci symlink_target_name = [string] 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci license_file = [string] # A .txt file. 304e41f4b71Sopenharmony_ci license_as_sources = [] 305e41f4b71Sopenharmony_ci} 306e41f4b71Sopenharmony_ci``` 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci**ohos_prebuilt_static_library** example 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci```shell 311e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 312e41f4b71Sopenharmony_ciohos_prebuilt_static_library("helloworld") { 313e41f4b71Sopenharmony_ci source = "file" # Source file, normally with a file name extension .so. 314e41f4b71Sopenharmony_ci output = [] 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 317e41f4b71Sopenharmony_ci public_configs = [] 318e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 319e41f4b71Sopenharmony_ci part_name = "" # Component name. 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci testonly = [boolean] 322e41f4b71Sopenharmony_ci visibility = [] 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci license_file = [string] # A .txt file. 325e41f4b71Sopenharmony_ci license_as_sources = [] 326e41f4b71Sopenharmony_ci} 327e41f4b71Sopenharmony_ci``` 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci> **NOTE**<br> Only **sources** and **part_name** are mandatory. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci### HAP Templates 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ciFor details about the HAP templates, see [HAP Build Guide](subsys-build-gn-hap-compilation-guide.md). 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci### Rust Templates 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ciFor details about the Rust templates, see [Rust Module Configuration Rules and Guide](subsys-build-rust-compilation.md). 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci### Other Templates 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**ohos_prebuilt_etc** example: 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci```shell 344e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 345e41f4b71Sopenharmony_ciohos_prebuilt_etc("helloworld") { 346e41f4b71Sopenharmony_ci # The most common attributes of the ohos_prebuilt_etc template. 347e41f4b71Sopenharmony_ci source = "file" # Single source file. 348e41f4b71Sopenharmony_ci module_install_dir = "" # Module installation directory, starting from system/ or vendor/. 349e41f4b71Sopenharmony_ci subsystem_name = ""# Subsystem name. 350e41f4b71Sopenharmony_ci part_name = "" # Component name. This parameter is mandatory. 351e41f4b71Sopenharmony_ci install_images = [] 352e41f4b71Sopenharmony_ci relative_install_dir = "" # Relative module installation directory (relative to system/etc). If module_install_dir is configured, the parameter does not take effect. 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci # Uncommon attributes of the ohos_prebuilt_etc template: 355e41f4b71Sopenharmony_ci deps = [] # Dependent modules that belong to the same component. 356e41f4b71Sopenharmony_ci testonly = [boolean] 357e41f4b71Sopenharmony_ci visibility = [] 358e41f4b71Sopenharmony_ci public_configs = [] 359e41f4b71Sopenharmony_ci symlink_target_name = [string] 360e41f4b71Sopenharmony_ci license_file = [string] 361e41f4b71Sopenharmony_ci license_as_sources = [] 362e41f4b71Sopenharmony_ci} 363e41f4b71Sopenharmony_ci``` 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**ohos_sa_profile** example: 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci```shell 368e41f4b71Sopenharmony_ciimport("//build/ohos.gni") 369e41f4b71Sopenharmony_ciohos_sa_profile("helloworld") { 370e41f4b71Sopenharmony_ci sources = [".xml"] # .xml file. 371e41f4b71Sopenharmony_ci part_name = "" # Component name. 372e41f4b71Sopenharmony_ci subsystem_name = "" # Subsystem name. 373e41f4b71Sopenharmony_ci} 374e41f4b71Sopenharmony_ci``` 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci> **NOTE** 377e41f4b71Sopenharmony_ci> 378e41f4b71Sopenharmony_ci> Only **sources** and **part_name** are mandatory. 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci## Adding and Building a Module 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ciThe following figure shows the logic for adding a module. Generally, you need to add a module to a component of a subsystem. If there is no subsystem or component, you must add the subsystem and component first. Note that the chip solution is a special component and does not have a subsystem. 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci- Add a module to an existing component. 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci- Add a module to a new component. 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci- Add a module to a new subsystem. 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci  393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci**Adding a Module to an Existing Component** 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci1. Configure the **BUILD.gn** file in the module directory and select the GN template. 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci2. Modify the **bundle.json** file. 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci ```shell 401e41f4b71Sopenharmony_ci { 402e41f4b71Sopenharmony_ci "name": "@ohos/<component_name>, # HPM component name, in the "@Organization/Component_name" format. 403e41f4b71Sopenharmony_ci "description": "xxxxxxxxxxxxxxxxxxx", # Description of the component functions. 404e41f4b71Sopenharmony_ci "version": "3.1", # Version, which must be the same as the version of OpenHarmony. 405e41f4b71Sopenharmony_ci "license": "MIT", # Component license. 406e41f4b71Sopenharmony_ci "publishAs": "code-segment", # HPM package release mode. The default value is code-segment. 407e41f4b71Sopenharmony_ci "segment": { 408e41f4b71Sopenharmony_ci "destPath": "third_party/nghttp2" 409e41f4b71Sopenharmony_ci }, # Code restoration path (source code path) set when publishAs is code-segment. 410e41f4b71Sopenharmony_ci "dirs": {}, # Directory structure of the HPM package. This field is mandatory and can be left empty. 411e41f4b71Sopenharmony_ci "scripts": {}, # Scripts to be executed. This field is mandatory and can be left empty. 412e41f4b71Sopenharmony_ci "licensePath": "COPYING", 413e41f4b71Sopenharmony_ci "readmePath": { 414e41f4b71Sopenharmony_ci "en": "README.rst" 415e41f4b71Sopenharmony_ci }, 416e41f4b71Sopenharmony_ci "component": { # Component attributes. 417e41f4b71Sopenharmony_ci "name": "<component_name>", # Component name. 418e41f4b71Sopenharmony_ci "subsystem": "", # Subsystem to which the component belongs. 419e41f4b71Sopenharmony_ci "syscap": [], # System capabilities provided by the component for applications. 420e41f4b71Sopenharmony_ci "features": [], # List of configurable features of the component. Generally, this parameter corresponds to sub_component in build. 421e41f4b71Sopenharmony_ci "adapted_system_type": [], # Types of adapted systems. The value can be mini, small, standard, or their combinations. 422e41f4b71Sopenharmony_ci "rom": "xxxKB" # ROM baseline. If there is no baseline, enter the current value. 423e41f4b71Sopenharmony_ci "ram": "xxxKB", # RAM baseline. If there is no baseline, enter the current value. 424e41f4b71Sopenharmony_ci "deps": { 425e41f4b71Sopenharmony_ci "components": [ # Other components on which this component depends. 426e41f4b71Sopenharmony_ci "third_party": [ # Third-party open-source software on which this component depends. 427e41f4b71Sopenharmony_ci }, 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci "build": { # Build-related configuration. 430e41f4b71Sopenharmony_ci "sub_component": [ 431e41f4b71Sopenharmony_ci "//foundation/arkui/napi:napi_packages", # Existing module 1. 432e41f4b71Sopenharmony_ci "//foundation/arkui/napi:napi_packages_ndk" # Existing module 2. 433e41f4b71Sopenharmony_ci "//foundation/arkui/napi:new" # Module to add. 434e41f4b71Sopenharmony_ci ], # Component build entry. Configure the module here. 435e41f4b71Sopenharmony_ci "inner_kits": [], # APIs between components. 436e41f4b71Sopenharmony_ci "test": [] # Entry for building the component's test cases. 437e41f4b71Sopenharmony_ci } 438e41f4b71Sopenharmony_ci } 439e41f4b71Sopenharmony_ci } 440e41f4b71Sopenharmony_ci ``` 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci > **NOTE**<br>The **bundle.json** file must be in the folder of the corresponding subsystem. 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci3. Start the build and check whether a .so file or binary file is generated. 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**Creating a Component and Adding a Module** 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci1. Configure the **BUILD.gn** file in the module directory and select the corresponding GN template. Note that **part_name** in the **BUILD.gn** file is the name of the component to add. 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci2. Create a **bundle.json** file in the folder of the corresponding subsystem. 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci3. Add the new component to the end of existing components in **vendor/{product_company}/{product-name}/config.json**. 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci ```shell 455e41f4b71Sopenharmony_ci "subsystems": [ 456e41f4b71Sopenharmony_ci { 457e41f4b71Sopenharmony_ci "subsystem": "Subsystem to which the component belongs", 458e41f4b71Sopenharmony_ci "components": [ 459e41f4b71Sopenharmony_ci {"component": "Component 1 name", "features":[]}, # Existing component 1 in the subsystem 460e41f4b71Sopenharmony_ci { "component": "Component 2 name", "features":[] }, # Existing component 2 in the subsystem 461e41f4b71Sopenharmony_ci {"component": "New component name", "features":[]} # New component in the subsystem 462e41f4b71Sopenharmony_ci ] 463e41f4b71Sopenharmony_ci }, 464e41f4b71Sopenharmony_ci . 465e41f4b71Sopenharmony_ci ] 466e41f4b71Sopenharmony_ci ``` 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci4. Start the build and check whether a .so file or binary file is generated. 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**Creating a Subsystem and Adding a Module** 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci1. Configure the **BUILD.gn** file in the module directory and select the corresponding GN template. This step is the same as Step 1 in "Creating a Component and Adding a Module." 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci2. Create a **bundle.json** file in the folder of the component of the subsystem. This step is the same as Step 2 in "Creating a Component and Adding a Module." 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci3. Modify the **subsystem_config.json** file in the **build** directory. 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci ```shell 480e41f4b71Sopenharmony_ci { 481e41f4b71Sopenharmony_ci "Subsystem 1 name": { # Existing subsystem 1 482e41f4b71Sopenharmony_ci "path": "Subsystem 1 directory", 483e41f4b71Sopenharmony_ci "name": "Subsystem 1 name" 484e41f4b71Sopenharmony_ci }, 485e41f4b71Sopenharmony_ci "Subsystem 2 name": { # Existing subsystem 2 486e41f4b71Sopenharmony_ci "path": "Subsystem 2 directory", 487e41f4b71Sopenharmony_ci "name": "Subsystem 2 name" 488e41f4b71Sopenharmony_ci }, 489e41f4b71Sopenharmony_ci "Subsystem name new": { # Subsystem to add 490e41f4b71Sopenharmony_ci "path": "New subsystem directory", 491e41f4b71Sopenharmony_ci "name": "New subsystem name" 492e41f4b71Sopenharmony_ci }, 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci } 495e41f4b71Sopenharmony_ci ``` 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci The **subsystem_config.json** file defines the subsystems and their directories. When adding a subsystem, specify **path** and **name** for the subsystem. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci4. If **product-name** in the **vendor/{product_company}/{product-name}** directory is **hispark_taurus_standard**, add the new component information to the end of existing components in the **config.json** file. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci ```shell 502e41f4b71Sopenharmony_ci "subsystems": [ 503e41f4b71Sopenharmony_ci { 504e41f4b71Sopenharmony_ci "subsystem": "arkui", # Name of the existing subsystem 505e41f4b71Sopenharmony_ci "components": [ # All components of the subsystem 506e41f4b71Sopenharmony_ci { 507e41f4b71Sopenharmony_ci "component": "ace_engine_standard", # Name of the existing component 508e41f4b71Sopenharmony_ci "features": [] 509e41f4b71Sopenharmony_ci }, 510e41f4b71Sopenharmony_ci { 511e41f4b71Sopenharmony_ci "component": "napi", # Name of the existing component 512e41f4b71Sopenharmony_ci "features": [] 513e41f4b71Sopenharmony_ci } 514e41f4b71Sopenharmony_ci { 515e41f4b71Sopenharmony_ci "component": "component_new1", # Name of the new component to add 516e41f4b71Sopenharmony_ci "features": [] 517e41f4b71Sopenharmony_ci } 518e41f4b71Sopenharmony_ci ] 519e41f4b71Sopenharmony_ci }, 520e41f4b71Sopenharmony_ci { 521e41f4b71Sopenharmony_ci "subsystem": "subsystem_new", # Name of the new subsystem to add. 522e41f4b71Sopenharmony_ci "components": [ 523e41f4b71Sopenharmony_ci { 524e41f4b71Sopenharmony_ci "component": "component_new2", # Name of the component to be added to the new subsystem 525e41f4b71Sopenharmony_ci "features": [] 526e41f4b71Sopenharmony_ci } 527e41f4b71Sopenharmony_ci ] 528e41f4b71Sopenharmony_ci }, 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ci ] 531e41f4b71Sopenharmony_ci ``` 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci4. Start the build and check whether a .so file or binary file is generated. 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci**Building a Module** 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ciYou can start the build by using the [CLI or hb tool](subsys-build-all.md#build-commands). The following uses the CLI as an example: 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ciRun the **--build-target** *Module_name* command to build a module separately. 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci ```shell 543e41f4b71Sopenharmony_ci ./build.sh --build-target Module_name 544e41f4b71Sopenharmony_ci ``` 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ciBuild a product. For example, to build hispark_taurus_standard, run the following command: 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci ```shell 549e41f4b71Sopenharmony_ci ./build.sh --product-name hispark_taurus_standard --build-target Module_name --ccache 550e41f4b71Sopenharmony_ci ``` 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ciBuild the component to which the module belongs. 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci ```shell 555e41f4b71Sopenharmony_ci ./build.sh --product-name hispark_taurus_standard --build-target musl --build-target Module_name --ccache 556e41f4b71Sopenharmony_ci ``` 557