Skip to content

Commit

Permalink
Merge pull request #1752 from tobil4sk/fix/mac-HXCPP_ARM64
Browse files Browse the repository at this point in the history
Set HXCPP_ARM64 by default when building on Apple Silicon Mac
  • Loading branch information
player-03 authored Feb 4, 2024
2 parents 3cbafc4 + 560ad5a commit 6fe43ea
Showing 1 changed file with 51 additions and 44 deletions.
95 changes: 51 additions & 44 deletions tools/platforms/MacPlatform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class MacPlatform extends PlatformTarget
private var contentDirectory:String;
private var executableDirectory:String;
private var executablePath:String;
private var is64:Bool;
private var targetArchitecture:Architecture;
private var targetType:String;

private var dirSuffix(get, never):String;

public function new(command:String, _project:HXProject, targetFlags:Map<String, String>)
{
super(command, _project, targetFlags);
Expand Down Expand Up @@ -93,20 +95,6 @@ class MacPlatform extends PlatformTarget
title: ""
};

switch (System.hostArchitecture)
{
case ARMV6:
defaults.architectures = [ARMV6];
case ARMV7:
defaults.architectures = [ARMV7];
case X86:
defaults.architectures = [X86];
case X64:
defaults.architectures = [X64];
default:
defaults.architectures = [];
}

defaults.window.allowHighDPI = false;

for (i in 1...project.windows.length)
Expand All @@ -122,11 +110,13 @@ class MacPlatform extends PlatformTarget
project.architectures.remove(excludeArchitecture);
}

targetArchitecture = Type.createEnum(Architecture, Type.enumConstructor(System.hostArchitecture));
for (architecture in project.architectures)
{
if (architecture == Architecture.X64)
if (architecture.match(X86 | X64 | ARMV6 | ARMV7 | ARM64))
{
is64 = true;
targetArchitecture = architecture;
break;
}
}

Expand All @@ -137,7 +127,6 @@ class MacPlatform extends PlatformTarget
else if (project.targetFlags.exists("hl"))
{
targetType = "hl";
is64 = true;
}
else if (project.targetFlags.exists("java"))
{
Expand All @@ -157,7 +146,7 @@ class MacPlatform extends PlatformTarget
}

targetDirectory = Path.combine(project.app.path, project.config.getString("mac.output-directory", targetType == "cpp" ? "macos" : targetType));
targetDirectory = StringTools.replace(targetDirectory, "arch64", is64 ? "64" : "");
targetDirectory = StringTools.replace(targetDirectory, "arch64", dirSuffix);
applicationDirectory = targetDirectory + "/bin/" + project.app.file + ".app";
contentDirectory = applicationDirectory + "/Contents/Resources";
executableDirectory = applicationDirectory + "/Contents/MacOS";
Expand All @@ -179,11 +168,11 @@ class MacPlatform extends PlatformTarget
// TODO: Support single binary for HashLink
if (targetType == "hl")
{
ProjectHelper.copyLibrary(project, ndll, "Mac" + (is64 ? "64" : ""), "", ".hdll", executableDirectory, project.debug, targetSuffix);
ProjectHelper.copyLibrary(project, ndll, "Mac" + dirSuffix, "", ".hdll", executableDirectory, project.debug, targetSuffix);
}
else
{
ProjectHelper.copyLibrary(project, ndll, "Mac" + (is64 ? "64" : ""), "",
ProjectHelper.copyLibrary(project, ndll, "Mac" + dirSuffix, "",
(ndll.haxelib != null
&& (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", executableDirectory,
project.debug, targetSuffix);
Expand All @@ -197,16 +186,16 @@ class MacPlatform extends PlatformTarget

if (noOutput) return;

NekoHelper.createExecutable(project.templatePaths, "mac" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath);
NekoHelper.copyLibraries(project.templatePaths, "mac" + (is64 ? "64" : ""), executableDirectory);
NekoHelper.createExecutable(project.templatePaths, "mac" + dirSuffix, targetDirectory + "/obj/ApplicationMain.n", executablePath);
NekoHelper.copyLibraries(project.templatePaths, "mac" + dirSuffix, executableDirectory);
}
else if (targetType == "hl")
{
System.runCommand("", "haxe", [hxml]);

if (noOutput) return;

HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, is64);
HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, true);

// HashLink looks for hlboot.dat and libraries in the current
// working directory, so the .app file won't work properly if it
Expand Down Expand Up @@ -234,16 +223,16 @@ class MacPlatform extends PlatformTarget
System.recursiveCopy(targetDirectory + "/obj/lib", Path.combine(executableDirectory, "lib"));
System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar",
Path.combine(executableDirectory, project.app.file + ".jar"));
JavaHelper.copyLibraries(project.templatePaths, "Mac" + (is64 ? "64" : ""), executableDirectory);
JavaHelper.copyLibraries(project.templatePaths, "Mac" + dirSuffix, executableDirectory);
}
else if (targetType == "nodejs")
{
System.runCommand("", "haxe", [hxml]);

if (noOutput) return;

// NekoHelper.createExecutable (project.templatePaths, "Mac" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath);
// NekoHelper.copyLibraries (project.templatePaths, "Mac" + (is64 ? "64" : ""), executableDirectory);
// NekoHelper.createExecutable (project.templatePaths, "Mac" + dirSuffix, targetDirectory + "/obj/ApplicationMain.n", executablePath);
// NekoHelper.copyLibraries (project.templatePaths, "Mac" + dirSuffix, executableDirectory);
}
else if (targetType == "cs")
{
Expand All @@ -264,12 +253,18 @@ class MacPlatform extends PlatformTarget
var haxeArgs = [hxml, "-D", "HXCPP_CLANG"];
var flags = ["-DHXCPP_CLANG"];

if (is64)
if (targetArchitecture == X64)
{
haxeArgs.push("-D");
haxeArgs.push("HXCPP_M64");
flags.push("-DHXCPP_M64");
}
else if (targetArchitecture == ARM64)
{
haxeArgs.push("-D");
haxeArgs.push("HXCPP_ARM64");
flags.push("-DHXCPP_ARM64");
}

if (!project.targetFlags.exists("static"))
{
Expand Down Expand Up @@ -332,7 +327,7 @@ class MacPlatform extends PlatformTarget
context.NODE_FILE = executableDirectory + "/ApplicationMain.js";
context.HL_FILE = targetDirectory + "/obj/ApplicationMain.hl";
context.CPP_DIR = targetDirectory + "/obj/";
context.BUILD_DIR = project.app.path + "/mac" + (is64 ? "64" : "");
context.BUILD_DIR = project.app.path + "/mac" + dirSuffix;

return context;
}
Expand Down Expand Up @@ -372,22 +367,27 @@ class MacPlatform extends PlatformTarget
{
var commands = [];

if (targetFlags.exists("hl") && System.hostArchitecture == X64)
{
// TODO: Support single binary
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64", "-Dhashlink"]);
}
else
switch (System.hostArchitecture)
{
if (!targetFlags.exists("32") && (command == "rebuild" || System.hostArchitecture == X64))
{
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64"]);
}

if (!targetFlags.exists("64") && (targetFlags.exists("32") || System.hostArchitecture == X86))
{
case X64:
if (targetFlags.exists("hl"))
{
// TODO: Support single binary
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64", "-Dhashlink"]);
}
else if (!targetFlags.exists("32"))
{
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M64"]);
}
else
{
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M32"]);
}
case X86:
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_M32"]);
}
case ARM64:
commands.push(["-Dmac", "-DHXCPP_CLANG", "-DHXCPP_ARM64"]);
default:
}

if (targetFlags.exists("hl"))
Expand Down Expand Up @@ -455,7 +455,7 @@ class MacPlatform extends PlatformTarget

if (ndll.path == null || ndll.path == "")
{
context.ndlls[i].path = NDLL.getLibraryPath(ndll, "Mac" + (is64 ? "64" : ""), "lib", ".a", project.debug);
context.ndlls[i].path = NDLL.getLibraryPath(ndll, "Mac" + dirSuffix, "lib", ".a", project.debug);
}
}
}
Expand Down Expand Up @@ -530,4 +530,11 @@ class MacPlatform extends PlatformTarget
@ignore public override function trace():Void {}

@ignore public override function uninstall():Void {}

// Getters & Setters

private inline function get_dirSuffix():String
{
return targetArchitecture == X64 ? "64" : "";
}
}

0 comments on commit 6fe43ea

Please sign in to comment.