diff -uprN src/build/config/BUILDCONFIG.gn src_ohos/build/config/BUILDCONFIG.gn
@@ -235,6 +235,8 @@ _default_toolchain = ""
if (target_os == "android") {
assert(host_os == "linux", "Android builds are only supported on Linux.")
_default_toolchain = "//build/toolchain/android:android_clang_$target_cpu"
+} else if (target_os == "ohos") { # OHOS-LOCAL
+ _default_toolchain = "//build/toolchain/ohos:ohos_clang_$target_cpu"
} else if (target_os == "chromeos" || target_os == "linux") {
# See comments in build/toolchain/cros/BUILD.gn about board compiles.
if (is_clang) {
@@ -298,6 +300,7 @@ if (custom_toolchain != "") {
# aix or one of the BSDs. If you need to check these, just check the
# current_os value directly.
+is_ohos = current_os == "ohos"
is_android = current_os == "android"
is_chromeos = current_os == "chromeos"
is_fuchsia = current_os == "fuchsia"
@@ -384,6 +387,10 @@ if (is_android) {
[ "//build/config/android:default_orderfile_instrumentation" ]
}
+if (is_ohos) {
+ default_compiler_configs += [ "//build/config/ohos:compiler" ]
+}
+
if (is_clang && !is_nacl) {
default_compiler_configs += [
"//build/config/clang:find_bad_constructs",
diff -uprN src/build/config/clang/BUILD.gn src_ohos/build/config/clang/BUILD.gn
@@ -16,38 +16,38 @@ config("find_bad_constructs") {
# The plugin is built directly into clang, so there's no need to load it
# dynamically.
cflags += [
- "-Xclang",
- "-add-plugin",
- "-Xclang",
- "find-bad-constructs",
-
- "-Xclang",
- "-plugin-arg-find-bad-constructs",
- "-Xclang",
- "raw-ref-template-as-trivial-member",
-
- "-Xclang",
- "-plugin-arg-find-bad-constructs",
- "-Xclang",
- "check-stack-allocated",
-
- "-Xclang",
- "-plugin-arg-find-bad-constructs",
- "-Xclang",
- "check-raw-ptr-to-stack-allocated",
+ #"-Xclang",
+ #"-add-plugin",
+ #"-Xclang",
+ #"find-bad-constructs",
+
+ #"-Xclang",
+ #"-plugin-arg-find-bad-constructs",
+ #"-Xclang",
+ #"raw-ref-template-as-trivial-member",
+
+ #"-Xclang",
+ #"-plugin-arg-find-bad-constructs",
+ #"-Xclang",
+ #"check-stack-allocated",
+
+ #"-Xclang",
+ #"-plugin-arg-find-bad-constructs",
+ #"-Xclang",
+ #"check-raw-ptr-to-stack-allocated",
# TODO(https://crbug.com/1449812): This option should be removed after
# next clang roll.
- "-Xclang",
- "-plugin-arg-find-bad-constructs",
- "-Xclang",
- "raw-ptr-fix-crbug-1449812",
+ #"-Xclang",
+ #"-plugin-arg-find-bad-constructs",
+ #"-Xclang",
+ #"raw-ptr-fix-crbug-1449812",
# TODO(https://crbug.com/1504043): Remove when raw_ptr check has been enabled for the dawn repo.
- "-Xclang",
- "-plugin-arg-find-bad-constructs",
- "-Xclang",
- "raw-ptr-exclude-path=/third_party/dawn/",
+ #"-Xclang",
+ #"-plugin-arg-find-bad-constructs",
+ #"-Xclang",
+ #"raw-ptr-exclude-path=/third_party/dawn/",
]
if (is_linux || is_chromeos || is_android || is_fuchsia) {
diff -uprN src/build/config/clang/clang.gni src_ohos/build/config/clang/clang.gni
@@ -7,14 +7,25 @@ import("//build/toolchain/toolchain.gni"
default_clang_base_path = "//third_party/llvm-build/Release+Asserts"
+if (is_ohos) {
+ declare_args() {
+ ohos_sdk_native_root = "//buildtools/ohos-sdk/linux/native"
+ }
+ default_clang_base_path = "${ohos_sdk_native_root}/llvm"
+ clang_lib_path = "${default_clang_base_path}/lib"
+}
+
declare_args() {
# Indicates if the build should use the Chrome-specific plugins for enforcing
# coding guidelines, etc. Only used when compiling with Chrome's Clang, not
# Chrome OS's.
- clang_use_chrome_plugins =
- is_clang && !is_nacl && current_os != "zos" &&
- default_toolchain != "//build/toolchain/cros:target"
-
+ if (is_ohos) {
+ clang_use_chrome_plugins = false
+ } else {
+ clang_use_chrome_plugins =
+ is_clang && !is_nacl && current_os != "zos" &&
+ default_toolchain != "//build/toolchain/cros:target"
+ }
enable_check_raw_ptr_fields =
build_with_chromium && !is_official_build &&
((is_linux && !is_castos) || (is_android && !is_cast_android) || is_mac ||
diff -uprN src/build/config/compiler/BUILD.gn src_ohos/build/config/compiler/BUILD.gn
@@ -605,14 +605,14 @@ config("compiler") {
# TODO(hans): Remove this once Clang generates better optimized debug info
# by default. https://crbug.com/765793
cflags += [
- "-mllvm",
- "-instcombine-lower-dbg-declare=0",
+ # "-mllvm",
+ # "-instcombine-lower-dbg-declare=0",
]
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
if (is_win) {
ldflags += [ "-mllvm:-instcombine-lower-dbg-declare=0" ]
} else {
- ldflags += [ "-Wl,-mllvm,-instcombine-lower-dbg-declare=0" ]
+ # ldflags += [ "-Wl,-mllvm,-instcombine-lower-dbg-declare=0" ]
}
}
@@ -622,14 +622,14 @@ config("compiler") {
if (default_toolchain != "//build/toolchain/cros:target" &&
!llvm_android_mainline) {
cflags += [
- "-mllvm",
- "-split-threshold-for-reg-with-hint=0",
+ #"-mllvm",
+ #"-split-threshold-for-reg-with-hint=0",
]
if (use_thin_lto && is_a_target_toolchain) {
if (is_win) {
ldflags += [ "-mllvm:-split-threshold-for-reg-with-hint=0" ]
} else {
- ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ]
+ #ldflags += [ "-Wl,-mllvm,-split-threshold-for-reg-with-hint=0" ]
}
}
}
@@ -1576,9 +1576,13 @@ config("compiler_deterministic") {
config("clang_revision") {
if (is_clang && clang_base_path == default_clang_base_path) {
update_args = [
- "--print-revision",
- "--verify-version=$clang_version",
+ "--print-revision"
]
+
+ if (!is_ohos) {
+ update_args += [ "--verify-version=$clang_version" ]
+ }
+
if (llvm_force_head_revision) {
update_args += [ "--llvm-force-head-revision" ]
}
@@ -1707,12 +1711,12 @@ config("treat_warnings_as_errors") {
if (is_win) {
cflags = [ "/WX" ]
} else {
- cflags = [ "-Werror" ]
+ # cflags = [ "-Werror" ]
# The compiler driver can sometimes (rarely) emit warnings before calling
# the actual linker. Make sure these warnings are treated as errors as
# well.
- ldflags = [ "-Werror" ]
+ # ldflags = [ "-Werror" ]
}
# Turn rustc warnings into the "deny" lint level, which produce compiler
diff -uprN src/build/config/ohos/BUILD.gn src_ohos/build/config/ohos/BUILD.gn
@@ -0,0 +1,79 @@
+import("//build/config/sysroot.gni")
+import("//build/config/clang/clang.gni")
+assert(is_ohos)
+
+ohos_clang_base_path = "${ohos_sdk_native_root}/llvm"
+ohos_clang_version = "15.0.4"
+
+if (is_ohos) {
+ if (current_cpu == "arm") {
+ abi_target = "arm-linux-ohos"
+ } else if (current_cpu == "x86") {
+ abi_target = ""
+ } else if (current_cpu == "arm64") {
+ abi_target = "aarch64-linux-ohos"
+ } else if (current_cpu == "x86_64") {
+ abi_target = "x86_64-linux-ohos"
+ } else {
+ assert(false, "Architecture not supported")
+ }
+}
+
+
+config("compiler") {
+ cflags = [
+ "-ffunction-sections",
+ "-fno-short-enums",
+ "-fno-addrsig",
+ ]
+
+ cflags += [
+ "-Wno-unknown-warning-option",
+ "-Wno-int-conversion",
+ "-Wno-unused-variable",
+ "-Wno-misleading-indentation",
+ "-Wno-missing-field-initializers",
+ "-Wno-unused-parameter",
+ "-Wno-c++11-narrowing",
+ "-Wno-unneeded-internal-declaration",
+ "-Wno-undefined-var-template",
+ "-Wno-implicit-int-float-conversion",
+ ]
+ defines = [
+ # The NDK has these things, but doesn't define the constants to say that it
+ # does. Define them here instead.
+ "HAVE_SYS_UIO_H",
+ ]
+
+ defines += [
+ "OHOS",
+ "__MUSL__",
+ "_LIBCPP_HAS_MUSL_LIBC",
+ "__BUILD_LINUX_WITH_CLANG",
+ "__GNU_SOURCE",
+ "_GNU_SOURCE",
+ ]
+
+ ldflags = [
+ "-Wl,--no-undefined",
+ "-Wl,--exclude-libs=libunwind_llvm.a",
+ "-Wl,--exclude-libs=libc++_static.a",
+
+ # Don't allow visible symbols from libraries that contain
+ # assembly code with symbols that aren't hidden properly.
+ # http://crbug.com/448386
+ "-Wl,--exclude-libs=libvpx_assembly_arm.a",
+ ]
+
+ cflags += [ "--target=$abi_target" ]
+ include_dirs = [
+ "${sysroot}/usr/include/${abi_target}",
+ "${ohos_clang_base_path}/lib/clang/${ohos_clang_version}/include",
+ ]
+
+ ldflags += [ "--target=$abi_target" ]
+
+ # Assign any flags set for the C compiler to asmflags so that they are sent
+ # to the assembler.
+ asmflags = cflags
+}
diff -uprN src/build/config/sysroot.gni src_ohos/build/config/sysroot.gni
@@ -34,6 +34,9 @@ if (sysroot == "") {
# Android uses unified headers, and thus a single compile time sysroot
sysroot = "$android_toolchain_root/sysroot"
+ } else if (is_ohos) {
+ import("//build/config/clang/clang.gni")
+ sysroot = "${ohos_sdk_native_root}/sysroot"
} else if ((is_linux || is_chromeos) && use_sysroot) {
# By default build against a sysroot image downloaded from Cloud Storage
# during gclient runhooks.
diff -uprN src/build/toolchain/gcc_toolchain.gni src_ohos/build/toolchain/gcc_toolchain.gni
@@ -126,6 +126,30 @@ template("single_gcc_toolchain") {
rebuild_string = ""
}
+ if (defined(invoker.libs_section_prefix)) {
+ libs_section_prefix = invoker.libs_section_prefix
+ } else {
+ libs_section_prefix = ""
+ }
+
+ if (defined(invoker.libs_section_postfix)) {
+ libs_section_postfix = invoker.libs_section_postfix
+ } else {
+ libs_section_postfix = ""
+ }
+
+ if (defined(invoker.solink_libs_section_prefix)) {
+ solink_libs_section_prefix = invoker.solink_libs_section_prefix
+ } else {
+ solink_libs_section_prefix = ""
+ }
+
+ if (defined(invoker.solink_libs_section_postfix)) {
+ solink_libs_section_postfix = invoker.solink_libs_section_postfix
+ } else {
+ solink_libs_section_postfix = ""
+ }
+
# GN's syntax can't handle more than one scope dereference at once, like
# "invoker.toolchain_args.foo", so make a temporary to hold the toolchain
# args so we can do "invoker_toolchain_args.foo".
@@ -502,6 +526,8 @@ template("single_gcc_toolchain") {
# --whole-archive, --no-whole-archive flags are not available on the aix
# ld.
rspfile_content = "{{inputs}} {{solibs}} {{libs}}"
+ } else if(current_os == "ohos") {
+ rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix"
} else {
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
}
@@ -582,8 +608,11 @@ template("single_gcc_toolchain") {
strip_command = "${invoker.strip} -o \"$sofile\" \"$unstripped_sofile\""
command += " && " + strip_command
}
- rspfile_content = "$whole_archive_flag {{inputs}} {{solibs}} $no_whole_archive_flag {{libs}} {{rlibs}}"
-
+ if (current_os == "ohos") {
+ rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix"
+ } else {
+ rspfile_content = "$whole_archive_flag {{inputs}} {{solibs}} $no_whole_archive_flag {{libs}} {{rlibs}}"
+ }
description = "SOLINK_MODULE $sofile"
# Use this for {{output_extension}} expansions unless a target manually
@@ -636,8 +665,13 @@ template("single_gcc_toolchain") {
start_group_flag = "-Wl,--start-group"
end_group_flag = "-Wl,--end-group "
}
- link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" $start_group_flag @\"$rspfile\" {{solibs}} $end_group_flag {{libs}} {{rlibs}}"
+ if (is_ohos) {
+ link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" $libs_section_prefix $start_group_flag @\"$rspfile\" {{solibs}} {{libs}} $end_group_flag $libs_section_postfix"
+ } else {
+ link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" $start_group_flag @\"$rspfile\" {{solibs}} $end_group_flag {{libs}} {{rlibs}}"
+ }
+
# Generate a map file to be used for binary size analysis.
# Map file adds ~10% to the link time on a z620.
# With target_os="android", libchrome.so.map.gz is ~20MB.
diff -uprN src/build/toolchain/ohos/BUILD.gn src_ohos/build/toolchain/ohos/BUILD.gn
@@ -0,0 +1,103 @@
+import("//build/config/sysroot.gni")
+import("//build/toolchain/gcc_toolchain.gni")
+
+declare_args() {
+ # Whether unstripped binaries, i.e. compiled with debug symbols, should be
+ # considered runtime_deps rather than stripped ones.
+ ohos_unstripped_runtime_outputs = true
+ ohos_extra_cflags = ""
+ ohos_extra_cppflags = ""
+ ohos_extra_cxxflags = ""
+ ohos_extra_asmflags = ""
+ ohos_extra_ldflags = ""
+}
+
+# The ohos clang toolchains share most of the same parameters, so we have this
+# wrapper around gcc_toolchain to avoid duplication of logic.
+#
+# Parameters:
+# - toolchain_root
+# Path to cpu-specific toolchain within the ndk.
+# - sysroot
+# Sysroot for this architecture.
+# - lib_dir
+# Subdirectory inside of sysroot where libs go.
+# - binary_prefix
+# Prefix of compiler executables.
+template("ohos_clang_toolchain") {
+ gcc_toolchain(target_name) {
+ assert(defined(invoker.toolchain_args),
+ "toolchain_args must be defined for ohos_clang_toolchain()")
+ toolchain_args = invoker.toolchain_args
+ toolchain_args.current_os = "ohos"
+
+ # Output linker map files for binary size analysis.
+ enable_linker_map = true
+
+ ohos_libc_dir =
+ rebase_path(invoker.sysroot + "/" + invoker.lib_dir, root_build_dir)
+ # libs_section_prefix = "${ohos_libc_dir}/Scrt1.o"
+ # libs_section_prefix += " ${ohos_libc_dir}/crti.o"
+ # libs_section_postfix = "${ohos_libc_dir}/crtn.o"
+
+ if (invoker.target_name == "ohos_clang_arm") {
+ abi_target = "arm-linux-ohos"
+ } else if (invoker.target_name == "ohos_clang_arm64") {
+ abi_target = "aarch64-linux-ohos"
+ } else if (invoker.target_name == "ohos_clang_x86_64") {
+ abi_target = "x86_64-linux-ohos"
+ }
+
+ clang_rt_dir =
+ rebase_path("${clang_lib_path}/${abi_target}/nanlegacy",
+ root_build_dir)
+ print("ohos_libc_dir :", ohos_libc_dir)
+ print("clang_rt_dir :", clang_rt_dir)
+# solink_libs_section_prefix = "${ohos_libc_dir}/crti.o"
+# solink_libs_section_prefix += " ${clang_rt_dir}/clang_rt.crtbegin.o"
+# solink_libs_section_postfix = "${ohos_libc_dir}/crtn.o"
+# solink_libs_section_postfix += " ${clang_rt_dir}/clang_rt.crtend.o"
+
+ _prefix = rebase_path("${clang_base_path}/bin", root_build_dir)
+ cc = "${_prefix}/clang"
+ cxx = "${_prefix}/clang++"
+ ar = "${_prefix}/llvm-ar"
+ ld = cxx
+ readelf = "${_prefix}/llvm-readobj"
+ nm = "${_prefix}/llvm-nm"
+ if (!is_debug) {
+ strip = rebase_path("${clang_base_path}/bin/llvm-strip", root_build_dir)
+ use_unstripped_as_runtime_outputs = ohos_unstripped_runtime_outputs
+ }
+ extra_cflags = ohos_extra_cflags
+ extra_cppflags = ohos_extra_cppflags
+ extra_cxxflags = ohos_extra_cxxflags
+ extra_asmflags = ohos_extra_asmflags
+ extra_ldflags = ohos_extra_ldflags
+ }
+}
+
+
+ohos_clang_toolchain("ohos_clang_arm") {
+ sysroot = "${sysroot}"
+ lib_dir = "usr/lib/arm-linux-ohos"
+ toolchain_args = {
+ current_cpu = "arm"
+ }
+}
+
+ohos_clang_toolchain("ohos_clang_arm64") {
+ sysroot = "${sysroot}"
+ lib_dir = "usr/lib/aarch64-linux-ohos"
+ toolchain_args = {
+ current_cpu = "arm64"
+ }
+}
+
+ohos_clang_toolchain("ohos_clang_x86_64") {
+ sysroot = "${sysroot}"
+ lib_dir = "usr/lib/x86_64-linux-ohos"
+ toolchain_args = {
+ current_cpu = "x86_64"
+ }
+}
diff -uprN src/build/toolchain/toolchain.gni src_ohos/build/toolchain/toolchain.gni
@@ -47,7 +47,11 @@ declare_args() {
if (llvm_android_mainline) { # https://crbug.com/1481060
clang_version = "17"
} else {
- clang_version = "18"
+ if (is_ohos) {
+ clang_version = "15.0.4"
+ } else {
+ clang_version = "18"
+ }
}
}
diff -uprN src/BUILD.gn src_ohos/BUILD.gn
@@ -214,6 +214,9 @@ config("common_inherited_config") {
"WEBRTC_IOS",
]
}
+ if (is_ohos) {
+ defines += [ "WEBRTC_OHOS", "WEBRTC_LINUX" ]
+ }
if (is_linux || is_chromeos) {
defines += [ "WEBRTC_LINUX" ]
}
diff -uprN src/modules/video_capture/BUILD.gn src_ohos/modules/video_capture/BUILD.gn
@@ -71,7 +71,7 @@ if (!build_with_chromium || is_linux ||
"video_capture_options.h",
]
- if (is_linux || is_chromeos) {
+ if (is_linux || is_chromeos || is_ohos) {
sources += [
"linux/device_info_linux.cc",
"linux/device_info_v4l2.cc",
diff -uprN src/rtc_base/platform_thread_types.cc src_ohos/rtc_base/platform_thread_types.cc
@@ -40,7 +40,7 @@ PlatformThreadId CurrentThreadId() {
#elif defined(WEBRTC_POSIX)
#if defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
return pthread_mach_thread_np(pthread_self());
-#elif defined(WEBRTC_ANDROID)
+#elif defined(WEBRTC_ANDROID) || defined(WEBRTC_OHOS)
return gettid();
#elif defined(WEBRTC_FUCHSIA)
return zx_thread_self();
diff -uprN src/third_party/dav1d/BUILD.gn src_ohos/third_party/dav1d/BUILD.gn
@@ -56,7 +56,7 @@ config("public_dav1d_config") {
defines = [ "CONFIG_LOG=1" ]
}
- if (!is_android && !is_win) {
+ if (!is_android && !is_win && !is_ohos) {
defines += [
"HAVE_PTHREAD_GETAFFINITY_NP=1",
"HAVE_PTHREAD_SETAFFINITY_NP=1",
diff -uprN src/third_party/libevent/BUILD.gn src_ohos/third_party/libevent/BUILD.gn
@@ -37,13 +37,13 @@ static_library("libevent") {
"mac/event-config.h",
]
include_dirs += [ "mac" ]
- } else if (is_linux || is_chromeos) {
+ } else if (is_linux || is_chromeos || is_ohos) {
sources += [
"epoll.c",
"linux/config.h",
"linux/event-config.h",
]
- include_dirs += [ "linux" ]
+ include_dirs += [ "linux", "compat" ]
} else if (is_android) {
sources += [
"android/config.h",
diff -uprN src/third_party/zlib/BUILD.gn src_ohos/third_party/zlib/BUILD.gn
@@ -127,7 +127,7 @@ if (use_arm_neon_optimizations) {
defines = [ "CRC32_ARMV8_CRC32" ]
if (is_android) {
defines += [ "ARMV8_OS_ANDROID" ]
- } else if (is_linux || is_chromeos) {
+ } else if (is_linux || is_chromeos || is_ohos) {
defines += [ "ARMV8_OS_LINUX" ]
} else if (is_mac) {
defines += [ "ARMV8_OS_MACOS" ]