Skip to content

Commit

Permalink
C#: Use Godot's LipO implementation instead of Xcode's lipo command
Browse files Browse the repository at this point in the history
  • Loading branch information
raulsntos committed Jun 16, 2024
1 parent 71699e0 commit 3c1241a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 106 deletions.
25 changes: 12 additions & 13 deletions modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,24 +355,23 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
if (outputPaths.Count > 2)
{
// lipo the simulator binaries together
// TODO: Move this to the native lipo implementation we have in the macos export plugin.
var lipoArgs = new List<string>();
lipoArgs.Add("-create");
lipoArgs.AddRange(outputPaths.Skip(1).Select(x => Path.Combine(x, $"{GodotSharpDirs.ProjectAssemblyName}.dylib")));
lipoArgs.Add("-output");
lipoArgs.Add(Path.Combine(outputPaths[1], $"{GodotSharpDirs.ProjectAssemblyName}.dylib"));

int lipoExitCode = OS.ExecuteCommand(XcodeHelper.FindXcodeTool("lipo"), lipoArgs);
if (lipoExitCode != 0)
throw new InvalidOperationException($"Command 'lipo' exited with code: {lipoExitCode}.");
string outputPath = Path.Combine(outputPaths[1], $"{GodotSharpDirs.ProjectAssemblyName}.dylib");
string[] files = outputPaths
.Skip(1)
.Select(path => Path.Combine(path, $"{GodotSharpDirs.ProjectAssemblyName}.dylib"))
.ToArray();

if (!Internal.LipOCreateFile(outputPath, files))
{
throw new InvalidOperationException($"Failed to 'lipo' simulator binaries.");
}

outputPaths.RemoveRange(2, outputPaths.Count - 2);
}

var xcFrameworkPath = Path.Combine(GodotSharpDirs.ProjectBaseOutputPath, publishConfig.BuildConfig,
$"{GodotSharpDirs.ProjectAssemblyName}_aot.xcframework");
if (!BuildManager.GenerateXCFrameworkBlocking(outputPaths,
Path.Combine(GodotSharpDirs.ProjectBaseOutputPath, publishConfig.BuildConfig, xcFrameworkPath)))
string xcFrameworkPath = Path.Combine(GodotSharpDirs.ProjectBaseOutputPath, publishConfig.BuildConfig, $"{GodotSharpDirs.ProjectAssemblyName}_aot.xcframework");
if (!BuildManager.GenerateXCFrameworkBlocking(outputPaths, xcFrameworkPath))
{
throw new InvalidOperationException("Failed to generate xcframework.");
}
Expand Down
93 changes: 0 additions & 93 deletions modules/mono/editor/GodotTools/GodotTools/Export/XcodeHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public static bool IsMacOSAppBundleInstalled(string bundleId)
return godot_icall_Internal_IsMacOSAppBundleInstalled(bundleIdIn);
}

public static bool LipOCreateFile(string outputPath, string[] files)
{
using godot_string outputPathIn = Marshaling.ConvertStringToNative(outputPath);
using godot_packed_string_array filesIn = Marshaling.ConvertSystemArrayToNativePackedStringArray(files);
return godot_icall_Internal_LipOCreateFile(outputPathIn, filesIn);
}

public static bool GodotIs32Bits() => godot_icall_Internal_GodotIs32Bits();

public static bool GodotIsRealTDouble() => godot_icall_Internal_GodotIsRealTDouble();
Expand Down Expand Up @@ -121,6 +128,8 @@ public static partial bool godot_icall_EditorProgress_Step(in godot_string task,

private static partial bool godot_icall_Internal_IsMacOSAppBundleInstalled(in godot_string bundleId);

private static partial bool godot_icall_Internal_LipOCreateFile(in godot_string outputPath, in godot_packed_string_array files);

private static partial bool godot_icall_Internal_GodotIs32Bits();

private static partial bool godot_icall_Internal_GodotIsRealTDouble();
Expand Down
9 changes: 9 additions & 0 deletions modules/mono/editor/editor_internal_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "editor/plugins/script_editor_plugin.h"
#include "editor/themes/editor_scale.h"
#include "main/main.h"
#include "platform/macos/export/lipo.h"

#ifdef UNIX_ENABLED
#include <unistd.h> // access
Expand Down Expand Up @@ -117,6 +118,13 @@ bool godot_icall_Internal_IsMacOSAppBundleInstalled(const godot_string *p_bundle
#endif
}

bool godot_icall_Internal_LipOCreateFile(const godot_string *p_output_path, const godot_packed_array *p_files) {
String output_path = *reinterpret_cast<const String *>(p_output_path);
PackedStringArray files = *reinterpret_cast<const PackedStringArray *>(p_files);
LipO lip;
return lip.create_file(output_path, files);
}

bool godot_icall_Internal_GodotIs32Bits() {
return sizeof(void *) == 4;
}
Expand Down Expand Up @@ -258,6 +266,7 @@ static const void *unmanaged_callbacks[]{
(void *)godot_icall_EditorProgress_Step,
(void *)godot_icall_Internal_FullExportTemplatesDir,
(void *)godot_icall_Internal_IsMacOSAppBundleInstalled,
(void *)godot_icall_Internal_LipOCreateFile,
(void *)godot_icall_Internal_GodotIs32Bits,
(void *)godot_icall_Internal_GodotIsRealTDouble,
(void *)godot_icall_Internal_GodotMainIteration,
Expand Down

0 comments on commit 3c1241a

Please sign in to comment.