diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index bbe17f9809dd6752ee533c0b15c1ec6c84574e57..84c50014e1c32ce13efa69e053f54a61fca03a3e 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -102,16 +102,16 @@ index b8d0f47..a3d1ed9 100644 @@ -313,7 +334,7 @@ if (!is_clang && using_sanitizer) { is_clang = true } - + -use_flutter_cxx = is_clang && (is_linux || is_android || is_mac || is_ios) +use_flutter_cxx = is_clang && (is_linux || is_android || is_mac || is_ios || is_ohos ) - + if (is_msan && !is_linux) { assert(false, "Memory sanitizer is only available on Linux.") @@ -365,7 +386,9 @@ if (is_posix) { ] } - + -if (is_linux) { +if (is_ohos || (is_linux && host_os == "mac")) { + _native_compiler_configs += [ "//build/config/ohos:sdk" ] @@ -160,7 +160,7 @@ index b8d0f47..a3d1ed9 100644 if (is_clang) { host_toolchain = "//build/toolchain/linux:clang_$host_cpu" diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn -index ba20010..17e0487 100644 +index ba20010..5f27c8c 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -191,10 +191,16 @@ config("compiler") { @@ -185,7 +185,7 @@ index ba20010..17e0487 100644 } else if (current_cpu == "x86") { cflags += [ "-m32" ] @@ -315,7 +321,7 @@ config("compiler") { - + # Linux/Android common flags setup. # --------------------------------- - if (is_linux || is_android) { @@ -193,8 +193,8 @@ index ba20010..17e0487 100644 cflags += [ "-fPIC", "-pipe", # Use pipes for communicating between sub-processes. Faster. -@@ -334,7 +340,16 @@ config("compiler") { - +@@ -334,7 +340,28 @@ config("compiler") { + # Linux-specific compiler flags setup. # ------------------------------------ - if (is_linux) { @@ -202,7 +202,19 @@ index ba20010..17e0487 100644 + cflags += [ "-pthread" ] + ldflags += [ "-pthread" ] + -+ if (current_cpu == "arm64") { ++ if (current_cpu == "x86") { ++ cflags += [ "--target=x86-linux-ohos" ] ++ ldflags += [ "--target=x86-linux-ohos" ] ++ cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] ++ } else if (current_cpu == "x64") { ++ cflags += [ "--target=x86_64-linux-ohos" ] ++ ldflags += [ "--target=x86_64-linux-ohos" ] ++ cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] ++ } else if (current_cpu == "arm") { ++ cflags += [ "--target=aarch-linux-ohos" ] ++ ldflags += [ "--target=aarch-linux-ohos" ] ++ cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] ++ } else if (current_cpu == "arm64") { + cflags += [ "--target=aarch64-linux-ohos" ] + ldflags += [ "--target=aarch64-linux-ohos" ] + cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] @@ -210,8 +222,8 @@ index ba20010..17e0487 100644 + } else if (is_linux) { cflags += [ "-pthread" ] ldflags += [ "-pthread" ] - -@@ -521,9 +536,13 @@ config("runtime_library") { + +@@ -521,9 +548,13 @@ config("runtime_library") { ldflags += [ "-nostdlib++" ] } include_dirs = [ @@ -224,9 +236,9 @@ index ba20010..17e0487 100644 + include_dirs += [ "//third_party/libcxx/include" ] + } } - + # Android standard library setup. -@@ -860,17 +879,35 @@ config("optimize") { +@@ -860,12 +891,14 @@ config("optimize") { cflags = [ "-Oz" ] + common_optimize_on_cflags # Favor size over speed. } else if (is_wasm) { cflags = [ "-Oz" ] @@ -235,34 +247,13 @@ index ba20010..17e0487 100644 } else { cflags = [ "-O2" ] + common_optimize_on_cflags } - + lto_flags = [] - if (enable_lto && (is_ios || is_android || is_fuchsia || is_wasm)) { + if (enable_lto && (is_ios || is_android || is_fuchsia || is_wasm || is_ohos)) { lto_flags += [ "-flto" ] } - -+ if (is_ohos) { -+ cflags += [ -+ "-mcpu=tsv110", -+ "-fwhole-program-vtables", -+ ] -+ } -+ - ldflags = common_optimize_on_ldflags + lto_flags - cflags += lto_flags -+ -+ if (is_ohos) { -+ ldflags += [ -+ "-Wl,--lto-O2", -+ "-Wl,--plugin-opt=-mcpu=tsv110", -+ "-Wl,-mllvm", -+ "-Wl,-wholeprogramdevirt-check=fallback", -+ ] -+ } - } - - # Turn off optimizations. + diff --git a/build/config/ohos/BUILD.gn b/build/config/ohos/BUILD.gn new file mode 100644 index 0000000..b2675d2 @@ -300,10 +291,10 @@ index 0000000..b2675d2 +} diff --git a/build/config/ohos/config.gni b/build/config/ohos/config.gni new file mode 100644 -index 0000000..0022d70 +index 0000000..add7249 --- /dev/null +++ b/build/config/ohos/config.gni -@@ -0,0 +1,13 @@ +@@ -0,0 +1,32 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. @@ -311,7 +302,26 @@ index 0000000..0022d70 +# This file contains common system config stuff for the Ohos build. + +if (is_ohos) { -+ if (current_cpu == "arm64") { ++ # Defines host_os ++ if (host_os == "linux") { ++ ohos_host_os = "linux" ++ } else if (host_os == "mac") { ++ ohos_host_os = "darwin" ++ } else if (host_os == "win") { ++ ohos_host_os = "win" ++ } else { ++ assert(false, "Need Ohos toolchain support for your build OS.") ++ } ++ ++ ++ # ABI ------------------------------------------------------------------------ ++ if (current_cpu == "x86") { ++ ohos_app_abi = "x86" ++ } else if (current_cpu == "x64") { ++ ohos_app_abi = "x86_64" ++ } else if (current_cpu == "arm") { ++ ohos_app_abi = "armeabi-v7a" ++ } else if (current_cpu == "arm64") { + ohos_app_abi = "arm64-v8a" + } else { + assert(false, "Unknown Ohos ABI: " + current_cpu) @@ -864,7 +874,7 @@ index cad6cbc..c17950b 100644 +++ b/build/secondary/third_party/glfw/BUILD.gn @@ -47,6 +47,34 @@ source_set("glfw") { ] - + defines = [ "_GLFW_WIN32" ] + } else if (is_ohos) { + sources += [ @@ -914,6 +924,6 @@ index 65b1623..a89742a 100644 + readelf = "${toolchain_bin}/llvm-readelf" + nm = "${toolchain_bin}/llvm-nm" + strip = "${toolchain_bin}/llvm-strip" - + target_triple_flags = "--target=${custom_target_triple}" sysroot_flags = "--sysroot ${custom_sysroot}" diff --git a/attachment/repos/dart.patch0 b/attachment/repos/dart.patch0 index 04ca043cec6ffd71361c290ec56a2728f68b4704..8094cc2e317d80592662f557836994999c0b947c 100644 --- a/attachment/repos/dart.patch0 +++ b/attachment/repos/dart.patch0 @@ -1,4 +1,4 @@ -diff --git a/pkg/dds/lib/dds.dart b/pkg/dds/lib/dds.dart +diff --git a/pkg/dds/lib/dds.dart b/pkg/dds/lib/dds.dart index 177a9265649..c7038c56ad7 100644 --- a/pkg/dds/lib/dds.dart +++ b/pkg/dds/lib/dds.dart @@ -75,6 +75,60 @@ index 33be98fc0aa..eda146a0580 100644 String? get authCode => _authCode; String? _authCode; +diff --git a/pkg/vm/lib/transformations/ffi/abi.dart b/pkg/vm/lib/transformations/ffi/abi.dart +index cc2d86bafd7..e703419eed7 100644 +--- a/pkg/vm/lib/transformations/ffi/abi.dart ++++ b/pkg/vm/lib/transformations/ffi/abi.dart +@@ -40,6 +40,7 @@ enum _OS { + linux, + macos, + windows, ++ ohos, + } + + /// An application binary interface (ABI). +@@ -71,6 +72,9 @@ class Abi { + /// The application binary interface for Fuchsia on the X64 architecture. + static const fuchsiaX64 = _fuchsiaX64; + ++ /// The application binary interface for Ohos on the X64 architecture. ++ static const ohosX64 = _ohosX64; ++ + /// The application binary interface for iOS on the Arm architecture. + static const iosArm = _iosArm; + +@@ -131,6 +135,7 @@ class Abi { + androidX64, + fuchsiaArm64, + fuchsiaX64, ++ ohosX64, + iosArm, + iosArm64, + iosX64, +@@ -176,6 +181,7 @@ class Abi { + static const _androidX64 = Abi._(_Architecture.x64, _OS.android); + static const _fuchsiaArm64 = Abi._(_Architecture.arm64, _OS.fuchsia); + static const _fuchsiaX64 = Abi._(_Architecture.x64, _OS.fuchsia); ++ static const _ohosX64 = Abi._(_Architecture.x64, _OS.ohos); + static const _iosArm = Abi._(_Architecture.arm, _OS.ios); + static const _iosArm64 = Abi._(_Architecture.arm64, _OS.ios); + static const _iosX64 = Abi._(_Architecture.x64, _OS.ios); +@@ -200,6 +206,7 @@ const Map abiNames = { + Abi.androidX64: 'androidX64', + Abi.fuchsiaArm64: 'fuchsiaArm64', + Abi.fuchsiaX64: 'fuchsiaX64', ++ Abi.ohosX64: 'ohosX64', + Abi.iosArm: 'iosArm', + Abi.iosArm64: 'iosArm64', + Abi.iosX64: 'iosX64', +@@ -239,6 +246,7 @@ const Map> nonSizeAlignment = { + // _wordSize64 + Abi.androidArm64: _wordSize64, + Abi.androidX64: _wordSize64, ++ Abi.ohosX64: _wordSize64, + Abi.fuchsiaArm64: _wordSize64, + Abi.fuchsiaX64: _wordSize64, + Abi.iosArm64: _wordSize64, diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 13bfd0a724b..042b6a45f7e 100644 --- a/runtime/BUILD.gn @@ -5575,27 +5629,28 @@ index 66fa5a8d564..cc5eb834b3d 100644 #if DART_TARGET_OS_MACOS_IOS #define DART_TARGET_OS_NAME IOS diff --git a/runtime/vm/compiler/ffi/abi.h b/runtime/vm/compiler/ffi/abi.h -index b693ef85255..54b15f48890 100644 +index b693ef85255..6a3f42bd949 100644 --- a/runtime/vm/compiler/ffi/abi.h +++ b/runtime/vm/compiler/ffi/abi.h -@@ -24,6 +24,8 @@ enum class Abi { +@@ -24,6 +24,9 @@ enum class Abi { kAndroidArm64, kAndroidIA32, kAndroidX64, + kOhosArm, + kOhosArm64, ++ kOhosX64, kFuchsiaArm64, kFuchsiaX64, kIOSArm, -@@ -49,9 +51,9 @@ const int64_t num_abis = static_cast(Abi::kWindowsX64) + 1; +@@ -49,9 +52,9 @@ const int64_t num_abis = static_cast(Abi::kWindowsX64) + 1; // - runtime/vm/compiler/frontend/kernel_to_il.cc static_assert(static_cast(Abi::kAndroidArm) == 0, "Enum value unexpected."); -static_assert(static_cast(Abi::kWindowsX64) == 19, -+static_assert(static_cast(Abi::kWindowsX64) == 21, ++static_assert(static_cast(Abi::kWindowsX64) == 22, "Enum value unexpected."); -static_assert(num_abis == 20, "Enum value unexpected."); -+static_assert(num_abis == 22, "Enum value unexpected."); ++static_assert(num_abis == 23, "Enum value unexpected."); // The target ABI. Defines sizes and alignment of native types. Abi TargetAbi(); @@ -7619,6 +7674,166 @@ index b7e5be3eab5..8a8f873f6c5 100644 bool _isAllowedOrigin(String origin) { Uri uri; +diff --git a/sdk/lib/ffi/abi.dart b/sdk/lib/ffi/abi.dart +index e6f08b37d25..5af605a8764 100644 +--- a/sdk/lib/ffi/abi.dart ++++ b/sdk/lib/ffi/abi.dart +@@ -34,6 +34,9 @@ class Abi { + /// The application binary interface for Fuchsia on the X64 architecture. + static const fuchsiaX64 = _fuchsiaX64; + ++ /// The application binary interface for Ohos on the X64 architecture. ++ static const ohosX64 = _ohosX64; ++ + /// The application binary interface for iOS on the Arm architecture. + static const iosArm = _iosArm; + +@@ -94,6 +97,7 @@ class Abi { + androidX64, + fuchsiaArm64, + fuchsiaX64, ++ ohosX64, + iosArm, + iosArm64, + iosX64, +@@ -136,6 +140,7 @@ class Abi { + static const _androidX64 = Abi._(_Architecture.x64, _OS.android); + static const _fuchsiaArm64 = Abi._(_Architecture.arm64, _OS.fuchsia); + static const _fuchsiaX64 = Abi._(_Architecture.x64, _OS.fuchsia); ++ static const _ohosX64 = Abi._(_Architecture.x64, _OS.ohos); + static const _iosArm = Abi._(_Architecture.arm, _OS.ios); + static const _iosArm64 = Abi._(_Architecture.arm64, _OS.ios); + static const _iosX64 = Abi._(_Architecture.x64, _OS.ios); +@@ -170,4 +175,5 @@ enum _OS { + linux, + macos, + windows, ++ ohos, + } +diff --git a/sdk/lib/ffi/c_type.dart b/sdk/lib/ffi/c_type.dart +index ee358c2f79d..1f9e629beb9 100644 +--- a/sdk/lib/ffi/c_type.dart ++++ b/sdk/lib/ffi/c_type.dart +@@ -29,6 +29,7 @@ part of dart.ffi; + Abi.androidX64: Int8(), + Abi.fuchsiaArm64: Uint8(), + Abi.fuchsiaX64: Int8(), ++ Abi.ohosX64: Int8(), + Abi.iosArm: Int8(), + Abi.iosArm64: Int8(), + Abi.iosX64: Int8(), +@@ -66,6 +67,7 @@ class Char extends AbiSpecificInteger { + Abi.androidX64: Int8(), + Abi.fuchsiaArm64: Int8(), + Abi.fuchsiaX64: Int8(), ++ Abi.ohosX64: Int8(), + Abi.iosArm: Int8(), + Abi.iosArm64: Int8(), + Abi.iosX64: Int8(), +@@ -103,6 +105,7 @@ class SignedChar extends AbiSpecificInteger { + Abi.androidX64: Uint8(), + Abi.fuchsiaArm64: Uint8(), + Abi.fuchsiaX64: Uint8(), ++ Abi.ohosX64: Uint8(), + Abi.iosArm: Uint8(), + Abi.iosArm64: Uint8(), + Abi.iosX64: Uint8(), +@@ -140,6 +143,7 @@ class UnsignedChar extends AbiSpecificInteger { + Abi.androidX64: Int16(), + Abi.fuchsiaArm64: Int16(), + Abi.fuchsiaX64: Int16(), ++ Abi.ohosX64: Int16(), + Abi.iosArm: Int16(), + Abi.iosArm64: Int16(), + Abi.iosX64: Int16(), +@@ -177,6 +181,7 @@ class Short extends AbiSpecificInteger { + Abi.androidX64: Uint16(), + Abi.fuchsiaArm64: Uint16(), + Abi.fuchsiaX64: Uint16(), ++ Abi.ohosX64: Uint16(), + Abi.iosArm: Uint16(), + Abi.iosArm64: Uint16(), + Abi.iosX64: Uint16(), +@@ -214,6 +219,7 @@ class UnsignedShort extends AbiSpecificInteger { + Abi.androidX64: Int32(), + Abi.fuchsiaArm64: Int32(), + Abi.fuchsiaX64: Int32(), ++ Abi.ohosX64: Int32(), + Abi.iosArm: Int32(), + Abi.iosArm64: Int32(), + Abi.iosX64: Int32(), +@@ -251,6 +257,7 @@ class Int extends AbiSpecificInteger { + Abi.androidX64: Uint32(), + Abi.fuchsiaArm64: Uint32(), + Abi.fuchsiaX64: Uint32(), ++ Abi.ohosX64: Uint32(), + Abi.iosArm: Uint32(), + Abi.iosArm64: Uint32(), + Abi.iosX64: Uint32(), +@@ -289,6 +296,7 @@ class UnsignedInt extends AbiSpecificInteger { + Abi.androidX64: Int64(), + Abi.fuchsiaArm64: Int64(), + Abi.fuchsiaX64: Int64(), ++ Abi.ohosX64: Int64(), + Abi.iosArm: Int32(), + Abi.iosArm64: Int64(), + Abi.iosX64: Int64(), +@@ -327,6 +335,7 @@ class Long extends AbiSpecificInteger { + Abi.androidX64: Uint64(), + Abi.fuchsiaArm64: Uint64(), + Abi.fuchsiaX64: Uint64(), ++ Abi.ohosX64: Uint64(), + Abi.iosArm: Uint32(), + Abi.iosArm64: Uint64(), + Abi.iosX64: Uint64(), +@@ -364,6 +373,7 @@ class UnsignedLong extends AbiSpecificInteger { + Abi.androidX64: Int64(), + Abi.fuchsiaArm64: Int64(), + Abi.fuchsiaX64: Int64(), ++ Abi.ohosX64: Int64(), + Abi.iosArm: Int64(), + Abi.iosArm64: Int64(), + Abi.iosX64: Int64(), +@@ -401,6 +411,7 @@ class LongLong extends AbiSpecificInteger { + Abi.androidX64: Uint64(), + Abi.fuchsiaArm64: Uint64(), + Abi.fuchsiaX64: Uint64(), ++ Abi.ohosX64: Uint64(), + Abi.iosArm: Uint64(), + Abi.iosArm64: Uint64(), + Abi.iosX64: Uint64(), +@@ -433,6 +444,7 @@ class UnsignedLongLong extends AbiSpecificInteger { + Abi.androidX64: Int64(), + Abi.fuchsiaArm64: Int64(), + Abi.fuchsiaX64: Int64(), ++ Abi.ohosX64: Int64(), + Abi.iosArm: Int32(), + Abi.iosArm64: Int64(), + Abi.iosX64: Int64(), +@@ -466,6 +478,7 @@ class IntPtr extends AbiSpecificInteger { + Abi.androidX64: Uint64(), + Abi.fuchsiaArm64: Uint64(), + Abi.fuchsiaX64: Uint64(), ++ Abi.ohosX64: Uint64(), + Abi.iosArm: Uint32(), + Abi.iosArm64: Uint64(), + Abi.iosX64: Uint64(), +@@ -499,6 +512,7 @@ class UintPtr extends AbiSpecificInteger { + Abi.androidX64: Uint64(), + Abi.fuchsiaArm64: Uint64(), + Abi.fuchsiaX64: Uint64(), ++ Abi.ohosX64: Uint64(), + Abi.iosArm: Uint32(), + Abi.iosArm64: Uint64(), + Abi.iosX64: Uint64(), +@@ -535,6 +549,7 @@ class Size extends AbiSpecificInteger { + Abi.androidX64: Uint32(), + Abi.fuchsiaArm64: Uint32(), + Abi.fuchsiaX64: Int32(), ++ Abi.ohosX64: Int32(), + Abi.iosArm: Int32(), + Abi.iosArm64: Int32(), + Abi.iosX64: Int32(), diff --git a/sdk_args.gni b/sdk_args.gni index 4b2a1e4ea63..a864344ee8d 100644 --- a/sdk_args.gni diff --git a/attachment/scripts/ohos.py b/attachment/scripts/ohos.py index 2d21f7848f4954e6e399f7dcf25ffc2390867848..d60c405775fcb9c163d2784360cc1b7097be03d3 100644 --- a/attachment/scripts/ohos.py +++ b/attachment/scripts/ohos.py @@ -28,6 +28,12 @@ from datetime import datetime SUPPORT_BUILD_NAMES = ("clean", "config", "har", "compile", "zip", "zip2", "upload") SUPPORT_BUILD_TYPES = ("debug", "profile", "release") +SUPPORT_ABIS = { + "x86": "x86", + "x64": "x86_64", + "arm": "armeabi-v7a", + "arm64": "arm64-v8a", +} DIR_ROOT = os.path.abspath(os.path.join(sys.argv[0], os.pardir)) OS_NAME = platform.system().lower() IS_WINDOWS = OS_NAME.startswith("win") @@ -61,14 +67,12 @@ class BuildInfo: buildType="release", targetOS="ohos", targetArch="arm64", - targetTriple="arm64-%s-ohos" % OS_NAME, - abi="arm64-v8a", ): self.buildType = buildType self.targetOS = targetOS self.targetArch = targetArch - self.targetTriple = targetTriple - self.abi = abi + self.targetTriple = "%s-%s-%s" % (targetArch, OS_NAME, targetOS) + self.abi = SUPPORT_ABIS[targetArch] def __repr__(self): return "BuildInfo(buildType=%s)" % (self.buildType) @@ -333,6 +337,9 @@ def addParseParam(parser): parser.add_argument( "--har-unstripped", action="store_true", help="Use so.unstripped or not." ) + parser.add_argument( + "--ohos-cpu", type=str, choices=['x64', 'x86', 'arm64', 'arm'], default="arm64" + ) def updateCode(args): @@ -365,7 +372,7 @@ def buildByNameAndType(args): for buildType in SUPPORT_BUILD_TYPES: if not buildType in buildTypes: continue - buildInfo = BuildInfo(buildType=buildType) + buildInfo = BuildInfo(buildType=buildType, targetArch=args.ohos_cpu) for buildName in SUPPORT_BUILD_NAMES: if not buildName in buildNames: continue diff --git a/tools/gn b/tools/gn index ccbb3b75e933bceb1895a4647097cdc2671c14ae..ee44e2512a164fa879863bc5c822adb21cb7632c 100755 --- a/tools/gn +++ b/tools/gn @@ -344,8 +344,6 @@ def to_gn_args(args): gn_args['target_os'] = args.target_os gn_args['target_cpu'] = get_target_cpu(args) gn_args['dart_target_arch'] = gn_args['target_cpu'] - if (args.target_os == 'ohos'): - gn_args['host_cpu'] = get_host_cpu() print("ARGS.target_os:%s-%s" % (args.target_os,gn_args['target_os'] ) ) # We cannot cross-compile for 32 bit arm on a Windows host. We work around