mirror of
https://github.com/Relintai/godot-mono-builds.git
synced 2024-11-12 10:25:10 +01:00
Add custom AndroidEnvironment class for Godot
The monodroid BCL expects to find this class in 'Mono.Android.dll'. We're not using Xamarin.Android (at least not for now) so we need a replacement.
This commit is contained in:
parent
bd129da22b
commit
ee54822600
17
bcl.py
17
bcl.py
@ -115,6 +115,23 @@ def make_product(opts: BclOpts, product: str):
|
||||
for profile in profiles:
|
||||
[rm_rf(x) for x in glob.iglob(hidden_file_pattern, recursive=True)]
|
||||
|
||||
if product == 'android':
|
||||
this_script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
monodroid_profile_dir = '%s/%s' % (install_dir, 'monodroid')
|
||||
godot_profile_dir = '%s/%s' % (install_dir, 'godot_android_ext')
|
||||
refs = ['mscorlib.dll', 'System.Core.dll', 'System.dll']
|
||||
|
||||
mkdir_p(godot_profile_dir)
|
||||
|
||||
android_env_csc_args = [
|
||||
path_join(this_script_dir, 'files', 'godot-AndroidEnvironment.cs'),
|
||||
'-target:library', '-out:%s' % path_join(godot_profile_dir, 'Mono.Android.dll'),
|
||||
'-nostdlib', '-noconfig', '-langversion:latest'
|
||||
]
|
||||
android_env_csc_args += ['-r:%s' % path_join(monodroid_profile_dir, r) for r in refs]
|
||||
|
||||
run_command('csc', android_env_csc_args)
|
||||
|
||||
|
||||
def clean_product(opts: BclOpts, product: str):
|
||||
clean_bcl(opts)
|
||||
|
111
files/godot-AndroidEnvironment.cs
Normal file
111
files/godot-AndroidEnvironment.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
// See 'mono/sdks/android/managed/fake-monodroid.cs' and 'xamarin-android/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs'
|
||||
|
||||
namespace Android.Runtime
|
||||
{
|
||||
public static class AndroidEnvironment
|
||||
{
|
||||
public const string AndroidLogAppName = "Mono.Android";
|
||||
|
||||
static object lock_ = new object();
|
||||
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
internal extern static void monodroid_free(IntPtr ptr);
|
||||
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern IntPtr _monodroid_timezone_get_default_id();
|
||||
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern int _monodroid_getifaddrs(out IntPtr ifap);
|
||||
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
static extern void _monodroid_freeifaddrs(IntPtr ifap);
|
||||
|
||||
static string GetDefaultTimeZone()
|
||||
{
|
||||
IntPtr id = _monodroid_timezone_get_default_id();
|
||||
|
||||
try
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(id);
|
||||
}
|
||||
finally
|
||||
{
|
||||
monodroid_free(id);
|
||||
}
|
||||
}
|
||||
|
||||
static SynchronizationContext GetDefaultSyncContext()
|
||||
{
|
||||
// Not needed
|
||||
return null;
|
||||
}
|
||||
|
||||
static IWebProxy GetDefaultProxy()
|
||||
{
|
||||
// Not needed
|
||||
return null;
|
||||
}
|
||||
|
||||
static int GetInterfaceAddresses(out IntPtr ifap)
|
||||
{
|
||||
return _monodroid_getifaddrs(out ifap);
|
||||
}
|
||||
|
||||
static void FreeInterfaceAddresses(IntPtr ifap)
|
||||
{
|
||||
_monodroid_freeifaddrs(ifap);
|
||||
}
|
||||
|
||||
static void DetectCPUAndArchitecture(out ushort builtForCPU, out ushort runningOnCPU, out bool is64bit)
|
||||
{
|
||||
// Not needed (For now? The BCL code that uses the result is commented...)
|
||||
builtForCPU = 0;
|
||||
runningOnCPU = 0;
|
||||
is64bit = Environment.Is64BitProcess;
|
||||
}
|
||||
|
||||
static bool TrustEvaluateSsl(List<byte[]> certsRawData)
|
||||
{
|
||||
// This is legacy. Not needed as BTLS is used by default instead.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
static extern bool _gd_mono_init_cert_store();
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
static extern byte[] _gd_mono_android_cert_store_lookup(string alias);
|
||||
|
||||
static bool certStoreInitOk = false;
|
||||
|
||||
static void InitCertStore()
|
||||
{
|
||||
if (certStoreInitOk)
|
||||
return;
|
||||
|
||||
lock (lock_)
|
||||
{
|
||||
certStoreInitOk = _gd_mono_init_cert_store();
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] CertStoreLookup(long hash, bool userStore)
|
||||
{
|
||||
InitCertStore();
|
||||
|
||||
if (!certStoreInitOk)
|
||||
return null;
|
||||
|
||||
string alias = string.Format("{0}:{1:x8}.0", userStore ? "user" : "system", hash);
|
||||
|
||||
return _gd_mono_android_cert_store_lookup(alias);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ def main(raw_args):
|
||||
args = parser.parse_args(raw_args)
|
||||
|
||||
this_script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
patches_dir = os.path.join(this_script_dir, 'patches')
|
||||
patches_dir = os.path.join(this_script_dir, 'files', 'patches')
|
||||
|
||||
mono_source_root = args.mono_sources
|
||||
|
||||
|
47
wasm.py
47
wasm.py
@ -67,8 +67,8 @@ def setup_wasm_target_template(env: dict, opts: RuntimeOpts, target: str):
|
||||
CONFIGURE_FLAGS += [
|
||||
'--cache-file=%s/wasm-%s-%s.config.cache' % (opts.configure_dir, target, opts.configuration),
|
||||
'--prefix=%s/wasm-%s-%s' % (opts.install_dir, target, opts.configuration),
|
||||
'CFLAGS=%s %s' % (' '.join(CFLAGS), env.get('wasm_%s_CFLAGS' % target, '')),
|
||||
'CXXFLAGS=%s %s' % (' '.join(CXXFLAGS), env.get('$$(wasm_%s_CXXFLAGS' % target, ''))
|
||||
'CFLAGS=%s %s' % (' '.join(CFLAGS), ' '.join(env.get('wasm_%s_CFLAGS' % target, ''))),
|
||||
'CXXFLAGS=%s %s' % (' '.join(CXXFLAGS), ' '.join(env.get('wasm_%s_CXXFLAGS' % target, '')))
|
||||
]
|
||||
|
||||
CONFIGURE_FLAGS += env.get('wasm_%s_CONFIGURE_FLAGS' % target, [])
|
||||
@ -167,6 +167,7 @@ def make(opts: RuntimeOpts, product: str, target: str):
|
||||
wasm_src_files = [
|
||||
'driver.c',
|
||||
'corebindings.c',
|
||||
'zlib-helper.c',
|
||||
'pinvoke-tables-default.h',
|
||||
'library_mono.js',
|
||||
'binding_support.js',
|
||||
@ -177,39 +178,25 @@ def make(opts: RuntimeOpts, product: str, target: str):
|
||||
|
||||
mkdir_p(dst_wasm_src_dir)
|
||||
|
||||
src_wasm_src_dir = None
|
||||
src_wasm_src_dir_hints = ['%s/sdks/wasm/src' % opts.mono_source_root, '%s/sdks/wasm/support' % opts.mono_source_root, '%s/sdks/wasm' % opts.mono_source_root]
|
||||
src_dir_hints = [
|
||||
'%s/sdks/wasm/src' % opts.mono_source_root,
|
||||
'%s/sdks/wasm/support' % opts.mono_source_root,
|
||||
'%s/sdks/wasm' % opts.mono_source_root
|
||||
]
|
||||
|
||||
for src_wasm_src_dir_hint in src_wasm_src_dir_hints:
|
||||
if os.path.isfile(path_join(src_wasm_src_dir_hint, 'driver.c')):
|
||||
src_wasm_src_dir = src_wasm_src_dir_hint
|
||||
break
|
||||
|
||||
if src_wasm_src_dir is None:
|
||||
raise BuildError('Cannot find \'driver.c\' in the Mono source tree. Tried with the following locations: ' + str(src_wasm_src_dir_hints))
|
||||
def dir_with_file(dirs, file):
|
||||
return (d for d in dirs if os.path.isfile(path_join(d, file)))
|
||||
|
||||
for wasm_src_file in wasm_src_files:
|
||||
copy(path_join(src_wasm_src_dir, wasm_src_file), dst_wasm_src_dir)
|
||||
src_dir = next(dir_with_file(src_dir_hints, wasm_src_file), '')
|
||||
if not src_dir:
|
||||
raise BuildError('File \'%s\' not found. Probed locations: %s' % (wasm_src_file, str(src_dir_hints)))
|
||||
copy(path_join(src_dir, wasm_src_file), dst_wasm_src_dir)
|
||||
|
||||
# Older versions didn't have .NET Core support
|
||||
if os.path.isfile(path_join(src_wasm_src_dir, 'pinvoke-tables-default-netcore.h')):
|
||||
copy(path_join(src_wasm_src_dir, 'pinvoke-tables-default-netcore.h'), dst_wasm_src_dir)
|
||||
|
||||
# Older versions had zlib-helper.c in different locations
|
||||
zlib_helper_name = 'zlib-helper.c'
|
||||
zlib_helper_dir = None
|
||||
|
||||
zlib_helper_dir_hints = src_wasm_src_dir_hints + ['%s/support' % opts.mono_source_root]
|
||||
|
||||
for zlib_helper_dir_hint in zlib_helper_dir_hints:
|
||||
if os.path.isfile(path_join(zlib_helper_dir_hint, zlib_helper_name)):
|
||||
zlib_helper_dir = zlib_helper_dir_hint
|
||||
break
|
||||
|
||||
if zlib_helper_dir is None:
|
||||
raise BuildError('Cannot find \'%s\' in the Mono source tree. Tried with the following locations: %s' % (zlib_helper_name, str(zlib_helper_dir_hints)))
|
||||
|
||||
copy(path_join(zlib_helper_dir, zlib_helper_name), dst_wasm_src_dir)
|
||||
src_dir = next(dir_with_file(src_dir_hints, 'pinvoke-tables-default-netcore.h'), '')
|
||||
if src_dir:
|
||||
copy(path_join(src_dir, 'pinvoke-tables-default-netcore.h'), dst_wasm_src_dir)
|
||||
|
||||
|
||||
def clean(opts: RuntimeOpts, product: str, target: str):
|
||||
|
Loading…
Reference in New Issue
Block a user