openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
753 stars 365 forks source link

Resolve any final issues that occur when building for WinRT #1024

Open jgranick opened 7 years ago

jgranick commented 7 years ago

After we have Lime and HXCPP binaries, building real applications for the Universal Windows Platform may reveal some minor behavioral issues we need to resolve. This issue represents completion of standard UWP support

madrazo commented 5 years ago

@jgranick Hi Joshua, I hope that you are fine I'm tring to run a winrt as request for @jaimedominguez_twitter

Would you please take a look at: https://github.com/madrazo/lime-1/commit/0cba86f840484d0522ed4ecc78b98e8b495808c5

I'm tring to use static build to have a custom Main.cpp from the templates However the problem I have is that I can't make the templates to work in: AppxManifest.xml BuildMain.xml Main.cpp

I use recursiveSmartCopyTemplate in WindowsPlatform.hx but the contents won't change. Following the instructions, a window opens but closes quickly, maybe because of the missing libs or ndlls. Hopefully you can have a better idea of what is missing.

Thanks

jgranick commented 5 years ago

I noticed this line:

ProjectHelper.recursiveSmartCopyTemplate (project, "winrt/appx", targetDirectory + "/bin", context, false, true);

The process argument is false, which means it will not process the file as a template, it will only do a straight copy. Do you want them to be treated as templates, and insert the title and other meta-data as dynamic data?

Also, look at the standard C++ static main we use, we have a few additional libs needed to run the application than we had before, though I suppose that would trigger a compile-time error.

If the application will not run, can you "Open Project" from Visual Studio on the EXE, then hit run and see if it gives you any information on the crash?

If you do a -debug build, and optionally, add -Dopenfl-debug and/or -Dlime-debug, there will be additional debug information if the Visual Studio debugger does not provide useful information in a stack trace

madrazo commented 5 years ago

@jgranick Hi Joshua, thank you for your help I'm trying to include SDL_main.h in the custom Main.cpp https://github.com/madrazo/lime-1/blob/winrtrun/templates/winrt/static/Main.cpp#L2 However the include flag is not working in BuildMain.xml https://github.com/madrazo/lime-1/blob/winrtrun/templates/winrt/static/BuildMain.xml#L15 This is needed to call the SDL_WinRTRunApp function I'll appreciate any idea, thanks

Branch url: https://github.com/madrazo/lime-1/tree/winrtrun Code comparisson: https://github.com/madrazo/lime-1/compare/develop...madrazo:winrtrun

lime rebuild tools
lime rebuild winrt -static
in DisplayingABitmap:
openfl test project.xml winrt -static

Thank you

jgranick commented 5 years ago

Is there a way to declare it as an extern, like here?

https://github.com/madrazo/lime-1/blob/winrtrun/templates/winrt/static/Main.cpp#L43

It's C++, so it would not be extern "C", but perhaps there's still a way to do a forward declaration?

madrazo commented 5 years ago

@jgranick that worked. Now I can get the debugger attached when uncommenting this "Sleep": https://github.com/madrazo/lime-1/blob/winrtrun/templates/winrt/static/Main.cpp#L64 That is, compiling 'openfl test project.xml winrt -static' and then Debug->Other debug targets->Debug installed app package.. in VS2017

However, the app returns without doing nothing, and no errors. So, it seems that I need to call ApplicationMain as it here: https://github.com/haxenme/nme/blob/master/project/src/winrt/Main.cpp#L50

jgranick commented 5 years ago

Here's what we use:

https://github.com/openfl/lime/blob/develop/templates/cpp/static/Main.cpp

I think hxRunLibrary () is the key?

https://github.com/HaxeFoundation/hxcpp/blob/8b99e1fa83b5df9d5ce21581a7b769dc461c0943/include/hx/MacrosFixed.h#L342

Perhaps __boot_all is generated to reference the entry point for the code (such as "ApplicationMain" or whatever it is called)

madrazo commented 5 years ago

@jgranick Im calling hxRunLibrary already https://github.com/madrazo/lime-1/blob/winrtrun/templates/winrt/static/Main.cpp#L80

I think those functions (*_register_prims) are just returning 0 because they need set compilerflags (defines), such as LIME_SDL, LIME_OPENGL...

madrazo commented 5 years ago

@jgranick after defining LIME_SDL, I got the following error from hxRunLibrary (VS2017 debug)

****LOG: ./Main.cpp(85): _main 
    [Error: [lime.utils.Preloader] ERROR: There is no asset library with an ID of "default"
]

Setting rootPath = "" in ManifestResources.hx seems to fix it but now it crashes on ApplicationMain.cpp

HXLINE( 147)        int result = app->exec();

wich is

        var result = app.exec ();

on Haxe It should be entering now NativeApplication.hx but it seems that it still doesn´t :(

This is "app" on ApplicationMain.cpp image

jgranick commented 5 years ago

It's strange that LIME_SDL had to be defined, we have more defines (LIME_SDL_ANGLE, etc) which may also be relevant, but I'm still trying to understand why this define affected the build. Shouldn't these be defined properly in the Build.xml, and affect all the files in the Lime shared library already?

Does WinRT still define the #if windows conditional flag? Does it also define #if sys, #if native, #if desktop? If those defines do not trigger, then on the Haxe side, we may have to fix some things

madrazo commented 5 years ago

Got Angle compiled as static. It works for Windows -static, but it still has a problem with WinRT. It crashes when compiling a shader. For Windows (non static) there is a link issue (DllMain defined multiple times).

For testing it, you need to add the Angle source to project/libs. On my test branch I added it directly, and it is the version from nme-toolkit git clone --single-branch --branch winrt7 --recursive https://github.com/madrazo/lime-1

I'm still figuring out how to send a flag to BuildMain.xml https://github.com/madrazo/lime-1/blob/winrt7/templates/cpp/static/BuildMain.xml#L21 (NATIVE_TOOLKIT_SDL_ANGLE is not recognized)

UPDATE: Added a define to avoid DllMain and force static angle for non -static as well (windows)

UPDATE2: Figured out how to send a flag to BuildMain.xml ,-angle is used to force native angle compiling