From ef1989c840d6e9866ace10c7cf2f7e63dda5b40b Mon Sep 17 00:00:00 2001 From: siyao Date: Tue, 26 Jul 2022 14:59:43 +0800 Subject: [PATCH 1/4] windows prebuild --- engine/.gitignore | 3 +- engine/Build.bee.cs | 47 +++++++++++++++++++++++++----- engine/Scripts/Readme.md | 13 +++++++++ engine/Scripts/lib_build.py | 36 ++++++++++++++++------- engine/Scripts/local_build_win.ps1 | 8 +++++ 5 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 engine/Scripts/Readme.md create mode 100644 engine/Scripts/local_build_win.ps1 diff --git a/engine/.gitignore b/engine/.gitignore index 526d64dcb..9cd8c3e17 100644 --- a/engine/.gitignore +++ b/engine/.gitignore @@ -4,4 +4,5 @@ artifacts build obj *.gen.* -third_party/skia \ No newline at end of file +third_party/skia +libs \ No newline at end of file diff --git a/engine/Build.bee.cs b/engine/Build.bee.cs index c8fec825a..84ce878ee 100644 --- a/engine/Build.bee.cs +++ b/engine/Build.bee.cs @@ -223,12 +223,22 @@ static void DeployIOS() static void Main() { - flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT_PATH"); - if (string.IsNullOrEmpty(flutterRoot)) + preBuildLibRoot = Environment.GetEnvironmentVariable("PREBUILD_LIB_ROOT_PATH"); + if(preBuildLibRoot != null && preBuildLibRoot.Length > 0) { - flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src"; + cachedHeader = Path.Combine(preBuildLibRoot, "windows"); + flutterRoot = Path.Combine(preBuildLibRoot, "headerout"); + skiaRoot = flutterRoot + "/third_party/skia"; + useLocal = true; + } + else { + flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT_PATH"); + if (string.IsNullOrEmpty(flutterRoot)) + { + flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src"; + } + skiaRoot = flutterRoot + "/third_party/skia"; } - skiaRoot = flutterRoot + "/third_party/skia"; try { @@ -279,6 +289,9 @@ static void Main() private static string skiaRoot; private static string flutterRoot; + private static string preBuildLibRoot; + private static string cachedHeader; + private static bool useLocal; private static bool buildArm64; //this setting is disabled by default, don't change it unless you know what you are doing @@ -625,9 +638,13 @@ static NativeProgram SetupLibUIWidgets(UIWidgetsBuildTargetPlatform platform, ou np.Sources.Add(c => IsAndroid(c), androidSource); np.Libraries.Add(c => IsWindows(c), new BagOfObjectFilesLibrary( + useLocal? new NPath[]{ + Path.Combine(preBuildLibRoot, "windows/icudtl.o") + } : new NPath[]{ flutterRoot + "/third_party/icu/flutter/icudtl.o" - })); + } + )); np.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp17)); np.CompilerSettings().Add(c => IsMac(c) || IsIosOrTvos(c), c => c.WithCustomFlags(new []{"-Wno-c++11-narrowing"})); @@ -1299,7 +1316,15 @@ static void SetupDependency(NativeProgram np) return IsWindows(c) && c.CodeGen == CodeGen.Debug; }, c => { - return new PrecompiledLibrary[] + return useLocal ? new PrecompiledLibrary[] + { + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/txt_lib.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/angle_lib.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/libEGL_static.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/libGLESv2_static.lib")), + new SystemLibrary("dxguid.lib"), + } + : new PrecompiledLibrary[] { new StaticLibrary(flutterRoot+"/out/host_debug_unopt/obj/flutter/third_party/txt/txt_lib.lib"), new StaticLibrary(flutterRoot+"/out/host_debug_unopt/obj/third_party/angle/angle_lib.lib"), @@ -1313,7 +1338,15 @@ static void SetupDependency(NativeProgram np) return IsWindows(c) && c.CodeGen == CodeGen.Release; }, c => { - return new PrecompiledLibrary[] + return useLocal ? new PrecompiledLibrary[] + { + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/txt_lib.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/angle_lib.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/libEGL_static.lib")), + new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/libGLESv2_static.lib")), + new SystemLibrary("dxguid.lib"), + } + : new PrecompiledLibrary[] { new StaticLibrary(flutterRoot+"/out/host_release/obj/flutter/third_party/txt/txt_lib.lib"), new StaticLibrary(flutterRoot+"/out/host_release/obj/third_party/angle/angle_lib.lib"), diff --git a/engine/Scripts/Readme.md b/engine/Scripts/Readme.md new file mode 100644 index 000000000..3c1f15c33 --- /dev/null +++ b/engine/Scripts/Readme.md @@ -0,0 +1,13 @@ +## build windows lib using prebuild libs +1. copy windows prebuilds under `engine/libs` +1. copy and unzip `headerout.zip` under `engine/libs` +2. build command + + build release + ``` + .\local_build_win.ps1 + ``` + build debug + ``` + .\local_build_win.ps1 -mode debug + ``` \ No newline at end of file diff --git a/engine/Scripts/lib_build.py b/engine/Scripts/lib_build.py index 2193f998f..a2f2258ba 100644 --- a/engine/Scripts/lib_build.py +++ b/engine/Scripts/lib_build.py @@ -21,6 +21,7 @@ flutter_root_path="" visual_studio_path="" architecture="" +localLibPath=False def get_opts(): # get intput agrs @@ -31,12 +32,15 @@ def get_opts(): global visual_studio_path global platform global architecture + global localLibPath if len(sys.argv) < 2: show_help() sys.exit() - options, args = getopt.getopt(sys.argv[1:], 'r:p:m:v:eh',["arm64","help"]) + options, args = getopt.getopt(sys.argv[1:], 'l:r:p:m:v:eh',["arm64","help"]) for opt, arg in options: + if opt == '-l': + localLibPath = arg if opt == '-r': engine_path = arg # set engine_path, depot_tools and flutter engine folder will be put into this path elif opt == '-p': @@ -137,6 +141,9 @@ def set_params(): def set_env_verb(): global platform global flutter_root_path + global localLibPath + + os.environ["PREBUILD_LIB_ROOT_PATH"] = localLibPath flutter_root_path = os.getenv('FLUTTER_ROOT_PATH', 'null') if flutter_root_path == 'null': os.environ["FLUTTER_ROOT_PATH"] = os.path.join(engine_path, "engine","src") @@ -505,6 +512,8 @@ def show_help(): required parameters: + -l build use local prebuild lib + -p Target platform, available values: android, windows, mac, ios -m Build mode, available values: debug, release @@ -523,16 +532,23 @@ def show_help(): def main(): + global localLibPath + get_opts() - engine_path_check() - bitcode_conf() - set_params() - set_env_verb() - get_depot_tools() - get_flutter_engine() - compile_engine() - build_engine() - revert_patches() + if localLibPath == False: + engine_path_check() + bitcode_conf() + set_params() + set_env_verb() + get_depot_tools() + get_flutter_engine() + compile_engine() + build_engine() + revert_patches() + else: + bitcode_conf() + set_env_verb() + build_engine() if __name__=="__main__": main() \ No newline at end of file diff --git a/engine/Scripts/local_build_win.ps1 b/engine/Scripts/local_build_win.ps1 new file mode 100644 index 000000000..1f0412f18 --- /dev/null +++ b/engine/Scripts/local_build_win.ps1 @@ -0,0 +1,8 @@ +param( + [Parameter()] + [String]$mode= "release" +) +$current_dir = Get-Location +$localLibsPath = Join-Path -Path $current_dir -ChildPath "../libs" + +python3 lib_build.py -m $mode -p windows -l $localLibsPath \ No newline at end of file From 5c62863e08b0dca0c5e4f8858eb8029f61afb609 Mon Sep 17 00:00:00 2001 From: siyao Date: Wed, 27 Jul 2022 14:25:28 +0800 Subject: [PATCH 2/4] copy lib to certain folder --- engine/Build.bee.cs | 47 ++++++------------------------------- engine/Scripts/Readme.md | 13 ++++++++-- engine/Scripts/lib_build.py | 32 +++++++++++++------------ 3 files changed, 35 insertions(+), 57 deletions(-) diff --git a/engine/Build.bee.cs b/engine/Build.bee.cs index 84ce878ee..c8fec825a 100644 --- a/engine/Build.bee.cs +++ b/engine/Build.bee.cs @@ -223,22 +223,12 @@ static void DeployIOS() static void Main() { - preBuildLibRoot = Environment.GetEnvironmentVariable("PREBUILD_LIB_ROOT_PATH"); - if(preBuildLibRoot != null && preBuildLibRoot.Length > 0) + flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT_PATH"); + if (string.IsNullOrEmpty(flutterRoot)) { - cachedHeader = Path.Combine(preBuildLibRoot, "windows"); - flutterRoot = Path.Combine(preBuildLibRoot, "headerout"); - skiaRoot = flutterRoot + "/third_party/skia"; - useLocal = true; - } - else { - flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT_PATH"); - if (string.IsNullOrEmpty(flutterRoot)) - { - flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src"; - } - skiaRoot = flutterRoot + "/third_party/skia"; + flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src"; } + skiaRoot = flutterRoot + "/third_party/skia"; try { @@ -289,9 +279,6 @@ static void Main() private static string skiaRoot; private static string flutterRoot; - private static string preBuildLibRoot; - private static string cachedHeader; - private static bool useLocal; private static bool buildArm64; //this setting is disabled by default, don't change it unless you know what you are doing @@ -638,13 +625,9 @@ static NativeProgram SetupLibUIWidgets(UIWidgetsBuildTargetPlatform platform, ou np.Sources.Add(c => IsAndroid(c), androidSource); np.Libraries.Add(c => IsWindows(c), new BagOfObjectFilesLibrary( - useLocal? new NPath[]{ - Path.Combine(preBuildLibRoot, "windows/icudtl.o") - } : new NPath[]{ flutterRoot + "/third_party/icu/flutter/icudtl.o" - } - )); + })); np.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp17)); np.CompilerSettings().Add(c => IsMac(c) || IsIosOrTvos(c), c => c.WithCustomFlags(new []{"-Wno-c++11-narrowing"})); @@ -1316,15 +1299,7 @@ static void SetupDependency(NativeProgram np) return IsWindows(c) && c.CodeGen == CodeGen.Debug; }, c => { - return useLocal ? new PrecompiledLibrary[] - { - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/txt_lib.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/angle_lib.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/libEGL_static.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/debug/libGLESv2_static.lib")), - new SystemLibrary("dxguid.lib"), - } - : new PrecompiledLibrary[] + return new PrecompiledLibrary[] { new StaticLibrary(flutterRoot+"/out/host_debug_unopt/obj/flutter/third_party/txt/txt_lib.lib"), new StaticLibrary(flutterRoot+"/out/host_debug_unopt/obj/third_party/angle/angle_lib.lib"), @@ -1338,15 +1313,7 @@ static void SetupDependency(NativeProgram np) return IsWindows(c) && c.CodeGen == CodeGen.Release; }, c => { - return useLocal ? new PrecompiledLibrary[] - { - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/txt_lib.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/angle_lib.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/libEGL_static.lib")), - new StaticLibrary(Path.Combine(preBuildLibRoot, "windows/release/libGLESv2_static.lib")), - new SystemLibrary("dxguid.lib"), - } - : new PrecompiledLibrary[] + return new PrecompiledLibrary[] { new StaticLibrary(flutterRoot+"/out/host_release/obj/flutter/third_party/txt/txt_lib.lib"), new StaticLibrary(flutterRoot+"/out/host_release/obj/third_party/angle/angle_lib.lib"), diff --git a/engine/Scripts/Readme.md b/engine/Scripts/Readme.md index 3c1f15c33..8f962f70b 100644 --- a/engine/Scripts/Readme.md +++ b/engine/Scripts/Readme.md @@ -1,7 +1,16 @@ ## build windows lib using prebuild libs -1. copy windows prebuilds under `engine/libs` 1. copy and unzip `headerout.zip` under `engine/libs` -2. build command +2. copy windows prebuilds under `engine/libs/headerout` + +|File| Directory| +|---|---| +| icudtl.o| engine\libs\headerout\third_party\icu\flutter | +| angle_lib.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | +| libEGL_static.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | +| libGLESv2_static.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | +| txt_lib.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\flutter\third_party\txt | + +3. build command build release ``` diff --git a/engine/Scripts/lib_build.py b/engine/Scripts/lib_build.py index a2f2258ba..0e0a66497 100644 --- a/engine/Scripts/lib_build.py +++ b/engine/Scripts/lib_build.py @@ -143,23 +143,25 @@ def set_env_verb(): global flutter_root_path global localLibPath - os.environ["PREBUILD_LIB_ROOT_PATH"] = localLibPath - flutter_root_path = os.getenv('FLUTTER_ROOT_PATH', 'null') - if flutter_root_path == 'null': - os.environ["FLUTTER_ROOT_PATH"] = os.path.join(engine_path, "engine","src") - flutter_root_path = os.getenv('FLUTTER_ROOT_PATH') - else: - print("This environment variable has been set, skip") - env_path = os.getenv('PATH') - path_strings = re.split("[;:]", env_path) - for path in path_strings: - if path.endswith("depot_tools"): + if localLibPath == False: + flutter_root_path = os.getenv('FLUTTER_ROOT_PATH', 'null') + if flutter_root_path == 'null': + os.environ["FLUTTER_ROOT_PATH"] = os.path.join(engine_path, "engine","src") + flutter_root_path = os.getenv('FLUTTER_ROOT_PATH') + else: print("This environment variable has been set, skip") - return - if platform == "windows": - os.environ["PATH"] = engine_path + "/depot_tools;" + os.environ["PATH"] + env_path = os.getenv('PATH') + path_strings = re.split("[;:]", env_path) + for path in path_strings: + if path.endswith("depot_tools"): + print("This environment variable has been set, skip") + return + if platform == "windows": + os.environ["PATH"] = engine_path + "/depot_tools;" + os.environ["PATH"] + else: + os.environ["PATH"] = engine_path + "/depot_tools:" + os.environ["PATH"] else: - os.environ["PATH"] = engine_path + "/depot_tools:" + os.environ["PATH"] + os.environ["FLUTTER_ROOT_PATH"] = os.path.join(localLibPath, "headerout") def get_depot_tools(): print("\nGetting Depot Tools...") From c45d6df346877d13767de719140115ebed27bd21 Mon Sep 17 00:00:00 2001 From: siyao Date: Wed, 27 Jul 2022 15:33:44 +0800 Subject: [PATCH 3/4] fix --- engine/Scripts/Readme.md | 13 ++----------- engine/Scripts/lib_build.py | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/engine/Scripts/Readme.md b/engine/Scripts/Readme.md index 8f962f70b..1f5de4ea2 100644 --- a/engine/Scripts/Readme.md +++ b/engine/Scripts/Readme.md @@ -1,15 +1,6 @@ ## build windows lib using prebuild libs -1. copy and unzip `headerout.zip` under `engine/libs` -2. copy windows prebuilds under `engine/libs/headerout` - -|File| Directory| -|---|---| -| icudtl.o| engine\libs\headerout\third_party\icu\flutter | -| angle_lib.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | -| libEGL_static.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | -| libGLESv2_static.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\third_party\angle | -| txt_lib.lib| engine\libs\headerout\out\[host_debug_unopt/host_release]\obj\flutter\third_party\txt | - +1. download `engine_dependencies` under `engine/libs` +2. copy and unzip `headerout.zip` under `engine\libs\engine_dependencies\src` 3. build command build release diff --git a/engine/Scripts/lib_build.py b/engine/Scripts/lib_build.py index 0e0a66497..a109efc00 100644 --- a/engine/Scripts/lib_build.py +++ b/engine/Scripts/lib_build.py @@ -161,7 +161,7 @@ def set_env_verb(): else: os.environ["PATH"] = engine_path + "/depot_tools:" + os.environ["PATH"] else: - os.environ["FLUTTER_ROOT_PATH"] = os.path.join(localLibPath, "headerout") + os.environ["FLUTTER_ROOT_PATH"] = os.path.join(localLibPath, "engine_dependencies\src") def get_depot_tools(): print("\nGetting Depot Tools...") From ef0b91a59392b37cfe060e889f45c690233ce14d Mon Sep 17 00:00:00 2001 From: siyao Date: Wed, 27 Jul 2022 17:21:24 +0800 Subject: [PATCH 4/4] fix --- engine/Scripts/lib_build.py | 4 ++-- engine/Scripts/local_build_win.ps1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/Scripts/lib_build.py b/engine/Scripts/lib_build.py index a109efc00..6fc024fb3 100644 --- a/engine/Scripts/lib_build.py +++ b/engine/Scripts/lib_build.py @@ -40,7 +40,7 @@ def get_opts(): options, args = getopt.getopt(sys.argv[1:], 'l:r:p:m:v:eh',["arm64","help"]) for opt, arg in options: if opt == '-l': - localLibPath = arg + localLibPath = True if opt == '-r': engine_path = arg # set engine_path, depot_tools and flutter engine folder will be put into this path elif opt == '-p': @@ -161,7 +161,7 @@ def set_env_verb(): else: os.environ["PATH"] = engine_path + "/depot_tools:" + os.environ["PATH"] else: - os.environ["FLUTTER_ROOT_PATH"] = os.path.join(localLibPath, "engine_dependencies\src") + os.environ["FLUTTER_ROOT_PATH"] = os.path.join(engine_path, "src") def get_depot_tools(): print("\nGetting Depot Tools...") diff --git a/engine/Scripts/local_build_win.ps1 b/engine/Scripts/local_build_win.ps1 index 1f0412f18..427090dba 100644 --- a/engine/Scripts/local_build_win.ps1 +++ b/engine/Scripts/local_build_win.ps1 @@ -3,6 +3,6 @@ param( [String]$mode= "release" ) $current_dir = Get-Location -$localLibsPath = Join-Path -Path $current_dir -ChildPath "../libs" +$localLibsPath = Join-Path -Path $current_dir -ChildPath "../libs/engine_dependencies" -python3 lib_build.py -m $mode -p windows -l $localLibsPath \ No newline at end of file +python3 lib_build.py -m $mode -p windows -l True -r $localLibsPath \ No newline at end of file