diff --git a/ohos/BUILD.gn b/ohos/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2087117443a895c843be19711960d88f691aec66 --- /dev/null +++ b/ohos/BUILD.gn @@ -0,0 +1,74 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +import("//build/ohos.gni") +import("//build/config/clang/clang.gni") +mesa3d_libs_dir = "$root_build_dir/packages/phone/mesa3d" + +mesa3d_gallium_symlinks = [] +if (defined(product_build_config.mesa3d_gallium_symlinks)) { + mesa3d_gallium_symlinks = product_build_config.mesa3d_gallium_symlinks +} + +mesa3d_all_lib_items = [ + ["libEGL.so.1.0.0", ["libEGL.so", "libEGL.so.1"]], + ["libgbm.so.1.0.0", ["libgbm.so", "libgbm.so.1"]], + ["libglapi.so.0.0.0", ["libglapi.so", "libglapi.so.0"]], + ["libGLESv1_CM.so.1.1.0", ["libGLESv1_CM.so", "libGLESv1_CM.so.1"]], + ["libGLESv2.so.2.0.0", ["libGLESv2.so", "libGLESv2.so.2", "libGLESv3.so"]], + ["libgallium_dri.so", mesa3d_gallium_symlinks] +] + +action("mesa3d_build") { + script = "build_mesa3d.py" + deps = [ + "//foundation/graphic/standard/frameworks/surface:surface", + "//third_party/expat:expat", + "//third_party/wayland_standard:libwayland_client", + "//third_party/wayland_standard:libwayland_server", + "//third_party/wayland_standard:libwayland_client.0", + "//third_party/wayland_standard:libwayland_server.0", + ] + outputs = [] + foreach(item, mesa3d_all_lib_items) { + name = item[0] + outputs += [ "$mesa3d_libs_dir/$name" ] + } + args = [ rebase_path(root_build_dir) ] +} + +mesa3d_all_lib_deps = [] + +foreach(item, mesa3d_all_lib_items) { + name = item[0] + ohos_prebuilt_shared_library(name) { + source = "$mesa3d_libs_dir/$name" + deps = [ ":mesa3d_build" ] + symlink_target_name = item[1] + install_enable = true + install_images = [ system_base_dir ] + subsystem_name = "rockchip_products" + part_name = "rockchip_products" + } + mesa3d_all_lib_deps += [ ":$name" ] +} + +group("mesa3d_all_libs"){ + deps = mesa3d_all_lib_deps +} diff --git a/ohos/README_zh.md b/ohos/README_zh.md index b9cdbefc3e32c064b975ca58a63b09c35b92249f..e7dde763793fbd54c23dff4bf3c81940cebc5b62 100644 --- a/ohos/README_zh.md +++ b/ohos/README_zh.md @@ -36,6 +36,6 @@ sudo apt-get install pkg-config ``` cd ~/mesa3d -python ohos/build_wayland_and_gbm.py ~/openharmony rk3568 ~/mesa3d +python ohos/build_ohos.py ~/openharmony rk3568 ~/mesa3d ``` \ No newline at end of file diff --git a/ohos/build_mesa3d.py b/ohos/build_mesa3d.py new file mode 100755 index 0000000000000000000000000000000000000000..4d7676616ffd6aca65c39df761a44de343857e68 --- /dev/null +++ b/ohos/build_mesa3d.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (c) 2022 Huawei Device Co., Ltd. + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +import sys +import os +import os.path +import subprocess +import multiprocessing +import glob +import shutil +from meson_cross_process import prepare_environment + +# input /path/to/openharmony/out/rk3568 + +nproc = multiprocessing.cpu_count() +out_dir = sys.argv[1] +mesa3d_install_dir = os.path.join(out_dir, 'packages', 'phone', 'mesa3d') +product = os.path.basename(out_dir) +project_dir = os.path.dirname(os.path.dirname(out_dir)) +project_dir = os.path.abspath(project_dir) +mesa3d_dir = os.path.dirname(os.path.dirname(__file__)) +mesa3d_dir = os.path.abspath(mesa3d_dir) +pkgconf_dir = os.path.join(mesa3d_dir, './pkgconfig') +os.environ['PKG_CONFIG_PATH'] = pkgconf_dir + +# workaround: using system python instead of prebuilt python +path_old = os.environ['PATH'].split(':') +path_filter = lambda p: not p.endswith('/prebuilts/python/linux-x86/3.8.5/bin') +path_new = ':'.join(filter(path_filter, path_old)) +os.environ['PATH'] = path_new + +os.chdir(mesa3d_dir) +prepare_environment(project_dir, product) + +meson_cmd = [ + 'meson', + 'setup', + mesa3d_dir, + 'build-ohos', + '-Dplatforms=ohos', + '-Degl-native-platform=ohos', + '-Ddri-drivers=', + '-Dgallium-drivers=panfrost', + '-Dvulkan-drivers=', + '-Dgbm=enabled', + '-Degl=enabled', + '-Dcpp_rtti=false', + '-Dglx=disabled', + '-Dtools=panfrost', + '-Ddri-search-path=/system/lib', + '--cross-file=cross_file', + F'--prefix={mesa3d_dir}/build-ohos/install', +] + +subprocess.run(meson_cmd, check=True) +subprocess.run(F'ninja -C build-ohos -j{nproc}', shell=True, check=True) +subprocess.run(F'ninja -C build-ohos install', shell=True, check=True) + +build_lib = os.path.join(mesa3d_dir, 'build-ohos', 'install', 'lib') +build_lib_dri = os.path.join(build_lib, 'dri') + +# install to out/rk3568/packages/phone/mesa3d +shutil.rmtree(mesa3d_install_dir, ignore_errors=True) +os.makedirs(mesa3d_install_dir, exist_ok=True) +for item in glob.glob(os.path.join(build_lib, 'lib*.so.*.*.*')): + shutil.copy(item, mesa3d_install_dir) +for item in glob.glob(os.path.join(build_lib_dri, '*_dri.so')): + # all *_dir.so are same file, we need only copy one and rename it to libgallium_dri.so + shutil.copy(item, os.path.join(mesa3d_install_dir, 'libgallium_dri.so')) # consider create symlink or hardlink + break diff --git a/ohos/cross_file b/ohos/cross_file deleted file mode 100644 index ce80bcd4dc557cd6dc29be1bbe8675aad3dfa416..0000000000000000000000000000000000000000 --- a/ohos/cross_file +++ /dev/null @@ -1,60 +0,0 @@ - -[properties] -needs_exe_wrapper = true - -c_args = [ - '-march=armv7-a', - '-mfloat-abi=softfp', - '-mtune=generic-armv7-a', - '-mfpu=neon', - '-mthumb', - '--target=arm-linux-ohosmusl', - '--sysroot=2/out/3/obj/third_party/musl', - '-fPIC'] - -cpp_args = [ - '-march=armv7-a', - '--target=arm-linux-ohosmusl', - '--sysroot=2/out/3/obj/third_party/musl', - '-fPIC'] - -c_link_args = [ - '-march=armv7-a', - '--target=arm-linux-ohosmusl', - '-fPIC', - '--sysroot=2/out/3/obj/third_party/musl', - '-L2/out/3/obj/third_party/musl/usr/lib/arm-linux-ohos', - '-L2/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/10.0.1/lib/arm-linux-ohos', - '-L2/prebuilts/clang/ohos/linux-x87_64/llvm/lib/arm-linux-ohos/c++', - '--rtlib=compiler-rt', - ] - -cpp_link_args = [ - '-march=armv7-a', - '--target=arm-linux-ohosmusl', - '--sysroot=2/out/3/obj/third_party/musl', - '-L2/out/3/obj/third_party/musl/usr/lib/arm-linux-ohos', - '-L2/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/10.0.1/lib/arm-linux-ohos', - '-L2/prebuilts/clang/ohos/linux-x87_64/llvm/lib/arm-linux-ohos/c++', - '-fPIC', - '-Wl,--exclude-libs=libunwind_llvm.a', - '-Wl,--exclude-libs=libc++_static.a', - '-Wl,--exclude-libs=libvpx_assembly_arm.a', - '-Wl,--warn-shared-textrel', - '--rtlib=compiler-rt', - ] - -[binaries] -ar = '2/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-ar' -c = ['ccache', '2/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang'] -cpp = ['ccache', '2/prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang++'] -c_ld= 'lld' -cpp_ld = 'lld' -strip = '2/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-strip' -pkgconfig = '/usr/bin/pkg-config' - -[host_machine] -system = 'linux' -cpu_family = 'arm' -cpu = 'armv7' -endian = 'little' diff --git a/ohos/meson_cross_process.py b/ohos/meson_cross_process.py index 479ba68571926e24f10f89b22279d9611e905e37..83e234882111f872ee8e17821237bb42448bf9bf 100644 --- a/ohos/meson_cross_process.py +++ b/ohos/meson_cross_process.py @@ -118,11 +118,17 @@ def process_pkgconfig(project_dir, product_name): generate_pc_file(template_dir + '/' + template, project_dir, product_name) print("process_pkgconfig") +def prepare_environment(project_path, product): + global project_stub + global sysroot_stub + product = product.lower() + project_stub = project_path + sysroot_stub = os.path.join(project_stub, "out", product, "obj", "third_party", "musl") + generate_cross_file(project_path, sysroot_stub) + process_pkgconfig(project_path, product) + if __name__ == '__main__': if len(sys.argv) < 3: print("must input the OpenHarmony directory and the product name") exit(-1) - project_stub = sys.argv[1] - sysroot_stub = sys.argv[1] + r"/out/" + sys.argv[2].lower() + r"/obj/third_party/musl" - generate_cross_file(sys.argv[1], sysroot_stub) - process_pkgconfig(sys.argv[1], sys.argv[2].lower()) + prepare_environment(sys.argv[1], sys.argv[2])