Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions modules/mono/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.cpp")
if env["platform"] in ["macos", "ios"]:
env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.mm")
env_mono.add_source_files(env.modules_sources, "mono_gd/support/*.m")
elif env["platform"] == "android":
env_mono.add_source_files(env.modules_sources, "mono_gd/android_mono_config.gen.cpp")

if env.editor_build:
env_mono.add_source_files(env.modules_sources, "editor/*.cpp")
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prior to .NET Core, we supported these: ["windows", "macos", "linuxbsd", "android", "haiku", "web", "ios"]
# Eventually support for each them should be added back (except Haiku if not supported by .NET Core)
supported_platforms = ["windows", "macos", "linuxbsd"]
supported_platforms = ["windows", "macos", "linuxbsd", "android"]


def can_build(env, platform):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using GodotTools.Build;
using GodotTools.Core;
using GodotTools.Internals;
Expand Down Expand Up @@ -45,6 +47,17 @@ public partial class ExportPlugin : EditorExportPlugin
}
},
{ "default_value", true }
},
new Godot.Collections.Dictionary()
{
{
"option", new Godot.Collections.Dictionary()
{
{ "name", "dotnet/embed_build_outputs" },
{ "type", (int)Variant.Type.Bool }
}
},
{ "default_value", false }
}
};
}
Expand Down Expand Up @@ -114,7 +127,7 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
if (!DeterminePlatformFromFeatures(features, out string platform))
throw new NotSupportedException("Target platform not supported.");

if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS }
if (!new[] { OS.Platforms.Windows, OS.Platforms.LinuxBSD, OS.Platforms.MacOS, OS.Platforms.Android }
.Contains(platform))
{
throw new NotImplementedException("Target platform not yet implemented.");
Expand All @@ -129,15 +142,19 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
{
archs.Add("x86_64");
}
else if (features.Contains("x86_32"))
if (features.Contains("x86_32"))
Comment thread
raulsntos marked this conversation as resolved.
Outdated
{
archs.Add("x86_32");
}
else if (features.Contains("arm64"))
if (features.Contains("arm64"))
{
archs.Add("arm64");
}
else if (features.Contains("universal"))
if (features.Contains("arm32"))
{
archs.Add("arm32");
}
if (features.Contains("universal"))
{
if (platform == OS.Platforms.MacOS)
{
Expand All @@ -146,6 +163,8 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
}
}

bool embedBuildResults = (bool)GetOption("dotnet/embed_build_outputs") || features.Contains("android");

foreach (var arch in archs)
{
string ridOS = DetermineRuntimeIdentifierOS(platform);
Expand Down Expand Up @@ -190,17 +209,44 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
"Publish succeeded but project assembly not found in the output directory");
}

// Add to the exported project shared object list.
var manifest = new StringBuilder();

// Add to the exported project shared object list or packed resources.
foreach (string file in Directory.GetFiles(publishOutputTempDir, "*", SearchOption.AllDirectories))
{
AddSharedObject(file, tags: null,
Path.Join(projectDataDirName,
Path.GetRelativePath(publishOutputTempDir, Path.GetDirectoryName(file))));
if (embedBuildResults)
{
var filePath = SanitizeSlashes(Path.GetRelativePath(publishOutputTempDir, file));
Comment thread
raulsntos marked this conversation as resolved.
Outdated
var fileData = File.ReadAllBytes(file);
var hash = Convert.ToBase64String(SHA512.HashData(fileData));

manifest.Append($"{filePath}\t{hash}\n");

AddFile($"res://.godot/mono/publish/{arch}/{filePath}", fileData, false);
}
else
{
AddSharedObject(file, tags: null,
Path.Join(projectDataDirName,
Path.GetRelativePath(publishOutputTempDir, Path.GetDirectoryName(file))));
}
}

if (embedBuildResults)
{
var fileData = Encoding.Default.GetBytes(manifest.ToString());
AddFile($"res://.godot/mono/publish/{arch}/.dotnet-publish-manifest", fileData, false);
}
}
}

private string SanitizeSlashes(string path)
{
if (Path.DirectorySeparatorChar == '\\')
return path.Replace('\\', '/');
return path;
}

private string DetermineRuntimeIdentifierOS(string platform)
=> OS.DotNetOSPlatformMap[platform];

Expand All @@ -214,7 +260,7 @@ private string DetermineRuntimeIdentifierArch(string arch)
"x86_64" => "x64",
"armeabi-v7a" => "arm",
"arm64-v8a" => "arm64",
"armv7" => "arm",
"arm32" => "arm",
Comment thread
raulsntos marked this conversation as resolved.
Outdated
"arm64" => "arm64",
_ => throw new ArgumentOutOfRangeException(nameof(arch), arch, "Unexpected architecture")
};
Expand Down
55 changes: 44 additions & 11 deletions modules/mono/godotsharp_dirs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,52 @@ class _GodotSharpDirs {
#else // TOOLS_ENABLED
String arch = Engine::get_singleton()->get_architecture_name();
String appname_safe = path::get_csharp_project_name();
String data_dir_root = exe_dir.path_join("data_" + appname_safe + "_" + arch);
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = exe_dir.path_join("data_Godot_" + arch);
}
String packed_path = "res://.godot/mono/publish/" + arch;
if (DirAccess::exists(packed_path)) {
// The dotnet publish data is packed in the pck/zip.
Comment thread
raulsntos marked this conversation as resolved.
Outdated
String data_dir_root = OS::get_singleton()->get_cache_path().path_join("data_" + appname_safe + "_" + arch);
bool has_data = false;
if (!has_data) {
// 1. Try to access the data directly.
String global_packed = ProjectSettings::get_singleton()->globalize_path(packed_path);
if (global_packed.is_absolute_path() && FileAccess::exists(global_packed.path_join(".dotnet-publish-manifest"))) {
data_dir_root = global_packed;
has_data = true;
}
}
if (!has_data) {
// 2. Check if the data was extracted before and is up-to-date.
String packed_manifest = packed_path.path_join(".dotnet-publish-manifest");
String extracted_manifest = data_dir_root.path_join(".dotnet-publish-manifest");
if (FileAccess::exists(packed_manifest) && FileAccess::exists(extracted_manifest)) {
if (FileAccess::get_file_as_bytes(packed_manifest) == FileAccess::get_file_as_bytes(extracted_manifest)) {
has_data = true;
}
}
}
if (!has_data) {
// 3. Extract the data to a temporary location to load from there.
Ref<DirAccess> da = DirAccess::create_for_path(packed_path);
ERR_FAIL_NULL(da);
ERR_FAIL_COND(da->copy_dir(packed_path, data_dir_root) != OK);
}
api_assemblies_dir = data_dir_root;
} else {
// The dotnet publish data is in a directory next to the executable.
String data_dir_root = exe_dir.path_join("data_" + appname_safe + "_" + arch);
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = exe_dir.path_join("data_Godot_" + arch);
}
#ifdef MACOS_ENABLED
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = res_dir.path_join("data_" + appname_safe + "_" + arch);
}
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = res_dir.path_join("data_Godot_" + arch);
}
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = res_dir.path_join("data_" + appname_safe + "_" + arch);
}
if (!DirAccess::exists(data_dir_root)) {
data_dir_root = res_dir.path_join("data_Godot_" + arch);
}
#endif
api_assemblies_dir = data_dir_root;
api_assemblies_dir = data_dir_root;
}
#endif
}

Expand Down
43 changes: 0 additions & 43 deletions modules/mono/mono_gd/android_mono_config.h

This file was deleted.

8 changes: 1 addition & 7 deletions modules/mono/mono_gd/gd_mono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@

// TODO mobile
#if 0
#ifdef ANDROID_ENABLED
#include "support/android_support.h"
#elif defined(IOS_ENABLED)
#ifdef IOS_ENABLED
#include "support/ios_support.h"
#endif
#endif
Expand Down Expand Up @@ -554,10 +552,6 @@ GDMono::~GDMono() {
finalizing_scripts_domain = false;
runtime_initialized = false;

#if defined(ANDROID_ENABLED)
gdmono::android::support::cleanup();
#endif

singleton = nullptr;
}

Expand Down
Loading