1b1994897Sopenharmony_ci# Bootstrapping 2b1994897Sopenharmony_ci 3b1994897Sopenharmony_ciCurrently an officially supported host OS for development, building and testing is Ubuntu 18.04 and Ubuntu 20.04. 4b1994897Sopenharmony_ciThe full list of packages required for building and testing the project is specified in 5b1994897Sopenharmony_ci`scripts/deps-lists` files. These packages can be installed either manually or by running 6b1994897Sopenharmony_cia bootstrap script: 7b1994897Sopenharmony_ci 8b1994897Sopenharmony_ci``` 9b1994897Sopenharmony_ci$ sudo ./scripts/install-deps-ubuntu 10b1994897Sopenharmony_ci``` 11b1994897Sopenharmony_ci 12b1994897Sopenharmony_ciFor more bootstrapping options, run: 13b1994897Sopenharmony_ci 14b1994897Sopenharmony_ci``` 15b1994897Sopenharmony_ci$ sudo ./scripts/install-deps-ubuntu --help 16b1994897Sopenharmony_ci``` 17b1994897Sopenharmony_ci 18b1994897Sopenharmony_ciE.g. for development purposes you should run: 19b1994897Sopenharmony_ci 20b1994897Sopenharmony_ci``` 21b1994897Sopenharmony_ci$ sudo ./scripts/install-deps-ubuntu -i=dev 22b1994897Sopenharmony_ci``` 23b1994897Sopenharmony_ci 24b1994897Sopenharmony_ciIf you want additionally to install Python dependencies for running tests add a parameter `-i=test`: 25b1994897Sopenharmony_ci 26b1994897Sopenharmony_ci``` 27b1994897Sopenharmony_ci$ sudo ./scripts/install-deps-ubuntu -i=dev -i=test 28b1994897Sopenharmony_ci``` 29b1994897Sopenharmony_ciIt creates a virtual environment .venv-panda in your home directory with all required dependencies. 30b1994897Sopenharmony_ciLater, tests Python scripts can activate this environment. If you already have run with the parameter `-i=test` 31b1994897Sopenharmony_cithe second time it might be skipped. 32b1994897Sopenharmony_ci 33b1994897Sopenharmony_ci# Third party 34b1994897Sopenharmony_ci 35b1994897Sopenharmony_ciPanda uses third party libraries. To install the libraries and apply patches, run: 36b1994897Sopenharmony_ci 37b1994897Sopenharmony_ci``` 38b1994897Sopenharmony_ci$ ./scripts/install-third-party --force-clone 39b1994897Sopenharmony_ci``` 40b1994897Sopenharmony_ci 41b1994897Sopenharmony_ci# Building 42b1994897Sopenharmony_ci 43b1994897Sopenharmony_ciAssuming your system is bootstrapped, please run the following commands in the root of the project: 44b1994897Sopenharmony_ci 45b1994897Sopenharmony_ci``` 46b1994897Sopenharmony_ci$ mkdir panda-build 47b1994897Sopenharmony_ci$ cd panda-build 48b1994897Sopenharmony_ci$ cmake /path/to/panda/repository -GNinja 49b1994897Sopenharmony_ci$ ninja 50b1994897Sopenharmony_ci``` 51b1994897Sopenharmony_ci 52b1994897Sopenharmony_ciThis will build Panda in debug mode with your default C++ compiler. All supported compilers can be 53b1994897Sopenharmony_cifound in `cmake/toolchain`. E.g., to build with Clang 14, pass a path to the corresponding toolchain 54b1994897Sopenharmony_cifile during configuration: 55b1994897Sopenharmony_ci 56b1994897Sopenharmony_ci``` 57b1994897Sopenharmony_ci$ cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/panda/repository/cmake/toolchain/host_clang_14.cmake /path/to/panda/repository 58b1994897Sopenharmony_ci``` 59b1994897Sopenharmony_ci 60b1994897Sopenharmony_ci## Explicitly setting build types 61b1994897Sopenharmony_ci 62b1994897Sopenharmony_ciRecommended way to build Panda is to set `CMAKE_BUILD_TYPE` variable explicitly during configurations. Supported values are: 63b1994897Sopenharmony_ci 64b1994897Sopenharmony_ci| Mode | Assertions | Optimizations | Debug info | 65b1994897Sopenharmony_ci| ---- | ---------- | ------------- | ---------- | 66b1994897Sopenharmony_ci| `Debug ` | Yes | None (CMake default) | `-g` (CMake default) | 67b1994897Sopenharmony_ci| `Release` | No | `-O3` (CMake default) | None (CMake default) | 68b1994897Sopenharmony_ci| `FastVerify` | Yes | `-O2` | `-ggdb3` | 69b1994897Sopenharmony_ci 70b1994897Sopenharmony_ciNotes: 71b1994897Sopenharmony_ci 72b1994897Sopenharmony_ci* Other common modes (`RelWithDebInfo`, `MinSizeRel`, `DebugDetailed`) should work but they are not tested in CI. 73b1994897Sopenharmony_ci* Unlike `RelWithDebInfo`, `FastVerify` preserves assertions (and provides more verbose debug information). 74b1994897Sopenharmony_ci Use this build type for running heavy test suites when you want both fast-running code and debuggability. 75b1994897Sopenharmony_ci* `DebugDetailed` gives more debug information than `Debug`, it can be usefull for debugging unit tests for example. 76b1994897Sopenharmony_ci 77b1994897Sopenharmony_ciExample: 78b1994897Sopenharmony_ci 79b1994897Sopenharmony_ci``` 80b1994897Sopenharmony_ci$ cmake -DCMAKE_BUILD_TYPE=Release ... 81b1994897Sopenharmony_ci``` 82b1994897Sopenharmony_ci 83b1994897Sopenharmony_ci## Building with LLVM Backend 84b1994897Sopenharmony_ci 85b1994897Sopenharmony_ciIf you want to build Ark with LLVM Backend you need to build first special modified LLVM 15 binaries. 86b1994897Sopenharmony_ci * Clone repository from [gitee.com](https://gitee.com/openharmony/third_party_llvm-project) 87b1994897Sopenharmony_ci * Check [README](scripts/llvm/README.md) file about build process 88b1994897Sopenharmony_ci * Use build [script](scripts/llvm/build_llvm.sh) 89b1994897Sopenharmony_ci 90b1994897Sopenharmony_ciIf modified LLVM available in `/opt`, the following two options are necessary 91b1994897Sopenharmony_cito build Ark with LLVM Backend functions. 92b1994897Sopenharmony_ci 93b1994897Sopenharmony_ci```cmake 94b1994897Sopenharmony_cicmake -DPANDA_LLVM_BACKEND=true -DLLVM_TARGET_PATH=/opt/llvm-15-{type}-{arch} ... 95b1994897Sopenharmony_ci``` 96b1994897Sopenharmony_ci 97b1994897Sopenharmony_ciThe `PANDA_LLVM_BACKEND` enables: 98b1994897Sopenharmony_ci 99b1994897Sopenharmony_ci1. LLVM Irtoc Interpreter. Use `-DPANDA_LLVM_INTERPRETER=OFF` to disable. 100b1994897Sopenharmony_ci2. LLVM Fastpaths compilation. Use `-DPANDA_LLVM_FASTPATH=OFF` to disable. 101b1994897Sopenharmony_ci3. LLVM Interpreter inlining. Use `-DPANDA_LLVM_INTERPRETER_INLINING=OFF` to disable. 102b1994897Sopenharmony_ci4. LLVM AOT compiler. Use `-DPANDA_LLVM_AOT=OFF` to disable. 103b1994897Sopenharmony_ci 104b1994897Sopenharmony_ci`PANDA_LLVM_INTERPRETER`, `PANDA_LLVM_FASTPATH`, and `PANDA_LLVM_AOT` are `ON` if `PANDA_LLVM_BACKEND` is turned on. 105b1994897Sopenharmony_ci 106b1994897Sopenharmony_ciIt is recommended to choose `clang` compiler using toolchain files: `-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/host_clang_14.cmake`. 107b1994897Sopenharmony_ciBy default GNU compiler `c++` is used, but some features are not available in such `gcc` builds. 108b1994897Sopenharmony_ci 109b1994897Sopenharmony_ci## Cross ARM64 build with LLVM Backend 110b1994897Sopenharmony_ci 111b1994897Sopenharmony_ciFor cross-build, when e.g. `-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cross-clang-14-qemu-aarch64.cmake` is used, 112b1994897Sopenharmony_citwo LLVM-paths options are required when all LLVM Backend functions are enabled. 113b1994897Sopenharmony_ci * First one is target LLVM, like `-DLLVM_TARGET_PATH=/opt/llvm-15-debug-aarch64` 114b1994897Sopenharmony_ci * It is required for AOT, so, alternatively, you can use `-DPANDA_LLVM_AOT=OFF`. 115b1994897Sopenharmony_ci * Second one is host LLVM, like `-DLLVM_HOST_PATH=/opt/llvm-15-debug-x86_64` 116b1994897Sopenharmony_ci * It is required for Irtoc compilation, so, alternatively, you can disable appropriate Interpreter and FastPath options (see above). 117b1994897Sopenharmony_ci 118b1994897Sopenharmony_ci## Running tests with QEMU for cross-compiled aarch64/arm builds 119b1994897Sopenharmony_ci 120b1994897Sopenharmony_ciRecommended QEMU version for running tests is 6.2.0 (but 5.1+ should be ok, too). By default, it is downloaded and installed during environment bootstrap. Any system-installed package is left intact. If recommended QEMU version is not accessible via $PATH it can be specified during configuration time: 121b1994897Sopenharmony_ci 122b1994897Sopenharmony_ci``` 123b1994897Sopenharmony_ci# If QEMU is available as /opt/qemu-6.2.0/bin/qemu-aarch64 124b1994897Sopenharmony_ci$ cmake -DQEMU_PREFIX=/opt/qemu-6.2.0 ... 125b1994897Sopenharmony_ci``` 126b1994897Sopenharmony_ci 127b1994897Sopenharmony_ci## Building with GN 128b1994897Sopenharmony_ci 129b1994897Sopenharmony_ci### Using bootstrap 130b1994897Sopenharmony_ci 131b1994897Sopenharmony_ciBuild `arkts_bin`, `ark_aot`, `es2panda`, `verifier_bin` and `ets_interop_js_napi` targets. 132b1994897Sopenharmony_ci``` 133b1994897Sopenharmony_ci./scripts/build-panda-with-gn 134b1994897Sopenharmony_ci``` 135b1994897Sopenharmony_ci 136b1994897Sopenharmony_ci### Mannually 137b1994897Sopenharmony_ci 138b1994897Sopenharmony_ci1. Getting GN binary 139b1994897Sopenharmony_ci 140b1994897Sopenharmony_ci``` 141b1994897Sopenharmony_ci$ git clone https://gn.googlesource.com/gn 142b1994897Sopenharmony_ci$ cd gn 143b1994897Sopenharmony_ci$ python build/gen.py 144b1994897Sopenharmony_ci$ ninja -C out 145b1994897Sopenharmony_ci``` 146b1994897Sopenharmony_ci 147b1994897Sopenharmony_ci2. Build panda using gn (`arkts_asm`, `arkts_disasm`, `ark_aot`, `ark_aotdump`, `arkts_bin`, `es2panda`, and `verifier_bin` targets are supported) 148b1994897Sopenharmony_ci 149b1994897Sopenharmony_ci``` 150b1994897Sopenharmony_ci$ cd /path/to/panda/repository 151b1994897Sopenharmony_ci$ /path/to/gn/repository/out/gn gen out 152b1994897Sopenharmony_ci$ ninja -C out arkts_bin 153b1994897Sopenharmony_ci``` 154b1994897Sopenharmony_ciWhen standard system, use 155b1994897Sopenharmony_ci``` 156b1994897Sopenharmony_ci$ cd /path/to/panda/repository 157b1994897Sopenharmony_ci$ /path/to/gn/repository/out/gn --args=is_standard_system=true gen out 158b1994897Sopenharmony_ci$ ninja -C out <target name> 159b1994897Sopenharmony_ci``` 160b1994897Sopenharmony_ciTo use LLVM Backend add the following arguments: 161b1994897Sopenharmony_ci``` 162b1994897Sopenharmony_ci$ /path/to/gn/repository/out/gn out is_llvmbackend=true llvm_target_dir="/opt/llvm-15-{type}-{arch}" ... 163b1994897Sopenharmony_ci``` 164b1994897Sopenharmony_ciSetting `is_llvmbackend=true` option enables the same scenarios as `-DPANDA_LLVM_BACKEND=true` option in cmake builds 165b1994897Sopenharmony_ci 166b1994897Sopenharmony_ci## Further reading 167b1994897Sopenharmony_ci 168b1994897Sopenharmony_ci* For more details, please see [build system readme](cmake/README.md). 169b1994897Sopenharmony_ci 170b1994897Sopenharmony_ci# Testing 171b1994897Sopenharmony_ci 172b1994897Sopenharmony_ciFor testing, the following umbrella targets that guarantee building prior to running may be used: 173b1994897Sopenharmony_ci 174b1994897Sopenharmony_ci* `tests`, for running all testing suites. 175b1994897Sopenharmony_ci* `tests_full`, for running all testing suites and various code linters. 176b1994897Sopenharmony_ci 177b1994897Sopenharmony_ci# Clang tools 178b1994897Sopenharmony_ci 179b1994897Sopenharmony_ci`clang-format` and `clang-tidy` checks are integrated into build system and can be called by target of build system: 180b1994897Sopenharmony_ci``` 181b1994897Sopenharmony_ci$ ninja code-style-check # clang-format 182b1994897Sopenharmony_ci$ ninja clang-tidy-check # clang-tidy 183b1994897Sopenharmony_ci``` 184b1994897Sopenharmony_ci 185b1994897Sopenharmony_ci# Test coverage 186b1994897Sopenharmony_ci 187b1994897Sopenharmony_ciIn order to measure bytecode optimizer coverage, configure your build with -DENABLE_BYTECODE_OPTIMIZER_COVERAGE=true. Then run: 188b1994897Sopenharmony_ci``` 189b1994897Sopenharmony_ci$ ninja bytecode_optimizer_coverage 190b1994897Sopenharmony_ci``` 191b1994897Sopenharmony_ci 192b1994897Sopenharmony_ci# Benchmarking 193b1994897Sopenharmony_ci 194b1994897Sopenharmony_ciTo build and run benchmarks, please use the umbrella target `benchmarks` or any of its 195b1994897Sopenharmony_cidependencies. Please see the root `CMakeLists.txt` for more details. 196b1994897Sopenharmony_ci 197b1994897Sopenharmony_ciNB! Make sure that you configure your build with `-DCMAKE_BUILD_TYPE=Release`, otherwise 198b1994897Sopenharmony_ciyour run will most likely be dead slow. 199b1994897Sopenharmony_ci 200b1994897Sopenharmony_ci# Running 201b1994897Sopenharmony_ci 202b1994897Sopenharmony_ci## Running assembler 203b1994897Sopenharmony_ci 204b1994897Sopenharmony_ciAssuming that you are in `panda-build` directory, please run: 205b1994897Sopenharmony_ci 206b1994897Sopenharmony_ci``` 207b1994897Sopenharmony_ci$ ./bin/ark_asm /path/to/panda-assembly.pa /path/to/binary/output.abc 208b1994897Sopenharmony_ci``` 209b1994897Sopenharmony_ci 210b1994897Sopenharmony_ci## Running interpreter 211b1994897Sopenharmony_ci 212b1994897Sopenharmony_ciAssuming that your main function is defined as `.function main(...)` in the assembly listing, 213b1994897Sopenharmony_ciand `/path/to/binary/output.abc` is the result of the assembler, please run: 214b1994897Sopenharmony_ci 215b1994897Sopenharmony_ci``` 216b1994897Sopenharmony_ci$ ./bin/ark /path/to/binary/output.abc _GLOBAL::main 217b1994897Sopenharmony_ci``` 218