Fixes for HL

This commit is contained in:
Joshua Granick
2019-03-12 15:57:19 -07:00
parent d55762569d
commit 299ed974c7
3 changed files with 179 additions and 118 deletions

View File

@@ -390,6 +390,9 @@
<ext value=".so" />
<ext value=".ndll" if="windows || mac || linux" />
<!-- TODO: Support single binary -->
<ext value=".hdll" if="LIME_HASHLINK" />
<section if="windows">
<lib name="gdi32.lib" />
@@ -419,7 +422,7 @@
<lib name="Xinput.lib" if="winrt" />
<lib name="DXGI.lib" if="winrt" />
<lib name="-libpath:${HLPATH}" if="LIME_HASHLINK" />
<lib name="-libpath:../templates/bin/hl/windows" if="LIME_HASHLINK" />
<lib name="libhl.lib" if="LIME_HASHLINK" />
<!-- <lib name="-delayload:libhl.dll" /> -->

View File

@@ -27,7 +27,7 @@
https://github.com/HaxeFoundation/hashlink/wiki/
**/
#define HL_VERSION 0x160
#define HL_VERSION 0x190
#if defined(_WIN32)
# define HL_WIN
@@ -206,8 +206,10 @@ typedef unsigned long long uint64;
// -------------- UNICODE -----------------------------------
#if defined(HL_WIN) && !defined(HL_LLVM)
#ifdef HL_WIN_DESKTOP
#if defined(HL_WIN_DESKTOP) && !defined(HL_MINGW)
// # include <Windows.h>
#elif defined(HL_WIN_DESKTOP) && defined(HL_MINGW)
// # include<windows.h>
#else
# include <xdk.h>
#endif
@@ -219,7 +221,7 @@ typedef wchar_t uchar;
# define uprintf wprintf
# define ustrlen wcslen
# define ustrdup _wcsdup
# define uvsprintf wvsprintf
HL_API int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list arglist );
# define utod(s,end) wcstod(s,end)
# define utoi(s,end) wcstol(s,end,10)
# define ucmp(a,b) wcscmp(a,b)
@@ -262,7 +264,7 @@ HL_API int utoi( const uchar *str, uchar **end );
HL_API int ucmp( const uchar *a, const uchar *b );
HL_API int utostr( char *out, int out_size, const uchar *str );
HL_API int usprintf( uchar *out, int out_size, const uchar *fmt, ... );
HL_API int uvsprintf( uchar *out, const uchar *fmt, va_list arglist );
HL_API int uvszprintf( uchar *out, int out_size, const uchar *fmt, va_list arglist );
HL_API void uprintf( const uchar *fmt, const uchar *str );
C_FUNCTION_END
#endif
@@ -295,6 +297,14 @@ C_FUNCTION_END
# define hl_debug_break()
#endif
#ifdef HL_VCC
# define HL_NO_RETURN(f) __declspec(noreturn) f
# define HL_UNREACHABLE
#else
# define HL_NO_RETURN(f) f __attribute__((noreturn))
# define HL_UNREACHABLE __builtin_unreachable()
#endif
// ---- TYPES -------------------------------------------
typedef enum {
@@ -318,8 +328,9 @@ typedef enum {
HABSTRACT=17,
HENUM = 18,
HNULL = 19,
HMETHOD = 20,
// ---------
HLAST = 20,
HLAST = 21,
_H_FORCE_INT = 0x7FFFFFFF
} hl_type_kind;
@@ -578,11 +589,12 @@ HL_API int hl_hash_utf8( const char *str ); // no cache
HL_API int hl_hash_gen( const uchar *name, bool cache_name );
HL_API const uchar *hl_field_name( int hash );
#define hl_error(msg) hl_error_msg(USTR(msg))
HL_API void hl_error_msg( const uchar *msg, ... );
#define hl_error(msg, ...) hl_throw(hl_alloc_strbytes(USTR(msg), ## __VA_ARGS__))
HL_API vdynamic *hl_alloc_strbytes( const uchar *msg, ... );
HL_API void hl_assert( void );
HL_API void hl_throw( vdynamic *v );
HL_API void hl_rethrow( vdynamic *v );
HL_API HL_NO_RETURN( void hl_throw( vdynamic *v ) );
HL_API HL_NO_RETURN( void hl_rethrow( vdynamic *v ) );
HL_API void hl_setup_longjump( void *j );
HL_API void hl_setup_exception( void *resolve_symbol, void *capture_stack );
HL_API void hl_dump_stack( void );
@@ -716,6 +728,7 @@ HL_API int hl_buffer_length( hl_buffer *b );
HL_API uchar *hl_buffer_content( hl_buffer *b, int *len );
HL_API uchar *hl_to_string( vdynamic *v );
HL_API const uchar *hl_type_str( hl_type *t );
HL_API void hl_throw_buffer( hl_buffer *b );
// ----------------------- FFI ------------------------------------------------------
@@ -784,7 +797,11 @@ typedef struct {
#endif
#if defined(HL_GCC) && !defined(HL_CONSOLE)
# define HL_NO_OPT __attribute__((optimize("-O0")))
# ifdef HL_CLANG
# define HL_NO_OPT __attribute__ ((optnone))
# else
# define HL_NO_OPT __attribute__((optimize("-O0")))
# endif
#else
# define HL_NO_OPT
#endif
@@ -806,8 +823,9 @@ typedef struct _hl_trap_ctx hl_trap_ctx;
struct _hl_trap_ctx {
jmp_buf buf;
hl_trap_ctx *prev;
vdynamic *tcheck;
};
#define hl_trap(ctx,r,label) { hl_thread_info *__tinf = hl_get_thread(); ctx.prev = __tinf->trap_current; __tinf->trap_current = &ctx; if( setjmp(ctx.buf) ) { r = __tinf->exc_value; goto label; } }
#define hl_trap(ctx,r,label) { hl_thread_info *__tinf = hl_get_thread(); ctx.tcheck = NULL; ctx.prev = __tinf->trap_current; __tinf->trap_current = &ctx; if( setjmp(ctx.buf) ) { r = __tinf->exc_value; goto label; } }
#define hl_endtrap(ctx) hl_get_thread()->trap_current = ctx.prev
#define HL_EXC_MAX_STACK 0x100
@@ -815,6 +833,7 @@ struct _hl_trap_ctx {
#define HL_EXC_CATCH_ALL 2
#define HL_EXC_IS_THROW 4
#define HL_TRACK_DISABLE 8
#define HL_THREAD_INVISIBLE 16
typedef struct {
int thread_id;

View File

@@ -51,6 +51,7 @@ class WindowsPlatform extends PlatformTarget
else if (project.targetFlags.exists("hl"))
{
targetType = "hl";
is64 = false;
}
else if (project.targetFlags.exists("nodejs"))
{
@@ -154,13 +155,13 @@ class WindowsPlatform extends PlatformTarget
if (targetType == "winrt")
{
if(!project.targetFlags.exists ("static"))
if (!project.targetFlags.exists("static"))
{
for (ndll in project.ndlls)
{
ProjectHelper.copyLibrary(project, ndll, "WinRT" + (is64 ? "64" : ""), "",
(ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", applicationDirectory,
project.debug, null);
(ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll",
applicationDirectory, project.debug, null);
}
}
}
@@ -170,9 +171,18 @@ class WindowsPlatform extends PlatformTarget
for (ndll in project.ndlls)
{
ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "",
(ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", applicationDirectory,
project.debug, targetSuffix);
// TODO: Support single binary for HashLink
if (targetType == "hl")
{
ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", ".hdll", applicationDirectory, project
.debug, targetSuffix);
}
else
{
ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "",
(ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll",
applicationDirectory, project.debug, targetSuffix);
}
}
}
@@ -200,7 +210,19 @@ class WindowsPlatform extends PlatformTarget
if (noOutput) return;
System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, project.app.file + ".hl"));
// System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, project.app.file + ".hl"));
System.recursiveCopyTemplate(project.templatePaths, "bin/hl/windows", applicationDirectory);
System.copyFile(targetDirectory + "/obj/ApplicationMain.hl", Path.combine(applicationDirectory, "hlboot.dat"));
System.renameFile(Path.combine(applicationDirectory, "hl.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 if (targetType == "nodejs")
{
@@ -237,8 +259,9 @@ class WindowsPlatform extends PlatformTarget
if (haxeVersion.length > 4)
{
haxeVersionString = haxeVersion.charAt(0) + haxeVersion.charAt(2) + (haxeVersion.length == 5 ? "0" + haxeVersion.charAt(4) : haxeVersion
.charAt(4) + haxeVersion.charAt(5));
haxeVersionString = haxeVersion.charAt(0)
+ haxeVersion.charAt(2)
+ (haxeVersion.length == 5 ? "0" + haxeVersion.charAt(4) : haxeVersion.charAt(4) + haxeVersion.charAt(5));
}
System.runCommand(targetDirectory + "/obj", "haxelib", ["run", "hxjava", "hxjava_build.txt", "--haxe-version", haxeVersionString]);
@@ -298,14 +321,14 @@ class WindowsPlatform extends PlatformTarget
System.copyFile(targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath);
}
//TODO createWinrtIcons
//var iconPath = Path.combine(applicationDirectory, "icon.ico");
// TODO createWinrtIcons
// var iconPath = Path.combine(applicationDirectory, "icon.ico");
//if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS)
//{
// 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
{
@@ -356,7 +379,8 @@ class WindowsPlatform extends PlatformTarget
if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS)
{
var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths);
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);
}
}
@@ -407,11 +431,11 @@ class WindowsPlatform extends PlatformTarget
}
}
else if (targetType == "winrt")
{
{
context.CPP_DIR = targetDirectory + "/obj";
context.BUILD_DIR = project.app.path + "/winrt" + (is64 ? "64" : "");
context.DC = "::";
}
}
else
{
context.NEKO_FILE = targetDirectory + "/obj/ApplicationMain.n";
@@ -439,11 +463,16 @@ class WindowsPlatform extends PlatformTarget
hxml.addClassName(context.APP_MAIN);
switch (targetType)
{
case "hl": hxml.hl = "_.hl";
case "neko": hxml.neko = "_.n";
case "java": hxml.java = "_";
case "nodejs", "winjs": hxml.js = "_.js";
default: hxml.cpp = "_";
case "hl":
hxml.hl = "_.hl";
case "neko":
hxml.neko = "_.n";
case "java":
hxml.java = "_";
case "nodejs", "winjs":
hxml.js = "_.js";
default:
hxml.cpp = "_";
}
hxml.noOutput = true;
return hxml;
@@ -463,14 +492,18 @@ class WindowsPlatform extends PlatformTarget
var commands = [];
if (!targetFlags.exists("64") && (command == "rebuild"
|| System.hostArchitecture == X86
|| (targetType != "cpp" && targetType != "winrt")))
if (!targetFlags.exists("64")
&& (command == "rebuild" || System.hostArchitecture == X86 || (targetType != "cpp" && targetType != "winrt")))
{
if (targetFlags.exists("winrt"))
if (targetType == "winrt")
{
commands.push(["-Dwinrt", "-DHXCPP_M32"]);
}
else if (targetType == "hl")
{
// TODO: Support single binary
commands.push(["-Dwindows", "-DHXCPP_M32", "-Dhashlink"]);
}
else
{
commands.push(["-Dwindows", "-DHXCPP_M32"]);
@@ -483,10 +516,12 @@ class WindowsPlatform extends PlatformTarget
if (!targetFlags.exists("32")
&& System.hostArchitecture == X64
&& (command != "rebuild" || targetType == "cpp" || targetType == "winrt"))
&& (command != "rebuild" || targetType == "cpp" || targetType == "winrt")
&& targetType != "hl")
{
if (targetFlags.exists("winrt"))
if (targetType == "winrt")
{
commands.push(["-Dwinrt", "-DHXCPP_M64"]);
}
else
@@ -508,11 +543,7 @@ class WindowsPlatform extends PlatformTarget
arguments.push("-verbose");
}
if (targetType == "hl")
{
System.runCommand(applicationDirectory, "hl", [project.app.file + ".hl"].concat(arguments));
}
else if (targetType == "nodejs")
if (targetType == "nodejs")
{
NodeJSHelper.run(project, targetDirectory + "/bin/ApplicationMain.js", arguments);
}
@@ -575,8 +606,8 @@ class WindowsPlatform extends PlatformTarget
// var test = '"& ""' + targetDirectory + '/bin/PowerShell_Set_Unrestricted.reg"""';
// Sys.command ('powershell & ""' + targetDirectory + '/bin/source/AppPackages/' + project.app.file + '_1.0.0.0_AnyCPU_Test/Add-AppDevPackage.ps1""');
var version = project.meta.version + "." + project.meta.buildNumber;
System.openFile(targetDirectory + "/source/AppPackages/" + project.app.file + "_" + version + "_AnyCPU_Test",
project.app.file + "_" + version + "_AnyCPU.appx");
System.openFile(targetDirectory + "/source/AppPackages/" + project.app.file + "_" + version + "_AnyCPU_Test", project.app
.file + "_" + version + "_AnyCPU.appx");
// source/AppPackages/uwp-project_1.0.0.0_AnyCPU_Test/Add-AppDevPackage.ps1
@@ -631,7 +662,8 @@ class WindowsPlatform extends PlatformTarget
if ((targetType == "cpp" || targetType == "winrt") && project.targetFlags.exists("static"))
{
var programFiles = project.environment.get("ProgramFiles(x86)");
var hasVSCommunity = (programFiles != null && FileSystem.exists(Path.combine(programFiles, "Microsoft Visual Studio/Installer/vswhere.exe")));
var hasVSCommunity = (programFiles != null
&& FileSystem.exists(Path.combine(programFiles, "Microsoft Visual Studio/Installer/vswhere.exe")));
var hxcppMSVC = project.environment.get("HXCPP_MSVC");
var vs140 = project.environment.get("VS140COMNTOOLS");
@@ -650,7 +682,8 @@ class WindowsPlatform extends PlatformTarget
if (ndll.path == null || ndll.path == "")
{
context.ndlls[i].path = NDLL.getLibraryPath(ndll, (targetType == "winrt" ? "WinRT":"Windows") + (is64 ? "64" : ""), "lib", suffix, project.debug);
context.ndlls[i].path = NDLL.getLibraryPath(ndll, (targetType == "winrt" ? "WinRT" : "Windows") + (is64 ? "64" : ""), "lib", suffix, project
.debug);
}
}
}
@@ -665,11 +698,11 @@ class WindowsPlatform extends PlatformTarget
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, targetType + "/hxml", targetDirectory + "/haxe", context);
if (targetType == "winrt" && project.targetFlags.exists ("static"))
if (targetType == "winrt" && project.targetFlags.exists("static"))
{
ProjectHelper.recursiveSmartCopyTemplate (project, "winrt/assetspkg", targetDirectory + "/bin/assetspkg", context, false, true);
ProjectHelper.recursiveSmartCopyTemplate (project, "winrt/appx", targetDirectory + "/bin", context, true, true);
ProjectHelper.recursiveSmartCopyTemplate (project, "winrt/static", targetDirectory + "/obj", context, true, true);
ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/assetspkg", targetDirectory + "/bin/assetspkg", context, false, true);
ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/appx", targetDirectory + "/bin", context, true, true);
ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/static", targetDirectory + "/obj", context, true, true);
}
else if (targetType == "cpp" && project.targetFlags.exists("static"))
{
@@ -908,78 +941,83 @@ class WindowsPlatform extends PlatformTarget
System.watch(command, dirs);
}
// @ignore public override function install ():Void {}
// @ignore public override function install ():Void {}
override public function install():Void
{
super.install();
if (targetType == "winrt")
{
//if(project.winrtConfig.isAppx)
//{
// if(project.winrtConfig.isAppx)
// {
// TODO: pack in appx
//}
//else
// }
// else
{
uninstall();
Log.info("run: Register app");
var process = new sys.io.Process('powershell', ["-noprofile", "-command",'Add-AppxPackage -Path '+applicationDirectory + "/"+'AppxManifest.xml -Register']);
if (process.exitCode() != 0)
uninstall();
Log.info("run: Register app");
var process = new sys.io.Process('powershell', [
"-noprofile",
"-command",
'Add-AppxPackage -Path ' + applicationDirectory + "/" + 'AppxManifest.xml -Register'
]);
if (process.exitCode() != 0)
{
var message = process.stderr.readAll().toString();
Log.error("Cannot register. " + message);
}
process.close();
Log.error("Cannot register. " + message);
}
process.close();
}
}
}
@ignore public override function trace():Void {}
//@ignore public override function uninstall ():Void {}
// @ignore public override function uninstall ():Void {}
override public function uninstall():Void
{
{
super.uninstall();
if (targetType == "winrt")
//if(project.winrtConfig.isAppx)
//{
// TODO
//}
//else
if (targetType == "winrt") // if(project.winrtConfig.isAppx)
// {
// TODO
// }
// else
{
var appxName = project.meta.packageName;
Log.info("run: Remove previous registered app");
var process = new sys.io.Process('powershell', ["-noprofile", "-command",'Get-AppxPackage '+appxName+' | Remove-AppxPackage']);
if (process.exitCode() != 0)
var appxName = project.meta.packageName;
Log.info("run: Remove previous registered app");
var process = new sys.io.Process('powershell', [
"-noprofile",
"-command",
'Get-AppxPackage ' + appxName + ' | Remove-AppxPackage'
]);
if (process.exitCode() != 0)
{
var message = process.stderr.readAll().toString();
Log.error("Cannot remove. " + message);
var message = process.stderr.readAll().toString();
Log.error("Cannot remove. " + message);
}
process.close();
process.close();
}
}
public function winrtRun (arguments:Array<String>):Void
public function winrtRun(arguments:Array<String>):Void
{
var dir = applicationDirectory;
var haxeDir = targetDirectory + "/haxe";
var haxeDir = targetDirectory + "/haxe";
//if(project.winrtConfig.isAppx)
//{
// if(project.winrtConfig.isAppx)
// {
// Log.info("\n***Double click on "+project.app.file + ".Appx to install Appx");
//}
//else
// }
// else
{
var appxName = project.meta.packageName;
var appxId = "App";
var appxAUMID:String = null;
var appxAUMID:String = null;
var appxInfoFile = haxeDir + "/appxinfo.txt";
var kitsRoot10 = "C:\\Program Files (x86)\\Windows Kits\\10\\"; //%WindowsSdkDir%
var kitsRoot10 = "C:\\Program Files (x86)\\Windows Kits\\10\\"; // %WindowsSdkDir%
//get PackageFamilyappxName and set appxAUMID
// get PackageFamilyappxName and set appxAUMID
// write app info in a file
var cmd = 'Get-AppxPackage '+appxName+' | Out-File '+appxInfoFile+' -Encoding ASCII';
var cmd = 'Get-AppxPackage ' + appxName + ' | Out-File ' + appxInfoFile + ' -Encoding ASCII';
trace("powershell " + cmd);
var process3 = new sys.io.Process('powershell', [cmd]);
if (process3.exitCode() != 0)
@@ -989,37 +1027,38 @@ class WindowsPlatform extends PlatformTarget
}
process3.close();
// parse file
if(sys.FileSystem.exists(appxInfoFile))
if (sys.FileSystem.exists(appxInfoFile))
{
var fin = sys.io.File.read(appxInfoFile, false);
try
{
while(true)
{
var str = fin.readLine();
var split = str.split (":");
var name = StringTools.trim(split[0]);
if( name == "PackageFamilyName")
{
var appxPackageFamilyName = StringTools.trim(split[1]);
if(appxPackageFamilyName!=null)
{
appxAUMID = appxPackageFamilyName+"!"+appxId;
try
{
while (true)
{
var str = fin.readLine();
var split = str.split(":");
var name = StringTools.trim(split[0]);
if (name == "PackageFamilyName")
{
var appxPackageFamilyName = StringTools.trim(split[1]);
if (appxPackageFamilyName != null)
{
appxAUMID = appxPackageFamilyName + "!" + appxId;
break;
}
}
}
}
catch(e:haxe.io.Eof)
{
Log.error('Could not get PackageFamilyName from '+appxInfoFile);
}
fin.close();
}
}
}
}
catch (e:haxe.io.Eof)
{
Log.error('Could not get PackageFamilyName from ' + appxInfoFile);
}
fin.close();
}
Log.info("run: "+appxAUMID);
Log.info(kitsRoot10+'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe '+appxAUMID);
var process4 = new sys.io.Process(kitsRoot10+'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe', [appxAUMID]);
Log.info("run: " + appxAUMID);
Log.info(kitsRoot10 + 'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe ' + appxAUMID);
var process4 = new sys.io.Process(kitsRoot10
+ 'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe', [appxAUMID]);
}
}
}