浏览代码

Merge pull request #163 from Unity-Technologies/zgh/build_scripts

Zgh/build scripts
/main
GitHub 3 年前
当前提交
02741ecf
共有 13 个文件被更改,包括 700 次插入39 次删除
  1. 155
      engine/Build.bee.cs
  2. 21
      engine/Scripts/patches/BUILD.gn.patch
  3. 13
      engine/Scripts/patches/find_sdk.patch
  4. 20
      engine/Scripts/patches/windows/BUILD.gn.patch
  5. 10
      engine/Scripts/patches/windows/BUILD_2.gn.patch
  6. 11
      engine/Scripts/patches/windows/cpp.patch
  7. 23
      engine/Scripts/patches/android/BUILD.gn.patch
  8. 10
      engine/Scripts/patches/android/BUILD_2.gn.patch
  9. 476
      engine/Scripts/lib_build.py

155
engine/Build.bee.cs


using Bee.Toolchain.GNU;
using Bee.Toolchain.IOS;
using System.Diagnostics;
using System.IO;
enum UIWidgetsBuildTargetPlatform
{
windows,

//bee.exe win
static void DeployWindows()
{
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.windows, out var dependencies);
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.windows, out var dependencies_debug, out var dependencies_release);
var builder = new VisualStudioNativeProjectFileBuilder(libUIWidgets);
builder = libUIWidgets.SetupConfigurations.Aggregate(

sln.Projects.Add(deployed);
Backend.Current.AddAliasDependency("ProjectFiles", sln.Setup());
Backend.Current.AddAliasDependency("win", deployed.Path);
foreach (var dep in dependencies)
Backend.Current.AddAliasDependency("win_debug", deployed.Path);
foreach (var dep in dependencies_debug)
Backend.Current.AddAliasDependency("win", dep);
Backend.Current.AddAliasDependency("win_debug", dep);
}
foreach (var dep in dependencies_release)
{
Backend.Current.AddAliasDependency("win_release", dep);
}
}

var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.android, out var dependencies);
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.android, out var dependencies_debug, out var dependencies_release);
foreach (var dep in dependencies)
foreach (var dep in dependencies_debug)
Backend.Current.AddAliasDependency("android", dep);
Backend.Current.AddAliasDependency("android_debug", dep);
}
foreach (var dep in dependencies_release)
{
Backend.Current.AddAliasDependency("android_release", dep);
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.mac, out var dependencies);
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.mac, out var dependencies_debug, out var dependencies_release);
Backend.Current.AddAliasDependency("mac", new NPath("libUIWidgetsMac.xcodeproj/project.pbxproj"));
foreach (var dep in dependencies)
Backend.Current.AddAliasDependency("mac_debug", new NPath("libUIWidgetsMac.xcodeproj/project.pbxproj"));
foreach (var dep in dependencies_debug)
Backend.Current.AddAliasDependency("mac", dep);
Backend.Current.AddAliasDependency("mac_debug", dep);
}
foreach (var dep in dependencies_release)
{
Backend.Current.AddAliasDependency("mac_release", dep);
}
}

var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.ios, out var dependencies);
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.ios, out var dependencies_debug, out var dependencies_release);
Backend.Current.AddAliasDependency("ios", new NPath("libUIWidgetsIOS.xcodeproj/project.pbxproj"));
foreach(var dep in dependencies) {
Backend.Current.AddAliasDependency("ios", dep);
Backend.Current.AddAliasDependency("ios_debug", new NPath("libUIWidgetsIOS.xcodeproj/project.pbxproj"));
foreach(var dep in dependencies_debug) {
Backend.Current.AddAliasDependency("ios_debug", dep);
}
foreach(var dep in dependencies_release) {
Backend.Current.AddAliasDependency("ios_release", dep);
flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT");
flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT_PATH");
if (string.IsNullOrEmpty(flutterRoot))
{
flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src";

try
{
if(File.Exists("Scripts/bitcode.conf"))
{
using (StreamReader sr = new StreamReader("Scripts/bitcode.conf"))
{
string line;
if ((line = sr.ReadLine()) != null)
{
if(line.Trim() == "true")
{
ios_bitcode_enabled = true;
}
else
{
ios_bitcode_enabled = false;
}
}
}
}
else
{
ios_bitcode_enabled = false;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
//available target platforms of Windows
if (BuildUtils.IsHostWindows())
{

//refer to the readme file for the details
private static bool ios_bitcode_enabled = false;
static NativeProgram SetupLibUIWidgets(UIWidgetsBuildTargetPlatform platform, out List<NPath> dependencies)
static NativeProgram SetupLibUIWidgets(UIWidgetsBuildTargetPlatform platform, out List<NPath> dependencies_debug, out List<NPath> dependencies_release)
{
var np = new NativeProgram("libUIWidgets")
{

//SetupFml(np);
//SetupSkia(np);
//SetupTxt(np);
var codegens = new[] { CodeGen.Debug };
dependencies = new List<NPath>();
var codegens = new[] { CodeGen.Debug, CodeGen.Release };
dependencies_debug = new List<NPath>();
dependencies_release = new List<NPath>();
if (platform == UIWidgetsBuildTargetPlatform.windows)
{
var toolchain = ToolChain.Store.Windows().VS2019().Sdk_17134().x64();

var config = new NativeProgramConfiguration(codegen, toolchain, lump: true);
var builtNP = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat)
.DeployTo("build");
dependencies.Add(builtNP.Path);
builtNP.DeployTo("../com.unity.uiwidgets/Runtime/Plugins/x86_64");
if(codegen == CodeGen.Debug)
{
var builtNP = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat)
.DeployTo("build_debug");
dependencies_debug.Add(builtNP.Path);
}
else if(codegen == CodeGen.Release)
{
var builtNP = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat)
.DeployTo("build_release");
dependencies_release.Add(builtNP.Path);
}
}
}
else if (platform == UIWidgetsBuildTargetPlatform.android)

var config = new NativeProgramConfiguration(codegen, androidToolchain, lump: true);
validConfigurations.Add(config);
var buildNP = np.SetupSpecificConfiguration(config, androidToolchain.DynamicLibraryFormat).DeployTo("build");
var deoployNp = buildNP.DeployTo("../com.unity.uiwidgets/Runtime/Plugins/Android");
dependencies.Add(buildNP.Path);
dependencies.Add(deoployNp.Path);
if(codegen == CodeGen.Debug)
{
var buildNP = np.SetupSpecificConfiguration(config, androidToolchain.DynamicLibraryFormat).DeployTo("build_debug");
dependencies_debug.Add(buildNP.Path);
}
else if(codegen == CodeGen.Release)
{
var buildNP = np.SetupSpecificConfiguration(config, androidToolchain.DynamicLibraryFormat).DeployTo("build_release");
dependencies_release.Add(buildNP.Path);
}
}
np.ValidConfigurations = validConfigurations;
}

validConfigurations.Add(config);
var buildProgram = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat);
var buildNp = buildProgram.DeployTo("build");
var deployNp = buildProgram.DeployTo("../com.unity.uiwidgets/Runtime/Plugins/osx");
dependencies.Add(buildNp.Path);
dependencies.Add(deployNp.Path);
if(codegen == CodeGen.Debug)
{
var buildNp = buildProgram.DeployTo("build_debug");
dependencies_debug.Add(buildNp.Path);
}
else if(codegen == CodeGen.Release)
{
var buildNp = buildProgram.DeployTo("build_release");
dependencies_release.Add(buildNp.Path);
}
}
np.ValidConfigurations = validConfigurations;

var config = new NativeProgramConfiguration(codegen, toolchain, lump: true);
validConfigurations.Add(config);
var buildProgram = np.SetupSpecificConfiguration(config, toolchain.StaticLibraryFormat);
var builtNP = buildProgram.DeployTo("build");
var deployNP = buildProgram.DeployTo("../com.unity.uiwidgets/Runtime/Plugins/iOS/");
dependencies.Add(builtNP.Path);
dependencies.Add(deployNP.Path);
if(codegen == CodeGen.Debug)
{
var builtNP = buildProgram.DeployTo("build_debug");
dependencies_debug.Add(builtNP.Path);
}
else if(codegen == CodeGen.Release)
{
var builtNP = buildProgram.DeployTo("build_release");
dependencies_release.Add(builtNP.Path);
}
}
np.ValidConfigurations = validConfigurations;

21
engine/Scripts/patches/BUILD.gn.patch


--- a/third_party/txt/BUILD.gn
+++ b/third_party/txt/BUILD.gn
@@ -141,6 +141,7 @@
"//third_party/harfbuzz",
"//third_party/icu",
"//third_party/skia",
+ "//third_party/skia/modules/skottie",
]
deps = [
@@ -339,3 +340,10 @@
deps += [ "//third_party/skia/modules/skparagraph" ]
}
}
+
+static_library("txt_lib") {
+ complete_static_lib = true
+ deps = [
+ ":txt",
+ ]
+}

13
engine/Scripts/patches/find_sdk.patch


diff --git a/Users/unity/Documents/GitHub/EngineBuildTool/engine/src/build/mac/find_sdk.py b/Users/unity/Desktop/find_sdk.py
index 0534766..e503ced 100755
--- a/Users/unity/Documents/GitHub/EngineBuildTool/engine/src/build/mac/find_sdk.py
+++ b/Users/unity/Desktop/find_sdk.py
@@ -55,7 +55,7 @@ def main():
sdk_dir = xcode43_sdk_path
else:
sdk_dir = os.path.join(out.rstrip(), 'SDKs')
- sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
+ sdks = [re.findall('^MacOSX(1[0-1]\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6']
sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6']
if parse_version(s) >= parse_version(min_sdk_version)]

20
engine/Scripts/patches/windows/BUILD.gn.patch


--- E:\EngineBuildTool\engine\src\third_party\angle\BUILD.gn 2021-05-20 11:40:00 +0800
+++ E:\EngineBuildTool\engine\src\third_party\angle\modify\BUILD.gn 2021-05-20 14:02:00 +0800
@@ -1252,3 +1252,17 @@
]
}
}
+angle_static_library("angle_lib"){
+ complete_static_lib = true
+
+ deps = [
+ ":libANGLE",
+ ":libANGLE_base",
+ ":angle_system_utils",
+ ":angle_version",
+ ]
+
+ public_deps = [
+ ":includes",
+ ]
+}

10
engine/Scripts/patches/windows/BUILD_2.gn.patch


--- e:\EngineBuildTool\engine\src\third_party\skia\BUILD.gn 2021-05-20 15:48:51 +0800
+++ e:\EngineBuildTool\engine\src\third_party\skia\modify\BUILD.gn 2021-05-20 16:08:53 +0800
@@ -524,6 +524,7 @@
if (skia_use_gl) {
public_defines += [ "SK_GL" ]
+ include_dirs = [ "//third_party/angle/include" ]
if (is_android) {
sources += [ "src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp" ]

11
engine/Scripts/patches/windows/cpp.patch


--- E:\EngineBuildTool\engine\src\third_party\angle\src\libANGLE\renderer\d3d\d3d11\ExternalImageSiblingImpl11.cpp 2021-05-20 11:40:01 +0800
+++ E:\EngineBuildTool\engine\src\third_party\angle\src\libANGLE\renderer\d3d\d3d11\modify\ExternalImageSiblingImpl11.cpp 2021-05-20 14:48:30 +0800
@@ -144,7 +144,7 @@
mRenderTarget = std::make_unique<TextureRenderTarget11>(
std::move(rtv), mTexture, std::move(srv), std::move(blitSrv), formatInfo.internalFormat,
- formatInfo, mSize.width, mSize.height, 1, 1);
+ formatInfo, mSize.width, mSize.height, 1, mSamples);
return angle::Result::Continue;
}

23
engine/Scripts/patches/android/BUILD.gn.patch


--- /Users/unity/Documents/GitHub/EngineBuildTool/engine/src/flutter/third_party/txt/BUILD.gn 2021-05-19 11:45:24.000000000 +0800
+++ /Users/unity/Documents/GitHub/EngineBuildTool/engine/src/flutter/third_party/txt/modify/BUILD.gn 2021-05-19 11:44:06.000000000 +0800
@@ -141,6 +141,9 @@
"//third_party/harfbuzz",
"//third_party/icu",
"//third_party/skia",
+ "//third_party/skia/modules/skottie",
+ "//third_party/libcxx",
+ "//third_party/libcxxabi",
]
deps = [
@@ -339,3 +342,10 @@
deps += [ "//third_party/skia/modules/skparagraph" ]
}
}
+
+static_library("txt_lib") {
+ complete_static_lib = true
+ deps = [
+ ":txt",
+ ]
+}

10
engine/Scripts/patches/android/BUILD_2.gn.patch


--- /Users/unity/Documents/GitHub/EngineBuildTool/engine/src/build/secondary/third_party/libcxxabi/BUILD.gn 2021-05-19 10:57:31.000000000 +0800
+++ /Users/unity/Documents/GitHub/EngineBuildTool/engine/src/build/secondary/third_party/libcxxabi/modify/BUILD.gn 2021-05-19 11:53:06.000000000 +0800
@@ -7,7 +7,6 @@
}
source_set("libcxxabi") {
- visibility = [ "../libcxx:*" ]
sources = [
"src/abort_message.cpp",

476
engine/Scripts/lib_build.py


from genericpath import exists
from pathlib import Path
import os
import sys
import getopt
import shutil
import json
work_path=os.getcwd()
engine_path=""
platform=""
gn_params=""
optimize=""
ninja_params=""
ninja_params1=""
ninja_params2=""
ninja_params3=""
runtime_mode=""
bitcode=""
flutter_root_path=""
visual_studio_path=""
def get_opts():
# get intput agrs
global engine_path
global gn_params
global runtime_mode
global bitcode
global visual_studio_path
global platform
if len(sys.argv) < 2:
show_help()
sys.exit()
options, args = getopt.getopt(sys.argv[1:], 'r:p:m:v:eh',["help"])
for opt, arg in options:
if opt == '-r':
engine_path = arg # set engine_path, depot_tools and flutter engine folder will be put into this path
elif opt == '-p':
platform = arg
if platform == "android" or platform == "ios":
gn_params += " --" + arg # set the target platform android/ios
elif opt == '-m':
runtime_mode = arg
gn_params += " --runtime-mode=" + runtime_mode # set runtime mode release/debug
elif opt == '-v':
visual_studio_path = arg
elif opt == '-e':
bitcode="-bitcode_bundle -bitcode_verify"
elif opt in ("-h","--help"):
show_help()
sys.exit()
if platform == "ios" and bitcode == "-bitcode_bundle -bitcode_verify":
gn_params += " --bitcode" # enable-bitcode switch
def engine_path_check():
global engine_path
if not os.path.exists(engine_path):
os.makedirs(engine_path)
def bitcode_conf():
global platform
global bitcode
if platform == "ios":
f = open("bitcode.conf",'w')
if bitcode == "-bitcode_bundle -bitcode_verify":
f.write("true")
else:
f.write("false")
f.close()
def set_params():
global output_path
global ninja_params
global ninja_params1
global ninja_params2
global ninja_params3
global gn_params
global visual_studio_path
global platform
global optimize
print("setting environment variable and other params...")
if platform == "windows":
visual_studio_path_env = os.getenv('GYP_MSVS_OVERRIDE_PATH', 'null')
if visual_studio_path == "":
if visual_studio_path_env == 'null':
assert False, "In func set_params(), visual_studio_path is not exist, please set the path by using \"-v\" param to set a engine path."
else:
os.environ["GYP_MSVS_OVERRIDE_PATH"] = visual_studio_path
if runtime_mode == "release" and (platform == "mac" or platform == "windows"):
optimize=""
output_path="host_release"
ninja_params1=" -C out/" +output_path + " flutter/third_party/txt:txt_lib"
ninja_params2=" -C out/" +output_path + " third_party/angle:angle_lib"
ninja_params3=" -C out/" +output_path + " third_party/angle:libEGL_static"
elif runtime_mode == "debug" and (platform == "mac" or platform == "windows"):
optimize="--unoptimized"
output_path="host_debug_unopt"
ninja_params1=" -C out/" +output_path + " flutter/third_party/txt:txt_lib"
ninja_params2=" -C out/" +output_path + " third_party/angle:angle_lib"
ninja_params3=" -C out/" +output_path + " third_party/angle:libEGL_static"
elif runtime_mode == "release" and platform == "android":
optimize=""
output_path="android_release"
elif runtime_mode == "debug" and platform == "android":
optimize="--unoptimized"
output_path="android_debug_unopt"
elif runtime_mode == "release" and platform == "ios":
optimize=""
output_path="ios_release"
elif runtime_mode == "debug" and platform == "ios":
optimize="--unoptimized"
output_path="ios_debug_unopt"
else:
assert False, "In func set_params(), unknown param"
ninja_params=" -C out/" + output_path + " flutter/third_party/txt:txt_lib"
gn_params=gn_params + " " + optimize
def set_env_verb():
global flutter_root_path
flutter_root_path = os.getenv('FLUTTER_ROOT_PATH', 'null')
if flutter_root_path == 'null':
os.environ["FLUTTER_ROOT_PATH"] = 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 = env_path.split(';')
for path in path_strings:
if path.startswith(engine_path):
print("This environment variable has been set, skip")
return
os.environ["PATH"] = engine_path + "/depot_tools;" + os.environ["PATH"]
def get_depot_tools():
print("\nGetting Depot Tools...")
if not os.path.exists(engine_path):
assert False,"Flutter engine path is not exist, please set the path by using \"-r\" param to set a engine path."
if os.path.exists(Path(engine_path + "/depot_tools")) and os.path.exists(Path(engine_path + "/depot_tools/.git")):
print("depot_tools already installed, skip")
else:
os.chdir(engine_path)
os.system("git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git")
os.system("gclient")
def get_flutter_engine():
global engine_path
global flutter_root_path
print("\nGetting flutter engine...")
if not os.path.exists(Path(engine_path + "/engine")):
os.makedirs(Path(engine_path + "/engine"))
content = '''
solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "git@github.com:flutter/engine.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]
'''
f = open(Path(engine_path + "/engine/.gclient"), "w")
f.write(content)
f.close()
os.chdir(Path(engine_path + "/engine"))
os.system("gclient sync")
os.chdir(Path(flutter_root_path + "/flutter"))
os.system("git checkout flutter-1.17-candidate.5")
os.system("gclient sync -D")
def compile_engine():
global flutter_root_path
global work_path
global gn_params
global output_path
global ninja_params1
global ninja_params2
global ninja_params3
global platform
print("\nSCompiling engine...")
if platform == "ios" or platform == "mac":
os.chdir(Path(flutter_root_path + "/flutter/third_party/txt"))
copy_file(Path(work_path + "/patches/BUILD.gn.patch"), Path(flutter_root_path + "/flutter/third_party/txt"))
os.system("patch < BUILD.gn.patch -N")
os.chdir(Path(flutter_root_path + "/build/mac"))
copy_file(Path(work_path + "/patches/find_sdk.patch"), Path(flutter_root_path + "/build/mac"))
os.system("patch < find_sdk.patch -N")
elif platform == "android":
os.chdir(Path(flutter_root_path + "/flutter/third_party/txt"))
copy_file(Path(work_path + "/patches/android/BUILD.gn.patch"), Path(flutter_root_path + "/flutter/third_party/txt"))
os.system("patch < BUILD.gn.patch -N")
os.chdir(Path(flutter_root_path + "/build/mac"))
copy_file(Path(work_path + "/patches/find_sdk.patch"), Path(flutter_root_path + "/build/mac"))
os.system("patch < find_sdk.patch -N")
os.chdir(Path(flutter_root_path + "/build/secondary/third_party/libcxxabi"))
copy_file(Path(work_path + "/patches/android/BUILD_2.gn.patch"), Path(flutter_root_path + "/build/secondary/third_party/libcxxabi"))
os.system("patch < BUILD_2.gn.patch -N")
elif platform == "windows":
os.chdir(Path(flutter_root_path + "/flutter/third_party/txt"))
copy_file(Path(work_path + "/patches/BUILD.gn.patch"), Path(flutter_root_path + "/flutter/third_party/txt"))
os.system("patch < BUILD.gn.patch -N")
os.chdir(Path(flutter_root_path + "/third_party/angle"))
copy_file(Path(work_path + "/patches/windows/BUILD.gn.patch"), Path(flutter_root_path + "/third_party/angle"))
os.system("patch < BUILD.gn.patch -N")
os.chdir(Path(flutter_root_path + "/third_party/angle/src/libANGLE/renderer/d3d/d3d11/"))
copy_file(Path(work_path + "/patches/windows/cpp.patch"), Path(flutter_root_path + "/third_party/angle/src/libANGLE/renderer/d3d/d3d11"))
os.system("patch < cpp.patch -N")
os.chdir(Path(flutter_root_path + "/third_party/skia/"))
copy_file(Path(work_path + "/patches/windows/BUILD_2.gn.patch"), Path(flutter_root_path + "/third_party/skia"))
os.system("patch < BUILD_2.gn.patch -N")
os.chdir(Path(flutter_root_path))
os.system("python ./flutter/tools/gn " + gn_params)
if platform == "mac":
f = open(Path(flutter_root_path + "/out/" + output_path + "/args.gn"), 'a')
f.write("icu_use_data_file = false")
f.close()
os.system("ninja " + ninja_params)
elif platform == "ios":
old_str = "bitcode_marker = true"
new_str = "bitcode_marker = false"
file_data = ""
with open(Path(flutter_root_path + "/out/" + output_path + "/args.gn"), "r") as f:
for line in f:
if old_str in line:
line = line.replace(old_str,new_str)
file_data += line
file_data += "icu_use_data_file = false"
with open(Path(flutter_root_path + "/out/" + output_path + "/args.gn"),"w") as f:
f.write(file_data)
os.system("ninja " + ninja_params)
elif platform == "windows":
f = open(Path(flutter_root_path + "/out/" + output_path + "/args.gn"), 'a')
f.write("skia_use_angle = true\nskia_use_egl = true")
f.close()
os.system("ninja " + ninja_params1)
os.system("ninja " + ninja_params2)
os.system("ninja " + ninja_params3)
os.chdir(Path(flutter_root_path + "/third_party/icu/flutter/"))
os.system("ld -r -b binary -o icudtl.o icudtl.dat")
elif platform == "android":
os.system("ninja " + ninja_params)
def build_engine():
global flutter_root_path
global work_path
global runtime_mode
global platform
global output_path
global bitcode
dest_folder=""
print("\nStarting build engine...")
if platform == "windows":
dest_folder = "x86_64"
elif platform == "mac":
dest_folder = "osx"
elif platform == "android":
dest_folder = "android"
os.chdir(work_path + "/../")
os.system("python " + flutter_root_path + "/flutter/sky/tools/objcopy.py --objcopy " + flutter_root_path + "/third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objcopy --input " + flutter_root_path + "/third_party/icu/flutter/icudtl.dat --output icudtl.o --arch arm")
elif platform == "ios":
dest_folder = "ios"
if not os.path.exists(Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/" + dest_folder)):
os.makedirs(Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/" + dest_folder))
os.chdir(Path(work_path + "/../"))
if runtime_mode == "release":
if os.path.exists(Path(work_path + "/../build_release")):
shutil.rmtree(Path(work_path + "/../build_release"))
if platform == "windows":
os.system("bee.exe win_release")
copy_file(Path(work_path + "/../build_release/"), Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/" + dest_folder))
else:
os.system("mono bee.exe " + platform +"_release")
copy_file(Path(work_path + "/../build_release/"), Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/" + dest_folder))
if platform == "android":
tundra_file=Path(work_path + "/../artifacts/tundra.dag.json")
rsp = get_rsp(tundra_file, runtime_mode)
if not os.path.exists(Path(work_path + "/../artifacts/rsp/backup")):
os.makedirs(Path(work_path + "/../artifacts/rsp/backup"))
copy_file(Path(work_path + "/../" + rsp), Path(work_path + "/../artifacts/rsp/backup"))
os.chdir(Path(work_path))
rsp_patch()
os.chdir(Path(work_path + "/../"))
os.system("artifacts/Stevedore/android-ndk-mac/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ " + "@\"" + rsp + "\"")
os.system(flutter_root_path + "/buildtools/mac-x64/clang/bin/clang++ " + "@\"" + rsp + "\"")
copy_file(Path(work_path + "/../artifacts/libUIWidgets/release_Android_arm32/libUIWidgets.so"), Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/Android"))
elif platform == "ios":
print("\nStarting prlink library...")
os.chdir(Path(work_path + "/../"))
tundra_file=Path(work_path + "/../artifacts/tundra.dag.json")
prelinkfiles(tundra_file, runtime_mode, output_path, work_path, bitcode)
elif runtime_mode == "debug":
if os.path.exists(Path(work_path + "/../build_debug")):
shutil.rmtree(Path(work_path + "/../build_debug"))
if platform == "windows":
os.system("bee.exe win_debug")
else:
os.system("mono bee.exe " + platform +"_debug")
copy_file(Path(work_path + "/../build_debug/"), Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/" + dest_folder))
if platform == "ios":
print("\nStarting prlink library...")
os.chdir(Path(work_path + "/../"))
tundra_file=Path(work_path + "/../artifacts/tundra.dag.json")
prelinkfiles(tundra_file, runtime_mode, output_path, work_path, bitcode)
def revert_patches():
global flutter_root_path
print("\nRevert patches...")
os.chdir(Path(flutter_root_path + "/flutter/third_party/txt"))
os.system("patch -R < BUILD.gn.patch")
if platform == "ios" or platform == "mac":
os.chdir(Path(flutter_root_path + "/build/mac"))
os.system("patch -R < find_sdk.patch")
if platform == "ios":
os.chdir(Path(work_path))
if os.path.exists(Path(work_path + "/bitcode.conf")):
os.remove("bitcode.conf")
elif platform == "android":
os.chdir(Path(flutter_root_path + "/build/mac"))
os.system("patch -R < find_sdk.patch")
os.chdir(Path(flutter_root_path + "/build/secondary/third_party/libcxxabi"))
os.system("patch -R < BUILD_2.gn.patch")
elif platform == "windows":
os.chdir(Path(flutter_root_path + "/third_party/angle"))
os.system("patch -R < BUILD.gn.patch")
os.chdir(Path(flutter_root_path + "/third_party/angle/src/libANGLE/renderer/d3d/d3d11/"))
os.system("patch -R < cpp.patch")
os.chdir(Path(flutter_root_path + "/third_party/skia/"))
os.system("patch -R < BUILD_2.gn.patch")
def copy_file(source_path, target_path):
if not os.path.exists(target_path):
os.makedirs(target_path)
if os.path.exists(source_path):
if os.path.isfile(source_path):
shutil.copy(source_path, target_path)
elif os.path.isdir(source_path):
for root, dirs, files in os.walk(source_path):
for file in files:
src_file = os.path.join(root, file)
shutil.copy(src_file, target_path)
def rsp_patch():
global work_path
file_data = ""
file = Path(work_path + "/../artifacts/rsp/14590475716575637239.rsp")
old_str = ',--icf-iterations=5'
with open(file, "r") as f:
for line in f:
if old_str in line:
line = line.replace(old_str,'')
file_data += line
with open(file,"w") as f:
f.write(file_data)
return "rsp modified"
def get_xcode_path():
res = os.popen('xcode-select -p')
return res.read()
def get_target_files(tundra_file, runtime_mode):
if not os.path.exists(tundra_file):
print('tundra.dag.json file not found')
return None
with open(tundra_file, 'r') as f:
temp = json.loads(f.read())
json_list = temp['Nodes']
target_files=''
for item in json_list:
if item['Annotation'].startswith('Lib_iOS_arm64') and item['Annotation'].find(runtime_mode) != -1:
action = item['Action']
o_file_list = action.split("\"")
for o in o_file_list:
if o.endswith('.o'):
target_files += ' '+o
return target_files
def prelinkfiles(tundra_file, runtime_mode, output_path, work_path, bitcode):
global flutter_root_path
target_files = get_target_files(tundra_file, runtime_mode)
if not target_files:
print("get prelink xxx.o files failed")
else:
os.system('nm -j ' + flutter_root_path + '/out/' + output_path + '/obj/flutter/third_party/txt/libtxt_lib.a > third.symbol')
xcode_path = get_xcode_path().strip()
os.system('\"' + xcode_path + '/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -r -arch arm64 ' + bitcode + ' -syslibroot ' + xcode_path + '/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -unexported_symbols_list third.symbol ' + target_files + ' ' + flutter_root_path + '/out/' + output_path + '/obj/flutter/third_party/txt/libtxt_lib.a -o "libUIWidgets.o"')
os.system('\"' + xcode_path + '/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool" -arch_only arm64 -static "libUIWidgets.o" -o "libUIWidgets.a"')
os.system('\"' + xcode_path + '/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip" -x "libUIWidgets.a"')
copy_file(Path(work_path + "/../libUIWidgets.a"), Path(work_path + "/../../com.unity.uiwidgets/Runtime/Plugins/ios/libUIWidgets.a"))
def get_rsp(tundra_file, runtime_mode):
if not os.path.exists(tundra_file):
print('tundra.dag.json file not found')
return None
with open(tundra_file, 'r') as f:
temp = json.loads(f.read())
json_list = temp['Nodes']
target_files=''
for item in json_list:
if item['Annotation'].startswith('Link_Android_arm32') and item['Annotation'].find(runtime_mode) != -1:
action_list = item['Inputs']
for o in action_list:
if o.endswith('.rsp'):
return o
def show_help():
help_note = '''
SYNOPSIS
python3 lib_build.py <-p <android|ios|windows|mac>> <-r <engine_path>> <-m <debug|release>> [-v [visual_studio_path]] [-e] [-h] [--help].
NOTION
python3 is required to run this script. For windows, visual studio 2017 need to be installed. For mac, Xcode need to be installed and Mac version should be 10 or 11.
You can build for mac/ios/android platforms on Mac. You can only build for windows platform on Windows
DESCRIPTION
lib_build.py will setup the build environment and build UIWidgets' engine.
The following options are available:
required parameters:
-p Target platform, available values: android, windows, mac, ios
-m Build mode, available values: debug, release
-r The build target directory, third party dependencies (e.g., flutter engine) will be downloaded and built here
optional parameters:
-h, --help Show this help message
-e Enable bitcode for ios targets and can only be used when "-p ios" is specified
-v The visual studio path in your PC, e.g., "C:\Program Files (x86)/Microsoft Visual Studio/2017/Community". It is required if "-p window" is specified
'''
print(help_note)
def main():
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 __name__=="__main__":
main()
正在加载...
取消
保存