From df0827f4a63bfeeab7ea45f28e078a8960752d44 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 1 Nov 2018 17:33:42 -0700 Subject: [PATCH] First pass at WinRT app builds --- templates/winrt/hxml/debug.hxml | 6 ++ templates/winrt/hxml/final.hxml | 6 ++ templates/winrt/hxml/release.hxml | 5 ++ templates/winrt/static/BuildMain.xml | 95 ++++++++++++++++++++++++++++ templates/winrt/static/Main.cpp | 43 +++++++++++++ tools/platforms/WindowsPlatform.hx | 63 +++++++++++++++++- 6 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 templates/winrt/hxml/debug.hxml create mode 100644 templates/winrt/hxml/final.hxml create mode 100644 templates/winrt/hxml/release.hxml create mode 100644 templates/winrt/static/BuildMain.xml create mode 100644 templates/winrt/static/Main.cpp diff --git a/templates/winrt/hxml/debug.hxml b/templates/winrt/hxml/debug.hxml new file mode 100644 index 000000000..4a7a166e4 --- /dev/null +++ b/templates/winrt/hxml/debug.hxml @@ -0,0 +1,6 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-cpp ::CPP_DIR:: +-cp ::OUTPUT_DIR::/haxe +--macro keep("::APP_MAIN::") +-D winrt +-debug diff --git a/templates/winrt/hxml/final.hxml b/templates/winrt/hxml/final.hxml new file mode 100644 index 000000000..48760af00 --- /dev/null +++ b/templates/winrt/hxml/final.hxml @@ -0,0 +1,6 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-cp ::OUTPUT_DIR::/haxe +-cpp ::CPP_DIR:: +--macro keep("::APP_MAIN::") +-D winrt +-D final diff --git a/templates/winrt/hxml/release.hxml b/templates/winrt/hxml/release.hxml new file mode 100644 index 000000000..d74c2747c --- /dev/null +++ b/templates/winrt/hxml/release.hxml @@ -0,0 +1,5 @@ +-main ApplicationMain ::HAXE_FLAGS:: +-cp ::OUTPUT_DIR::/haxe +-cpp ::CPP_DIR:: +--macro keep("::APP_MAIN::") +-D winrt diff --git a/templates/winrt/static/BuildMain.xml b/templates/winrt/static/BuildMain.xml new file mode 100644 index 000000000..cc019892f --- /dev/null +++ b/templates/winrt/static/BuildMain.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + ::foreach ndlls:: + ::end:: + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + +
+ + + +
+ + + + + + + +
diff --git a/templates/winrt/static/Main.cpp b/templates/winrt/static/Main.cpp new file mode 100644 index 000000000..dc71655b3 --- /dev/null +++ b/templates/winrt/static/Main.cpp @@ -0,0 +1,43 @@ +#include + +#ifdef HX_WINDOWS +#include +#endif + +extern "C" const char *hxRunLibrary (); +extern "C" void hxcpp_set_top_of_stack (); + +extern "C" int zlib_register_prims (); +extern "C" int lime_cairo_register_prims (); +extern "C" int lime_openal_register_prims (); +::foreach ndlls::::if (registerStatics):: +extern "C" int ::nameSafe::_register_prims ();::end::::end:: + + +#ifdef HX_WINDOWS +int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { +#else +extern "C" int main(int argc, char *argv[]) { +#endif + + hxcpp_set_top_of_stack (); + + zlib_register_prims (); + lime_cairo_register_prims (); + lime_openal_register_prims (); + ::foreach ndlls::::if (registerStatics):: + ::nameSafe::_register_prims ();::end::::end:: + + const char *err = NULL; + err = hxRunLibrary (); + + if (err) { + + printf("Error: %s\n", err); + return -1; + + } + + return 0; + +} \ No newline at end of file diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 29768a87d..263082877 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -72,6 +72,10 @@ class WindowsPlatform extends PlatformTarget { targetType = "java"; + } else if (project.targetFlags.exists ("winrt")) { + + targetType = "winrt"; + } else { targetType = "cpp"; @@ -166,7 +170,15 @@ class WindowsPlatform extends PlatformTarget { } - if (!project.targetFlags.exists ("static") || targetType != "cpp") { + if (targetType == "winrt") { + + for (ndll in project.ndlls) { + + ProjectHelper.copyLibrary (project, ndll, "WinRT", "", (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", applicationDirectory, project.debug, null); + + } + + } else if (!project.targetFlags.exists ("static") || targetType != "cpp") { var targetSuffix = (targetType == "hl") ? ".hdll" : null; @@ -249,6 +261,55 @@ class WindowsPlatform extends PlatformTarget { System.copyFile (targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", Path.combine (applicationDirectory, project.app.file + ".jar")); JavaHelper.copyLibraries (project.templatePaths, "Windows" + (is64 ? "64" : ""), applicationDirectory); + } else if (targetType == "winrt") { + + var haxeArgs = [ hxml ]; + var flags = []; + + haxeArgs.push ("-D"); + haxeArgs.push ("winrt"); + flags.push ("-Dwinrt"); + + if (!project.environment.exists ("SHOW_CONSOLE")) { + + haxeArgs.push ("-D"); + haxeArgs.push ("no_console"); + flags.push ("-Dno_console"); + + } + + if (!project.targetFlags.exists ("static")) { + + System.runCommand ("", "haxe", haxeArgs); + + if (noOutput) return; + + CPPHelper.compile (project, targetDirectory + "/obj", flags); + + System.copyFile (targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath); + + } else { + + System.runCommand ("", "haxe", haxeArgs.concat ([ "-D", "static_link" ])); + + if (noOutput) return; + + CPPHelper.compile (project, targetDirectory + "/obj", flags.concat ([ "-Dstatic_link" ])); + CPPHelper.compile (project, targetDirectory + "/obj", flags, "BuildMain.xml"); + + System.copyFile (targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath); + + } + + var iconPath = Path.combine (applicationDirectory, "icon.ico"); + + if (IconHelper.createWindowsIcon (icons, iconPath) && System.hostPlatform == WINDOWS) { + + var templates = [ Haxelib.getPath (new Haxelib (#if lime "lime" #else "hxp" #end)) + "/templates" ].concat (project.templatePaths); + System.runCommand ("", System.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ executablePath, iconPath, "1" ], true, true); + + } + } else { var haxeArgs = [ hxml ];