static NativeProgram CreateLibIl2CppProgram(bool useExceptions, NativeProgram boehmGcProgram = null, string libil2cppname = "libil2cpptiny") { var fileList = Distribution.GetFileList(libil2cppname).ResolveWithFileSystem().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" }, { c => ((DotsRuntimeNativeProgramConfiguration)c).CSharpConfig.DotsConfiguration != DotsConfiguration.Release,"IL2CPP_TINY_DEBUG_METADATA" }, }, 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") } } }, Defines = { { c => c.Platform is AndroidPlatform && c.ToolChain.Architecture is Arm64Architecture && ManagedDebuggingIsEnabled(c), "TARGET_ARM64" }, } }; program.Libraries.Add(BoehmGCProgram); program.RTTI.Set(c => useExceptions && c.ToolChain.EnablingExceptionsRequiresRTTI); if (libil2cppname == "libil2cpptiny") { program.Sources.Add(Distribution.GetFileList("libil2cpp/os").ResolveWithFileSystem()); program.Sources.Add(Distribution.GetFileList("libil2cpp/gc").ResolveWithFileSystem()); program.Sources.Add(Distribution.GetFileList("libil2cpp/utils").ResolveWithFileSystem()); program.Sources.Add(Distribution.GetFileList("libil2cpp/vm-utils").ResolveWithFileSystem()); program.Sources.Add(Distribution.GetFileList("libil2cpp/codegen").ResolveWithFileSystem()); program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp")); program.PublicIncludeDirectories.Add(Distribution.Path.Combine("libil2cpp", "pch")); } 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.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"), Distribution.Path.Combine("libil2cpp/pch"), }.ResolveWithFileSystem()); var MonoSourceDir = Distribution.Path.Combine("external/mono").ResolveWithFileSystem(); 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)); program.CompilerSettingsForGcc().Add(s => s.WithWarningPolicies(GetGccLikeWarningPolicies())); // Use Baselib headers and library code from the NativeJobs library. NativeJobsPrebuiltLibrary.AddToNativeProgram(program); //program.CompilerSettingsForMsvc().Add(l => l.WithCompilerRuntimeLibrary(CompilerRuntimeLibrary.None)); program.CompilerSettingsForEmscripten().Add(ManagedDebuggingIsEnabled, c => c.WithMultithreading_Compiler(EmscriptenMultithreadingMode.Enabled)); program.StaticLinkerSettings().Add(c => c.ToolChain is EmscriptenToolchain && ManagedDebuggingIsEnabled(c), s => s.WithCustomFlags_workaround(new[] { "-s", "USE_PTHREADS=1" })); return(program); }