public static void SetupDotsRuntimeNativeProgram(string libname, NativeProgram np) { np.DynamicLinkerSettingsForMac().Add(c => c.WithInstallName(libname + ".dylib")); np.DynamicLinkerSettingsForIos() .Add(c => c.WithInstallName("@executable_path/Frameworks/" + libname + ".dylib")); np.IncludeDirectories.Add(BuildProgram.BeeRootValue.Combine("cppsupport/include")); //lets always add a dummy cpp file, in case this np is only used to carry other libraries np.Sources.Add(BuildProgram.BeeRootValue.Combine("cppsupport/dummy.cpp").ResolveWithFileSystem()); np.Defines.Add(c => c.Platform is WebGLPlatform, "UNITY_WEBGL=1"); np.Defines.Add(c => c.Platform is WindowsPlatform, "UNITY_WINDOWS=1"); np.Defines.Add(c => c.Platform is MacOSXPlatform, "UNITY_MACOSX=1"); np.Defines.Add(c => c.Platform is LinuxPlatform, "UNITY_LINUX=1"); np.Defines.Add(c => c.Platform is IosPlatform, "UNITY_IOS=1"); np.Defines.Add(c => c.Platform is AndroidPlatform, "UNITY_ANDROID=1"); np.Defines.Add(c => c.CodeGen == CodeGen.Debug, "DEBUG=1"); np.Defines.Add("BINDGEM_DOTS=1"); np.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging && ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.WaitForManagedDebugger, "UNITY_DOTSRUNTIME_IL2CPP_WAIT_FOR_MANAGED_DEBUGGER"); np.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableUnityCollectionsChecks, "ENABLE_UNITY_COLLECTIONS_CHECKS"); // Using ENABLE_PROFILER and not ENABLE_DOTSRUNTIME_PROFILER because native code doesn't call any DOTS Runtime specific API np.Defines.Add(c => (c as DotsRuntimeNativeProgramConfiguration)?.CSharpConfig.EnableProfiler == true, "ENABLE_PROFILER"); //we don't want to do this for c#, because then burst sees different code from the unbursted path and it's very //easy and tempting to go insane this way. but for native, it's fine, since burst //doesn't see that directly. and also, it enables us to error when we don't find the burst dll when burst is on, //and not look for it when it's off. np.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.UseBurst, "ENABLE_UNITY_BURST=1"); np.CompilerSettingsForEmscripten().Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); np.StaticLinkerSettings() .Add(c => c.ToolChain is EmscriptenToolchain && ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.EnableManagedDebugging, s => s.WithCustomFlags_workaround(new[] { "-s", "USE_PTHREADS=1" })); np.CompilerSettings().Add(c => c.WithWarningsAsErrors(ShouldEnableWarningsAsErrors(libname))); }
public BgfxBuild() { var rendererRoot = AsmDefConfigFile.AsmDefDescriptionFor("Unity.Tiny.Rendering.Native").Directory; bool useLocalBgfx = false; BgfxArtifact = new StevedoreArtifact("bgfx-source"); BgfxRoot = BgfxArtifact.Path.ResolveWithFileSystem(); //BgfxRoot = @"C:\Users\sebastianm\gits\bgfx-root"; //useLocalBgfx = true; var bx = BgfxRoot.Combine("bx"); var bgfx = BgfxRoot.Combine("bgfx"); var bimg = BgfxRoot.Combine("bimg"); // Note that these 3 NativePrograms are only linked in as BagOfObjects into the bgfx dll above. // They should not have Libraries themselves (e.g. bgfx should not reference the bx or bimg NativePrograms). // This means that PublicIncludes won't work, which is why Bimg and Bgfx explicitly add BxLib's PublicIncludes // to their own Includes. BxLib = new NativeProgram("bx") { Exceptions = { false }, RTTI = { false }, PublicIncludeDirectories = { bx.Combine("include"), bx.Combine("3rdparty"), }, Sources = { //bx.Combine("src").Files("*.cpp").Except(new[] {bx.Combine("src/amalgamated.cpp"), bx.Combine("src/crtnone.cpp")}) bx.Combine("src/amalgamated.cpp") }, Defines = { "__STDC_FORMAT_MACROS" }, }; BxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BxLib.Defines.Add(c => c.Platform is WindowsPlatform, "_CRT_SECURE_NO_WARNINGS"); BxLib.PublicIncludeDirectories.Add(c => c.ToolChain is WindowsToolchain, bx.Combine("include/compat/msvc")); BxLib.PublicIncludeDirectories.Add(c => c.Platform is MacOSXPlatform, bx.Combine("include/compat/osx")); BxLib.PublicIncludeDirectories.Add(c => c.Platform is IosPlatform, bx.Combine("include/compat/ios")); BxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); BimgLib = new NativeProgram("bimg") { Exceptions = { false }, RTTI = { false }, IncludeDirectories = { bimg.Combine("include"), bimg.Combine("3rdparty/astc-codec/include"), // comment out next line once BIMG_DECODE_ASTC lands in bimg bimg.Combine("3rdparty/astc-codec"), }, Sources = { bimg.Combine("src/image.cpp"), bimg.Combine("src/image_gnf.cpp"), // comment out next line once BIMG_DECODE_ASTC lands in bimg bimg.Combine("3rdparty/astc-codec/src/decoder").CombineMany(new [] { "astc_file.cc","codec.cc", "endpoint_codec.cc", "footprint.cc", "integer_sequence_codec.cc", "intermediate_astc_block.cc", "logical_astc_block.cc", "partition.cc", "physical_astc_block.cc", "quantization.cc", "weight_infill.cc" }) }, Defines = { "__STDC_FORMAT_MACROS", "BIMG_DECODE_ENABLE=0" }, }; BimgLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BimgLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BimgLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BimgLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c)); BimgLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); BgfxLib = new NativeProgram("bgfx") { Exceptions = { false }, RTTI = { false }, IncludeDirectories = { bimg.Combine("include"), bgfx.Combine("include"), bgfx.Combine("3rdparty"), bgfx.Combine("3rdparty/khronos"), rendererRoot.Combine("cpp~/include"), }, Defines = { "BGFX_SHARED_LIB_BUILD", "__STDC_FORMAT_MACROS" }, }; BgfxLib.CompilerSettings().Add(c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp14)); BgfxLib.CompilerSettingsForMac().Add(c => c.WithObjcArc(false)); BgfxLib.CompilerSettingsForIos().Add(c => c.WithObjcArc(false)); BgfxLib.IncludeDirectories.Add(c => BxLib.PublicIncludeDirectories.For(c)); BgfxLib.Defines.Add(c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.Defines.Contains("RENDERING_ENABLE_TRACE"), "BGFX_CONFIG_DEBUG=1"); BgfxLib.Defines.Add(c => c.ToolChain is WindowsToolchain, "_CRT_SECURE_NO_WARNINGS"); //BgfxLib.Defines.Add("BGFX_CONFIG_DEBUG_UNIFORM=0"); if (!useLocalBgfx) { // when using bgfx from stevedore, this requires pix3.h which we don't distribute BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0"); } else { BgfxLib.Defines.Add(c => c.Platform is WindowsPlatform, "BGFX_CONFIG_DEBUG_ANNOTATION=0"); ///BgfxLib.IncludeDirectories.Add(bgfx.Combine("3rdparty/dxsdk")); } BgfxLib.Defines.Add("BGFX_CONFIG_MAX_BONES=4"); BgfxLib.Defines.Add(c => (c as DotsRuntimeNativeProgramConfiguration)?.CSharpConfig.EnableProfiler == true, "BGFX_CONFIG_PROFILER=1"); // At some point we need to stop using amalgamated, especially for small-size web builds BgfxLib.Sources.Add(c => !(c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.cpp")); BgfxLib.Sources.Add(c => (c.Platform is MacOSXPlatform || c.Platform is IosPlatform), bgfx.Combine("src/amalgamated.mm")); // This is a hack that the Khronos eglplatform.h header understands in order to define the EGL types as intptr_t, // which is what emscripten wants. Otherwise we fall into a __unix__ path, which includes X11/Xlib.h, and // all hell breaks loose. BgfxLib.Defines.Add(c => c.Platform is WebGLPlatform, "USE_OZONE"); BgfxLib.CompilerSettingsForEmscripten().Add(Il2Cpp.ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); }
static NativeProgram CreateLibIl2CppProgram(bool useExceptions, NativeProgram boehmGcProgram = null, string libil2cppname = "libil2cpptiny") { var fileList = Distribution.GetFileList(libil2cppname).ToArray(); var nPaths = fileList.Where(f => f.HasExtension("cpp")).ToArray(); var win32Sources = nPaths.Where(p => p.HasDirectory("Win32")).ToArray(); var posixSources = nPaths.Where(p => p.HasDirectory("Posix")).ToArray(); nPaths = nPaths.Except(win32Sources).Except(posixSources).ToArray(); var program = new NativeProgram(libil2cppname) { Sources = { nPaths, { c => c.Platform.HasPosix,posixSources }, { c => c.Platform is WindowsPlatform,win32Sources } }, Exceptions = { useExceptions }, PublicIncludeDirectories = { Distribution.Path.Combine(libil2cppname), Distribution.Path.Combine("libil2cpp"), }, PublicDefines = { "NET_4_0", "GC_NOT_DLL", "RUNTIME_IL2CPP", "LIBIL2CPP_IS_IN_EXECUTABLE=1", { c => c.ToolChain is VisualStudioToolchain,"NOMINMAX", "WIN32_THREADS", "IL2CPP_TARGET_WINDOWS=1" }, { c => c.CodeGen == CodeGen.Debug,"DEBUG", "IL2CPP_DEBUG" } }, Libraries = { { c => c.Platform is WindowsPlatform, new[] { "user32.lib", "advapi32.lib", "ole32.lib", "oleaut32.lib", "Shell32.lib", "Crypt32.lib", "psapi.lib", "version.lib", "MsWSock.lib", "ws2_32.lib", "Iphlpapi.lib", "Dbghelp.lib" }.Select(s => new SystemLibrary(s)) }, { c => c.Platform is MacOSXPlatform, new PrecompiledLibrary[] { new SystemFramework("CoreFoundation") } }, { c => c.Platform is LinuxPlatform, new SystemLibrary("dl") }, { c => c.Platform is AndroidPlatform, new[] { new SystemLibrary("log") } } } }; program.Libraries.Add(BoehmGCProgram); program.RTTI.Set(c => useExceptions && c.ToolChain.EnablingExceptionsRequiresRTTI); if (libil2cppname == "libil2cpptiny") { program.Sources.Add(Distribution.GetFileList("libil2cpp/os")); program.Sources.Add(Distribution.GetFileList("libil2cpp/gc")); program.Sources.Add(Distribution.GetFileList("libil2cpp/utils")); program.Sources.Add(Distribution.GetFileList("libil2cpp/vm-utils")); program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp")); } else { program.Defines.Add(ManagedDebuggingIsEnabled, "IL2CPP_MONO_DEBUGGER=1", "PLATFORM_UNITY", "UNITY_USE_PLATFORM_STUBS", "ENABLE_OVERRIDABLE_ALLOCATORS", "IL2CPP_ON_MONO=1", "DISABLE_JIT=1", "DISABLE_REMOTING=1", "HAVE_CONFIG_H", "MONO_DLL_EXPORT=1"); program.Defines.Add(c => c.ToolChain.Platform is WebGLPlatform && ManagedDebuggingIsEnabled(c), "HOST_WASM=1"); program.IncludeDirectories.Add(ManagedDebuggingIsEnabled, new[] { Distribution.Path.Combine("external/mono/mono/eglib"), Distribution.Path.Combine("external/mono/mono"), Distribution.Path.Combine("external/mono/"), Distribution.Path.Combine("external/mono/mono/sgen"), Distribution.Path.Combine("external/mono/mono/utils"), Distribution.Path.Combine("external/mono/mono/metadata"), Distribution.Path.Combine("external/mono/metadata/private"), Distribution.Path.Combine("libmono/config"), Distribution.Path.Combine("libil2cpp/os/c-api") }); var MonoSourceDir = Distribution.Path.Combine("external/mono"); program.Sources.Add(ManagedDebuggingIsEnabled, new [] { "mono/eglib/garray.c", "mono/eglib/gbytearray.c", "mono/eglib/gdate-unity.c", "mono/eglib/gdir-unity.c", "mono/eglib/gerror.c", "mono/eglib/gfile-unity.c", "mono/eglib/gfile.c", "mono/eglib/ghashtable.c", "mono/eglib/giconv.c", "mono/eglib/glist.c", "mono/eglib/gmarkup.c", "mono/eglib/gmem.c", "mono/eglib/gmisc-unity.c", "mono/eglib/goutput.c", "mono/eglib/gpath.c", "mono/eglib/gpattern.c", "mono/eglib/gptrarray.c", "mono/eglib/gqsort.c", "mono/eglib/gqueue.c", "mono/eglib/gshell.c", "mono/eglib/gslist.c", "mono/eglib/gspawn.c", "mono/eglib/gstr.c", "mono/eglib/gstring.c", "mono/eglib/gunicode.c", "mono/eglib/gutf8.c", "mono/metadata/mono-hash.c", "mono/metadata/profiler.c", "mono/mini/debugger-agent.c", "mono/utils/atomic.c", "mono/utils/bsearch.c", "mono/utils/dlmalloc.c", "mono/utils/hazard-pointer.c", "mono/utils/json.c", "mono/utils/lock-free-alloc.c", "mono/utils/lock-free-array-queue.c", "mono/utils/lock-free-queue.c", "mono/utils/memfuncs.c", "mono/utils/mono-codeman.c", "mono/utils/mono-conc-hashtable.c", "mono/utils/mono-context.c", "mono/utils/mono-counters.c", "mono/utils/mono-dl.c", "mono/utils/mono-error.c", "mono/utils/mono-filemap.c", "mono/utils/mono-hwcap.c", "mono/utils/mono-internal-hash.c", "mono/utils/mono-io-portability.c", "mono/utils/mono-linked-list-set.c", "mono/utils/mono-log-common.c", "mono/utils/mono-logger.c", "mono/utils/mono-math.c", "mono/utils/mono-md5.c", "mono/utils/mono-mmap-windows.c", "mono/utils/mono-mmap.c", "mono/utils/mono-networkinterfaces.c", "mono/utils/mono-os-mutex.c", "mono/utils/mono-path.c", "mono/utils/mono-poll.c", "mono/utils/mono-proclib-windows.c", "mono/utils/mono-proclib.c", "mono/utils/mono-property-hash.c", "mono/utils/mono-publib.c", "mono/utils/mono-sha1.c", "mono/utils/mono-stdlib.c", "mono/utils/mono-threads-coop.c", "mono/utils/mono-threads-state-machine.c", "mono/utils/mono-threads.c", "mono/utils/mono-tls.c", "mono/utils/mono-uri.c", "mono/utils/mono-value-hash.c", "mono/utils/monobitset.c", "mono/utils/networking-missing.c", "mono/utils/networking.c", "mono/utils/parse.c", "mono/utils/strenc.c", "mono/utils/unity-rand.c", "mono/utils/unity-time.c", "mono/utils/mono-dl-unity.c", "mono/utils/mono-log-unity.c", "mono/utils/mono-threads-unity.c", "mono/utils/networking-unity.c", "mono/utils/os-event-unity.c", "mono/metadata/console-unity.c", "mono/metadata/file-mmap-unity.c", "mono/metadata/w32error-unity.c", "mono/metadata/w32event-unity.c", "mono/metadata/w32file-unity.c", "mono/metadata/w32mutex-unity.c", "mono/metadata/w32process-unity.c", "mono/metadata/w32semaphore-unity.c", "mono/metadata/w32socket-unity.c" }.Select(path => MonoSourceDir.Combine(path))); program.Sources.Add(c => c.ToolChain.Platform is WindowsPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/eglib/gunicode-win32.c")); program.Sources.Add(c => c.ToolChain.Platform is WindowsPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-os-wait-win32.c")); program.Sources.Add(c => c.ToolChain.Platform is WebGLPlatform && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-web.c")); program.Sources.Add(c => c.ToolChain.Architecture is IntelArchitecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-x86.c")); program.Sources.Add(c => c.ToolChain.Architecture is ARMv7Architecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-arm.c")); program.Sources.Add(c => c.ToolChain.Architecture is Arm64Architecture && ManagedDebuggingIsEnabled(c), MonoSourceDir.Combine("mono/utils/mono-hwcap-arm64.c")); program.IncludeDirectories.Add(ManagedDebuggingIsEnabled, Distribution.Path.Combine("libil2cpp/debugger")); } program.PublicDefines.Add("IL2CPP_TINY"); program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external").Combine("xxHash")); program.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11)); // Use Baselib headers and library code from the NativeJobs library. CustomizerForZeroJobs.NativeJobsPrebuiltLibrary.Add(program); //program.CompilerSettingsForMsvc().Add(l => l.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.None)); return(program); }
private NativeProgram NativeProgramForIL2CPPOutput(string nativeProgramName, NPath[] il2cppOutputFiles, IL2CPPPlatformBeeSupport platformSupport, bool managedDebuggingEnabled = true, bool libil2cpptiny = false) { var il2cppPlayerPackageDirectory = _incrementalClassicSharedData.PlayerPackageDirectory.Combine("il2cpp"); var nativeProgram = new NativeProgram(nativeProgramName) { Sources = { il2cppOutputFiles }, Exceptions = { true }, IncludeDirectories = { il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpp/include") : Distribution.Path.Combine("libil2cpp"), il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("external/baselib/include") : Distribution.Path.Combine("external/baselib/include"), c => il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include") : Distribution.Path.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include") }, Defines = { "BASELIB_INLINE_NAMESPACE=il2cpp_baselib", "RUNTIME_IL2CPP=1" } }; nativeProgram.Libraries.Add(c => CreateLibIl2CppProgram(!libil2cpptiny, platformSupport, managedDebuggingEnabled, libil2cpptiny ? "libil2cpptiny" : "libil2cpp")); nativeProgram.Libraries.Add(c => c.ToolChain.Platform is WindowsPlatform && _incrementalClassicSharedData.VariationDirectory.Combine("baselib.dll.lib").Exists(), new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("baselib.dll.lib"))); nativeProgram.Libraries.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture && _incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/arm64-v8a/baselib.a").Exists(), new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/arm64-v8a/baselib.a"))); nativeProgram.Libraries.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is ARMv7Architecture && _incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/armeabi-v7a/baselib.a").Exists(), new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("StaticLibs/armeabi-v7a/baselib.a"))); nativeProgram.Libraries.Add(c => c.ToolChain.Platform is MacOSXPlatform && _incrementalClassicSharedData.VariationDirectory.Combine("baselib.a").Exists(), new StaticLibrary(_incrementalClassicSharedData.VariationDirectory.Combine("baselib.a"))); nativeProgram.Libraries.Add(c => c.ToolChain.Platform is IosPlatform && _incrementalClassicSharedData.PlayerPackageDirectory.Combine("Trampoline/Libraries/baselib-dev.a").Exists(), new StaticLibrary(_incrementalClassicSharedData.PlayerPackageDirectory.Combine("Trampoline", "Libraries", "baselib-dev.a"))); if (il2cppPlayerPackageDirectory.Combine("libil2cpp/include/pch").Exists() || Distribution.Path.Combine("libil2cpp/pch").Exists()) { var libil2cppDir = il2cppPlayerPackageDirectory.Combine("libil2cpp/include").Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpp/include") : Distribution.Path.Combine("libil2cpp"); var libil2cpptinyDir = il2cppPlayerPackageDirectory.Combine("libil2cpptiny/include").Exists() ? il2cppPlayerPackageDirectory.Combine("libil2cpptiny/include") : Distribution.Path.Combine("libil2cpptiny"); if (libil2cpptiny) { nativeProgram.Defines.Add("IL2CPP_TINY"); if (managedDebuggingEnabled) { nativeProgram.IncludeDirectories.Add(libil2cppDir.Combine("pch")); nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-cpp.hpp"), nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp"))); nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-c.h"), nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".c"))); } else { // Tiny needs to be able to find its include directory before libil2cpp nativeProgram.IncludeDirectories.AddFront(libil2cpptinyDir); nativeProgram.IncludeDirectories.AddFront(libil2cpptinyDir.Combine("pch")); nativeProgram.PerFilePchs.Add(libil2cpptinyDir.Combine("pch/pch-cpp.hpp"), nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp"))); } } else { nativeProgram.IncludeDirectories.Add(libil2cppDir.Combine("pch")); nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-cpp.hpp"), nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".cpp"))); nativeProgram.PerFilePchs.Add(libil2cppDir.Combine("pch/pch-c.h"), nativeProgram.Sources.ForAny().Where(f => f.HasExtension(".c"))); } } nativeProgram.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11)); nativeProgram.CompilerSettingsForMsvc() .Add(c => c.WithCustomFlags(new[] { "/EHs" })); nativeProgram.CompilerSettingsForMsvc() .Add(c => c.WithWarningPolicies(new[] { new WarningAndPolicy("4102", WarningPolicy.Silent) })); // nativeProgram.CompilerSettingsForMsvc() // .Add(c => c.WithPDB(_incrementalClassicSharedData.BeeProjectRoot.Combine("libil2cpp.pdb"))); nativeProgram.CompilerSettingsForClang().Add(c => c.WithWarningPolicies(new[] { new WarningAndPolicy("pragma-once-outside-header", WarningPolicy.Silent) })); if (platformSupport != null) { platformSupport.ProvideNativeProgramSettings(nativeProgram); } nativeProgram.NonLumpableFiles.Add(nativeProgram.Sources.ForAny()); return(nativeProgram); }
private NativeProgramAsLibrary CreateLibIl2CppProgram(bool useExceptions, IL2CPPPlatformBeeSupport platformSupport, bool managedDebuggingEnabled = true, string libil2cppname = "libil2cpp") { NPath[] fileList; if (libil2cppname == "libil2cpptiny" && managedDebuggingEnabled) { fileList = Distribution.GetFileList("libil2cpp").ToArray(); } else { fileList = Distribution.GetFileList(libil2cppname).ToArray(); } var nPaths = fileList.Where(f => f.Parent.FileName != "pch" && f.HasExtension("cpp")).ToArray(); var il2cppPlayerPackageDirectory = _incrementalClassicSharedData.PlayerPackageDirectory.Combine("il2cpp"); var program = new NativeProgram(libil2cppname) { Sources = { nPaths }, Exceptions = { useExceptions }, PublicIncludeDirectories = { Distribution.Path.Combine("libil2cpp") }, IncludeDirectories = { il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine("external/baselib/include") : Distribution.Path.Combine("external/baselib/include"), c => il2cppPlayerPackageDirectory.Exists() ? il2cppPlayerPackageDirectory.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include") : Distribution.Path.Combine($"external/baselib/Platforms/{c.Platform.Name}/Include"), Distribution.Path.Combine("external/mono/mono/eglib"), Distribution.Path.Combine("external/mono/mono"), Distribution.Path.Combine("external/mono/"), Distribution.Path.Combine("external/mono/mono/sgen"), Distribution.Path.Combine("external/mono/mono/utils"), Distribution.Path.Combine("external/mono/mono/metadata"), Distribution.Path.Combine("external/mono/mono/metadata/private"), Distribution.Path.Combine("libmono/config"), Distribution.Path.Combine("libil2cpp/os/c-api"), Distribution.Path.Combine("libil2cpp/debugger") }, PublicDefines = { "NET_4_0", "GC_NOT_DLL", "RUNTIME_IL2CPP", "LIBIL2CPP_IS_IN_EXECUTABLE=0", { c => c.ToolChain is VisualStudioToolchain,"NOMINMAX", "WIN32_THREADS", "IL2CPP_TARGET_WINDOWS=1" }, { c => c.CodeGen == CodeGen.Debug,"DEBUG", "IL2CPP_DEBUG=1" }, { c => !(c.Platform is WebGLPlatform),"GC_THREADS=1", "USE_MMAP=1", "USE_MUNMAP=1" }, }, Defines = { "BASELIB_INLINE_NAMESPACE=il2cpp_baselib" }, Libraries = { { c => c.Platform is WindowsPlatform, new[] { "user32.lib", "advapi32.lib", "ole32.lib", "oleaut32.lib", "Shell32.lib", "Crypt32.lib", "psapi.lib", "version.lib", "MsWSock.lib", "ws2_32.lib", "Iphlpapi.lib", "Dbghelp.lib" }.Select(s => new SystemLibrary(s)) }, { c => c.Platform is MacOSXPlatform || c.Platform is IosPlatform, new ILibrary[] { new SystemFramework("CoreFoundation") } }, { c => c.Platform is LinuxPlatform, new SystemLibrary("dl") }, { c => c.Platform is AndroidPlatform, new ILibrary[] { new SystemLibrary("log") } }, } }; program.RTTI.Set(c => useExceptions && c.ToolChain.EnablingExceptionsRequiresRTTI); if (libil2cppname == "libil2cpptiny") { program.Defines.Add("IL2CPP_TINY"); if (!managedDebuggingEnabled) { // Tiny needs to be able to find its include directory before libil2cpp program.IncludeDirectories.AddFront(Distribution.Path.Combine("libil2cpptiny")); program.Sources.Add(Distribution.GetFileList("libil2cpp/os")); program.Sources.Add(Distribution.GetFileList("libil2cpp/gc")); program.Sources.Add(Distribution.GetFileList("libil2cpp/utils")); program.Sources.Add(Distribution.GetFileList("libil2cpp/vm-utils")); } } if (managedDebuggingEnabled) { program.Defines.Add("IL2CPP_MONO_DEBUGGER=1", "IL2CPP_DEBUGGER_PORT=56000", "PLATFORM_UNITY", "UNITY_USE_PLATFORM_STUBS", "ENABLE_OVERRIDABLE_ALLOCATORS", "IL2CPP_ON_MONO=1", "DISABLE_JIT=1", "DISABLE_REMOTING=1", "HAVE_CONFIG_H", "MONO_DLL_EXPORT=1"); program.Defines.Add(c => c.ToolChain.Platform is WebGLPlatform, "HOST_WASM=1"); program.CompilerSettingsForMsvc().Add(c => c.WithCustomFlags(new[] { "/EHcs" })); program.CompilerSettingsForClang().Add(c => c.WithRTTI(true)); program.CompilerSettingsForClang().Add(c => c.WithExceptions(true)); } else { program.Defines.Add("IL2CPP_MONO_DEBUGGER_DISABLED"); } program.PublicDefines.Add(c => c.ToolChain.Platform is AndroidPlatform, "LINUX", "ANDROID", "PLATFORM_ANDROID", "__linux__", "__STDC_FORMAT_MACROS" ); program.PublicDefines.Add(c => c.ToolChain.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture, "TARGET_ARM64"); var MonoSourceDir = Distribution.Path.Combine("external/mono"); program.Sources.Add(c => MonoSourcesFor(c, MonoSourceDir, managedDebuggingEnabled)); program.NonLumpableFiles.Add(c => MonoSourcesFor(c, MonoSourceDir, managedDebuggingEnabled)); if (libil2cppname != "libil2cpptiny") { program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external/zlib")); var zlibSources = Distribution.GetFileList("external/zlib").Where(f => f.Extension.Equals("c")).ToArray(); program.NonLumpableFiles.Add(zlibSources); program.Sources.Add(zlibSources); } else { program.PublicIncludeDirectories.Add(Distribution.Path.Combine("external/xxHash")); program.Sources.Add(Distribution.Path.Combine("external/xxHash/xxhash.c")); } var boehmGcRoot = Distribution.Path.Combine("external/bdwgc"); program.Sources.Add(boehmGcRoot.Combine("extra/gc.c")); program.PublicIncludeDirectories.Add(boehmGcRoot.Combine("include")); program.IncludeDirectories.Add(boehmGcRoot.Combine("libatomic_ops/src")); program.Defines.Add( "ALL_INTERIOR_POINTERS=1", "GC_GCJ_SUPPORT=1", "JAVA_FINALIZATION=1", "NO_EXECUTE_PERMISSION=1", "GC_NO_THREADS_DISCOVERY=1", "IGNORE_DYNAMIC_LOADING=1", "GC_DONT_REGISTER_MAIN_STATIC_DATA=1", "NO_DEBUGGING=1", "GC_VERSION_MAJOR=7", "GC_VERSION_MINOR=7", "GC_VERSION_MICRO=0", "HAVE_BDWGC_GC", "HAVE_BOEHM_GC", "DEFAULT_GC_NAME=\"BDWGC\"", "NO_CRT=1", "DONT_USE_ATEXIT=1", "NO_GETENV=1"); program.Defines.Add(c => !(c.Platform is WebGLPlatform), "GC_THREADS=1", "USE_MMAP=1", "USE_MUNMAP=1"); program.Defines.Add(c => c.ToolChain is VisualStudioToolchain, "NOMINMAX", "WIN32_THREADS"); program.CompilerSettings().Add(s => s.WithCppLanguageVersion(CppLanguageVersion.Cpp11)); if (platformSupport != null) { platformSupport.ProvideLibIl2CppProgramSettings(program); } return(program); }