using Bee.Tools ;
using NiceIO ;
using System.Collections.Generic ;
using System.Runtime.InteropServices ;
using RuntimeInformation = System . Runtime . InteropServices . RuntimeInformation ;
using OSPlatform = System . Runtime . InteropServices . OSPlatform ;
using Bee.Toolchain.GNU ;
using Bee.Toolchain.IOS ;
using System.Diagnostics ;
class BuildUtils
enum UIWidgetsBuildTargetPlatform
{
windows ,
mac ,
ios ,
android
}
static class BuildUtils
{
public static bool IsHostWindows ( )
{
}
}
/ * *
* How to add new target platform ( taking iOS as the example )
* ( 1 ) add a new static void DeployIOS ( ) { } in which we need call SetupLibUIWidgets ( ) with UIWidgetsBuildTargetPlatform . ios as its
* first parameter . We should also generate the corresponding project file ( i . e . , XcodeProjectFile ) . Finally , we should call
* Backend . Current . AddAliasDependency ( "ios" , dep ) to add the alias "ios" to all the final output files for ios platform . By
* doing so , we can call "mono bee.exe ios" in command line to tell bee to process the specific subgraph for ios build only .
* ( refer to the following session for the details on this : https : //unity.slack.com/archives/C1RM0NBLY/p1615797377297800)
*
* ( 2 ) add the DeployIOS ( ) function inside the available target platforms of MacOS in Main ( ) since the dependencies on ios - platform
* , i . e . , skia , flutter , etc . can only be built on Mac .
*
* ( 3 ) pick the corresponding toolchains for UIWidgetsBuildTargetPlatform . ios at the end of the function SetupLibUIWidgets ( ) and setup
* the build targets .
*
* ( 4 ) change all the build settings ( e . g . , Defines , Includes , Source files ) accordingly with platform - filters like IsMac , IsWindows ,
* IsIosOrTvos inside bee for plaform - dependent settings .
*
* ( 5 ) finally , try call "mono bee.exe" with our predefined platform - dependent alias name "ios" in step ( 1 ) , i . e . , "mono bee.exe ios"
* to start the build
* * /
static void Main ( )
//bee.exe win
static void DeployWindows ( )
skiaRoot = Environment . GetEnvironmentVariable ( "SKIA_ROOT" ) ;
if ( string . IsNullOrEmpty ( skiaRoot ) )
var libUIWidgets = SetupLibUIWidgets ( UIWidgetsBuildTargetPlatform . windows , out var dependencies ) ;
var builder = new VisualStudioNativeProjectFileBuilder ( libUIWidgets ) ;
builder = libUIWidgets . SetupConfigurations . Aggregate (
builder ,
( current , c ) = > current . AddProjectConfiguration ( c ) ) ;
var sln = new VisualStudioSolution ( ) ;
sln . Path = "libUIWidgets.gen.sln" ;
var deployed = builder . DeployTo ( "libUIWidgets.gen.vcxproj" ) ;
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" , dep ) ;
}
}
//bee.exe mac
static void DeployMac ( )
{
if ( buildAndroid )
{
var libUIWidgets = SetupLibUIWidgets ( UIWidgetsBuildTargetPlatform . mac , out var dependencies ) ;
var androidProject = AndroidNativeProgramExtensions . DynamicLinkerSettingsForAndroid ( libUIWidgets ) ;
}
else
skiaRoot = Environment . GetEnvironmentVariable ( "USERPROFILE" ) + "/skia_repo/skia" ;
var libUIWidgets = SetupLibUIWidgets ( UIWidgetsBuildTargetPlatform . mac , out var dependencies ) ;
var nativePrograms = new List < NativeProgram > ( ) ;
nativePrograms . Add ( libUIWidgets ) ;
var xcodeProject = new XCodeProjectFile ( nativePrograms , new NPath ( "libUIWidgetsMac.xcodeproj/project.pbxproj" ) ) ;
Backend . Current . AddAliasDependency ( "mac" , new NPath ( "libUIWidgetsMac.xcodeproj/project.pbxproj" ) ) ;
foreach ( var dep in dependencies )
{
Backend . Current . AddAliasDependency ( "mac" , dep ) ;
}
}
static void Main ( )
{
flutterRoot = Environment . GetEnvironmentVariable ( "FLUTTER_ROOT" ) ;
if ( string . IsNullOrEmpty ( flutterRoot ) )
{
var buildAndroidEnv = Environment . GetEnvironmentVariable ( "BUILD_ANDROID" ) ;
buildAndroid = true ;
var libUIWidgets = SetupLibUIWidgets ( ) ;
skiaRoot = flutterRoot + "/third_party/skia" ;
//create ide projects
//available target platforms of Windows
//create vs project
var builder = new VisualStudioNativeProjectFileBuilder ( libUIWidgets ) ;
builder = libUIWidgets . SetupConfigurations . Aggregate (
builder ,
( current , c ) = > current . AddProjectConfiguration ( c ) ) ;
var sln = new VisualStudioSolution ( ) ;
sln . Path = "libUIWidgets.gen.sln" ;
sln . Projects . Add ( builder . DeployTo ( "libUIWidgets.gen.vcxproj" ) ) ;
Backend . Current . AddAliasDependency ( "ProjectFiles" , sln . Setup ( ) ) ;
DeployWindows ( ) ;
//available target platforms of MacOS
if ( buildAndroid )
{
var androidProject = AndroidNativeProgramExtensions . DynamicLinkerSettingsForAndroid ( libUIWidgets ) ;
}
else
{
//create xcode project
var nativePrograms = new List < NativeProgram > ( ) ;
nativePrograms . Add ( libUIWidgets ) ;
var xcodeProject = new XCodeProjectFile ( nativePrograms , new NPath ( "libUIWidgets.xcodeproj/project.pbxproj" ) ) ;
}
DeployMac ( ) ;
}
}
static NativeProgram SetupLibUIWidgets ( )
static NativeProgram SetupLibUIWidgets ( UIWidgetsBuildTargetPlatform platform , out List < NPath > dependencies )
{
var np = new NativeProgram ( "libUIWidgets" )
{
np . Libraries . Add ( c = > IsWindows ( c ) , new BagOfObjectFilesLibrary (
new NPath [ ] {
skia Root + "/third_party/externals /icu/flutter/icudtl.o"
flutter Root + "/third_party/icu/flutter/icudtl.o"
np . Defines . Add ( c = > IsAndroid ( c ) , new [ ] {
np . Defines . Add ( c = > IsAndroid ( c ) , new [ ] {
"USE_OPENSSL=1" ,
"USE_OPENSSL_CERTS=1" ,
"ANDROID" ,
}
else
{
SetupFml ( np ) ;
SetupRadidJson ( np ) ;
SetupSkia ( np ) ;
SetupTxt ( np ) ;
SetupDependency ( np ) ;
//SetupFml(np);
//SetupSkia(np);
//SetupTxt(np);
dependencies = new List < NPath > ( ) ;
if ( BuildUtils . IsHostWindows ( ) )
if ( platform = = UIWidgetsBuildTargetPlatform . windows )
{
var toolchain = ToolChain . Store . Windows ( ) . VS2019 ( ) . Sdk_17134 ( ) . x64 ( ) ;
var builtNP = np . SetupSpecificConfiguration ( config , toolchain . DynamicLibraryFormat )
. DeployTo ( "build" ) ;
dependencies . Add ( builtNP . Path ) ;
else if ( BuildUtils . IsHostMac ( ) )
else if ( platform = = UIWidgetsBuildTargetPlatform . mac )
{
if ( buildAndroid )
{
builtNP . DeployTo ( "../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/Android" ) ;
builtNP . DeployTo ( "/Users/siyao/Documents/GitHub/untitled folder/unityLibrary/src/main/jniLibs/armeabi-v7a" ) ;
}
else
{
var config = new NativeProgramConfiguration ( codegen , toolchain , lump : true ) ;
validConfigurations . Add ( config ) ;
var builtNP = np . SetupSpecificConfiguration ( config , toolchain . DynamicLibraryFormat ) . DeployTo ( "build" ) ;
builtNP . DeployTo ( "../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/osx" ) ;
var buildProgram = np . SetupSpecificConfiguration ( config , toolchain . DynamicLibraryFormat ) ;
var buildNp = buildProgram . DeployTo ( "build" ) ;
var deployNp = buildProgram . DeployTo ( "../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/osx" ) ;
dependencies . Add ( buildNp . Path ) ;
dependencies . Add ( deployNp . Path ) ;
}
return np ;
} ) ;
}
static void SetupDependency ( NativeProgram np )
{
SetupRadidJson ( np ) ;
// TODO: fix warning, there are some type mismatches
var ignoreWarnigs = new string [ ] { "4244" , "4267" , "5030" , "4101" , "4996" , "4359" , "4018" , "4091" , "4722" , "4312" , "4838" , "4172" , "4005" , "4311" , "4477" } ;
np . CompilerSettings ( ) . Add ( c = > IsWindows ( c ) , s = > s . WithWarningPolicies ( ignoreWarnigs . Select ( ( code ) = > new WarningAndPolicy ( code , WarningPolicy . Silent ) ) . ToArray ( ) ) ) ;
np . Defines . Add ( c = > IsMac ( c ) , new [ ]
{
//lib flutter
"USE_OPENSSL=1" ,
"__STDC_CONSTANT_MACROS" ,
"__STDC_FORMAT_MACROS" ,
"_FORTIFY_SOURCE=2" ,
"_LIBCPP_DISABLE_AVAILABILITY=1" ,
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ,
"_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS" ,
"_DEBUG" ,
"FLUTTER_RUNTIME_MODE_DEBUG=1" ,
"FLUTTER_RUNTIME_MODE_PROFILE=2" ,
"FLUTTER_RUNTIME_MODE_RELEASE=3" ,
"FLUTTER_RUNTIME_MODE_JIT_RELEASE=4" ,
"FLUTTER_RUNTIME_MODE=1" ,
"FLUTTER_JIT_RUNTIME=1" ,
//lib skia
"SK_ENABLE_SPIRV_VALIDATION" ,
"SK_ASSUME_GL=1" ,
"SK_ENABLE_API_AVAILABLE" ,
"SK_GAMMA_APPLY_TO_A8" ,
"GR_OP_ALLOCATE_USE_NEW" ,
"SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1" ,
"GR_TEST_UTILS=1" ,
"SKIA_IMPLEMENTATION=1" ,
"SK_GL" ,
"SK_ENABLE_DUMP_GPU" ,
"SK_SUPPORT_PDF" ,
"SK_CODEC_DECODES_JPEG" ,
"SK_ENCODE_JPEG" ,
"SK_ENABLE_ANDROID_UTILS" ,
"SK_USE_LIBGIFCODEC" ,
"SK_HAS_HEIF_LIBRARY" ,
"SK_CODEC_DECODES_PNG" ,
"SK_ENCODE_PNG" ,
"SK_CODEC_DECODES_RAW" ,
"SK_ENABLE_SKSL_INTERPRETER" ,
"SKVM_JIT_WHEN_POSSIBLE" ,
"SK_CODEC_DECODES_WEBP" ,
"SK_ENCODE_WEBP" ,
"SK_XML" ,
} ) ;
//lib txt
np . Defines . Add ( c = > IsMac ( c ) , new [ ] {
"SK_USING_THIRD_PARTY_ICU" , "U_USING_ICU_NAMESPACE=0" ,
"U_ENABLE_DYLOAD=0" , "USE_CHROMIUM_ICU=1" , "U_STATIC_IMPLEMENTATION" ,
"ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC"
} ) ;
np . IncludeDirectories . Add ( c = > IsWindows ( c ) , new NPath [ ] {
"." ,
"third_party" ,
"src" ,
flutterRoot ,
flutterRoot + "/third_party/rapidjson/include" ,
flutterRoot + "/third_party/angle/include" ,
skiaRoot ,
flutterRoot + "/flutter/third_party/txt/src" ,
flutterRoot + "/third_party/harfbuzz/src" ,
flutterRoot + "/third_party/icu/source/common" ,
flutterRoot + "/third_party/icu/source/common" ,
flutterRoot + "/third_party/icu/source/i18n" ,
} ) ;
np . CompilerSettings ( ) . Add ( c = > IsWindows ( c ) , c = > c . WithCustomFlags ( new [ ] {
"-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING" ,
"-DUSE_OPENSSL=1" ,
"-D__STD_C" ,
"-D_CRT_RAND_S" ,
"-D_CRT_SECURE_NO_DEPRECATE" ,
"-D_HAS_EXCEPTIONS=0" ,
"-D_SCL_SECURE_NO_DEPRECATE" ,
"-DWIN32_LEAN_AND_MEAN" ,
"-DNOMINMAX" ,
"-D_ATL_NO_OPENGL" ,
"-D_WINDOWS" ,
"-DCERT_CHAIN_PARA_HAS_EXTRA_FIELDS" ,
"-DNTDDI_VERSION=0x06030000" ,
"-DPSAPI_VERSION=1" ,
"-DWIN32" ,
"-D_SECURE_ATL" ,
"-D_USING_V110_SDK71_" ,
"-D_UNICODE" ,
"-DUNICODE" ,
"-D_WIN32_WINNT=0x0603" ,
"-DWINVER=0x0603" ,
"-D_DEBUG" ,
"-DU_USING_ICU_NAMESPACE=0" ,
"-DU_ENABLE_DYLOAD=0" ,
"-DUSE_CHROMIUM_ICU=1" ,
"-DU_STATIC_IMPLEMENTATION" ,
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE" ,
"-DUCHAR_TYPE=wchar_t" ,
"-DFLUTTER_RUNTIME_MODE_DEBUG=1" ,
"-DFLUTTER_RUNTIME_MODE_PROFILE=2" ,
"-DFLUTTER_RUNTIME_MODE_RELEASE=3" ,
"-DFLUTTER_RUNTIME_MODE_JIT_RELEASE=4" ,
"-DFLUTTER_RUNTIME_MODE=1" ,
"-DFLUTTER_JIT_RUNTIME=1" ,
"-DSK_ENABLE_SPIRV_VALIDATION" ,
"-D_CRT_SECURE_NO_WARNINGS" ,
"-D_HAS_EXCEPTIONS=0" ,
"-DWIN32_LEAN_AND_MEAN" ,
"-DNOMINMAX" ,
"-DSK_GAMMA_APPLY_TO_A8" ,
"-DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1" ,
// TODO: fix this by update txt_lib build setting, reference: https://github.com/microsoft/vcpkg/issues/12123
// "-DGR_TEST_UTILS=1",
"-DSKIA_IMPLEMENTATION=1" ,
"-DSK_GL" ,
"-DSK_ENABLE_DUMP_GPU" ,
"-DSK_SUPPORT_PDF" ,
"-DSK_CODEC_DECODES_JPEG" ,
"-DSK_ENCODE_JPEG" ,
"-DSK_SUPPORT_XPS" ,
"-DSK_ENABLE_ANDROID_UTILS" ,
"-DSK_USE_LIBGIFCODEC" ,
"-DSK_HAS_HEIF_LIBRARY" ,
"-DSK_CODEC_DECODES_PNG" ,
"-DSK_ENCODE_PNG" ,
"-DSK_ENABLE_SKSL_INTERPRETER" ,
"-DSK_CODEC_DECODES_WEBP" ,
"-DSK_ENCODE_WEBP" ,
"-DSK_XML" ,
"-DLIBEGL_IMPLEMENTATION" ,
"-D_CRT_SECURE_NO_WARNINGS" ,
"-D_HAS_EXCEPTIONS=0" ,
"-DWIN32_LEAN_AND_MEAN" ,
"-DNOMINMAX" ,
"-DANGLE_ENABLE_ESSL" ,
"-DANGLE_ENABLE_GLSL" ,
"-DANGLE_ENABLE_HLSL" ,
"-DANGLE_ENABLE_OPENGL" ,
"-DEGL_EGLEXT_PROTOTYPES" ,
"-DGL_GLEXT_PROTOTYPES" ,
"-DANGLE_ENABLE_D3D11" ,
"-DANGLE_ENABLE_D3D9" ,
"-DGL_APICALL=" ,
"-DGL_API=" ,
"-DEGLAPI=" ,
"/FS" ,
"/MTd" ,
"/Od" ,
"/Ob0" ,
"/RTC1" ,
"/Zi" ,
"/WX" ,
"/std:c++17" ,
"/GR-" ,
} ) ) ;
np . CompilerSettings ( ) . Add ( c = > IsMac ( c ) , c = > c . WithCustomFlags ( new [ ] {
"-MD" ,
"-MF" ,
"-I." ,
"-Ithird_party" ,
"-Isrc" ,
"-I" + flutterRoot ,
"-I" + flutterRoot + "/third_party/rapidjson/include" ,
"-I" + skiaRoot ,
"-I" + flutterRoot + "/flutter/third_party/txt/src" ,
"-I" + flutterRoot + "/third_party/harfbuzz/src" ,
"-I" + skiaRoot + "/third_party/externals/icu/source/common" ,
// "-Igen",
"-I" + flutterRoot + "/third_party/icu/source/common" ,
"-I" + flutterRoot + "/third_party/icu/source/i18n" ,
"-fvisibility-inlines-hidden" ,
} ) ) ;
var windowsSkiaBuild = skiaRoot + "/out/Debug" ;
np . Libraries . Add ( IsWindows , c = >
{
return new PrecompiledLibrary [ ]
{
new StaticLibrary ( flutterRoot + "/out/host_debug_unopt/obj/flutter/third_party/txt/txt_lib.lib" ) ,
new StaticLibrary ( windowsSkiaBuild + "/libEGL.dll.lib" ) ,
new StaticLibrary ( windowsSkiaBuild + "/libGLESv2.dll.lib" ) ,
new SystemLibrary ( "Opengl32.lib" ) ,
new SystemLibrary ( "User32.lib" ) ,
new SystemLibrary ( "Rpcrt4.lib" ) ,
} ;
} ) ;
np . SupportFiles . Add ( c = > IsWindows ( c ) , new [ ] {
new DeployableFile ( windowsSkiaBuild + "/libEGL.dll" ) ,
new DeployableFile ( windowsSkiaBuild + "/libEGL.dll.pdb" ) ,
new DeployableFile ( windowsSkiaBuild + "/libGLESv2.dll" ) ,
new DeployableFile ( windowsSkiaBuild + "/libGLESv2.dll.pdb" ) ,
}
) ;
np . Libraries . Add ( IsMac , c = >
{
return new PrecompiledLibrary [ ]
{
new StaticLibrary ( flutterRoot + "/out/host_debug_unopt/obj/flutter/third_party/txt/libtxt_lib.a" ) ,
new SystemFramework ( "Foundation" ) ,
new SystemFramework ( "ApplicationServices" ) ,
new SystemFramework ( "OpenGL" ) ,
new SystemFramework ( "AppKit" ) ,
new SystemFramework ( "CoreVideo" ) ,
} ;
} ) ;
}
static void SetupSkia ( NativeProgram np )
{
np . Defines . Add ( c = > IsWindows ( c ) , new [ ]
var ignoreWarnigs = new string [ ] { "4091" , "4722" , "4312" , "4838" , "4172" , "4005" , "4311" , "4477" } ; // todo comparing the list with engine
txtLib . CompilerSettings ( ) . Add ( s = > s . WithWarningPolicies ( ignoreWarnigs . Select ( ( code ) = > new WarningAndPolicy ( code , WarningPolicy . Silent ) ) . ToArray ( ) ) ) ;
txtLib . CompilerSettings ( ) . Add ( c = > IsMac ( c ) , c = > c . WithCppLanguageVersion ( CppLanguageVersion . Cpp17 ) ) ;
txtLib . CompilerSettings ( ) . Add ( c = > IsMac ( c ) , c = > c . WithCustomFlags ( new [ ] { "-Wno-c++11-narrowing" } ) ) ;
txtLib . CompilerSettings ( ) . Add ( c = > IsMac ( c ) , c = > c . WithCustomFlags ( new [ ] { "-Wno-c++11-narrowing" } ) ) ;
txtLib . Defines . Add ( c = > c . CodeGen = = CodeGen . Debug ,
new [ ] { "_ITERATOR_DEBUG_LEVEL=2" , "_HAS_ITERATOR_DEBUGGING=1" , "_SECURE_SCL=1" } ) ;