Revert WebAssembly improvements (moved to 8.1.0-Dev branch)

This commit is contained in:
Joshua Granick
2023-05-30 09:03:18 -07:00
parent 1a46366823
commit 35d1436dcd
34 changed files with 189 additions and 289 deletions

View File

@@ -13,17 +13,14 @@ import lime.tools.CPPHelper;
import lime.tools.DeploymentHelper;
import lime.tools.HTML5Helper;
import lime.tools.HXProject;
import lime.tools.Icon;
import lime.tools.IconHelper;
import lime.tools.Orientation;
import lime.tools.PlatformTarget;
import lime.tools.ProjectHelper;
import sys.io.File;
import sys.FileSystem;
class WebAssemblyPlatform extends PlatformTarget
class EmscriptenPlatform extends PlatformTarget
{
private var dependencyPath:String;
private var outputFile:String;
public function new(command:String, _project:HXProject, targetFlags:Map<String, String>)
@@ -94,8 +91,7 @@ class WebAssemblyPlatform extends PlatformTarget
defaults.merge(project);
project = defaults;
targetDirectory = Path.combine(project.app.path, project.config.getString("webassembly.output-directory", "webassembly"));
dependencyPath = project.config.getString("webassembly.dependency-path", "lib");
targetDirectory = Path.combine(project.app.path, project.config.getString("emscripten.output-directory", "emscripten"));
outputFile = targetDirectory + "/bin/" + project.app.file + ".js";
}
@@ -114,11 +110,11 @@ class WebAssemblyPlatform extends PlatformTarget
if (sdkPath == null)
{
Log.error("You must define EMSCRIPTEN_SDK with the path to your Emscripten SDK.");
Log.error("You must define EMSCRIPTEN_SDK with the path to your Emscripten SDK");
}
var hxml = targetDirectory + "/haxe/" + buildType + ".hxml";
var args = [hxml, "-D", "webassembly", "-D", "wasm", "-D", "emscripten", "-D", "webgl", "-D", "static_link"];
var args = [hxml, "-D", "emscripten", "-D", "webgl", "-D", "static_link"];
if (Log.verbose)
{
@@ -130,12 +126,11 @@ class WebAssemblyPlatform extends PlatformTarget
if (noOutput) return;
CPPHelper.compile(project, targetDirectory + "/obj", ["-Dwebassembly", "-Dwasm", "-Demscripten", "-Dwebgl", "-Dstatic_link"]);
// CPPHelper.compile(project, targetDirectory + "/obj", ["-Demscripten", "-Dwebgl", "-Dstatic_link"], "BuildMain.xml");
CPPHelper.compile(project, targetDirectory + "/obj", ["-Demscripten", "-Dwebgl", "-Dstatic_link"]);
project.path(sdkPath);
System.runCommand("", "emcc", ["-c", targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o"], true, false, true);
System.runCommand("", "emcc", [targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o"], true, false, true);
args = ["Main.o"];
@@ -164,8 +159,11 @@ class WebAssemblyPlatform extends PlatformTarget
"-o",
"ApplicationMain.o"
]);
System.runCommand(targetDirectory + "/obj", "emcc", args, true, false, true);
if (!project.targetFlags.exists("asmjs"))
args = ["ApplicationMain.o"];
if (project.targetFlags.exists("webassembly") || project.targetFlags.exists("wasm"))
{
args.push("-s");
args.push("WASM=1");
@@ -190,56 +188,29 @@ class WebAssemblyPlatform extends PlatformTarget
}
}
if (project.targetFlags.exists("final") || project.defines.exists("disable-exception-catching") || project.targetFlags.exists("disable-exception-catching"))
if (project.targetFlags.exists("final"))
{
args.push("-s");
args.push("DISABLE_EXCEPTION_CATCHING=1");
args.push("DISABLE_EXCEPTION_CATCHING=0");
args.push("-O3");
}
else if (!project.debug)
{
args.push("-s");
args.push("DISABLE_EXCEPTION_CATCHING=0");
// args.push ("-s");
// args.push ("OUTLINING_LIMIT=70000");
args.push("-O2");
}
else
{
args.push("-gsource-map");
args.push("-s");
args.push("DISABLE_EXCEPTION_CATCHING=0");
args.push("-s");
args.push("NO_DISABLE_EXCEPTION_CATCHING=1");
args.push("DISABLE_EXCEPTION_CATCHING=2");
args.push("-s");
args.push("ASSERTIONS=1");
// args.push("-s");
// args.push("ASSERTIONS=2");
// args.push("-s");
// args.push("STACK_OVERFLOW_CHECK=2");
// args.push("-s");
// args.push("DEMANGLE_SUPPORT=1");
args.push("-O1");
}
// set initial size
// args.push("-s");
// args.push("INITIAL_MEMORY=32MB");
args.push("-s");
args.push("STACK_SIZE=1MB");
// args.push("-s");
// args.push("SAFE_HEAP=1");
// if (project.targetFlags.exists("final"))
// {
// args.push("-O3");
// }
// else if (!project.debug)
// {
// // args.push ("-s");
// // args.push ("OUTLINING_LIMIT=70000");
// args.push("-O2");
// }
// else
// {
// args.push("-O1");
// }
// https://github.com/HaxeFoundation/hxcpp/issues/987
args.push("-O0");
args.push("-s");
args.push("ALLOW_MEMORY_GROWTH=1");
@@ -288,24 +259,6 @@ class WebAssemblyPlatform extends PlatformTarget
System.runCommand(targetDirectory + "/obj", "emcc", args, true, false, true);
if (FileSystem.exists(outputFile))
{
var context = project.templateContext;
context.SOURCE_FILE = File.getContent(outputFile);
context.embeddedLibraries = [];
for (dependency in project.dependencies)
{
if (dependency.embed && StringTools.endsWith(dependency.path, ".js") && FileSystem.exists(dependency.path))
{
var script = File.getContent(dependency.path);
context.embeddedLibraries.push(script);
}
}
System.copyFileTemplate(project.templatePaths, "webassembly/output.js", outputFile, context);
}
if (project.targetFlags.exists("minify"))
{
HTML5Helper.minify(project, targetDirectory + "/bin/" + project.app.file + ".js");
@@ -340,7 +293,7 @@ class WebAssemblyPlatform extends PlatformTarget
public override function deploy():Void
{
DeploymentHelper.deploy(project, targetFlags, targetDirectory, "WebAssembly");
DeploymentHelper.deploy(project, targetFlags, targetDirectory, "Emscripten");
}
public override function display():Void
@@ -377,7 +330,7 @@ class WebAssemblyPlatform extends PlatformTarget
public override function rebuild():Void
{
CPPHelper.rebuild(project, [["-Dwebassembly", "-Dwasm", "-Demscripten", "-Dstatic_link"]]);
CPPHelper.rebuild(project, [["-Demscripten", "-Dstatic_link"]]);
}
public override function run():Void
@@ -402,10 +355,10 @@ class WebAssemblyPlatform extends PlatformTarget
}
}
// for (asset in project.assets)
// {
// asset.resourceName = "assets/" + asset.resourceName;
// }
for (asset in project.assets)
{
asset.resourceName = "assets/" + asset.resourceName;
}
var destination = targetDirectory + "/bin/";
System.mkdir(destination);
@@ -433,44 +386,6 @@ class WebAssemblyPlatform extends PlatformTarget
context.CPP_DIR = targetDirectory + "/obj";
context.USE_COMPRESSION = project.targetFlags.exists("compress");
context.favicons = [];
var icons = project.icons;
if (icons.length == 0)
{
icons = [new Icon(System.findTemplate(project.templatePaths, "default/icon.svg"))];
}
// if (IconHelper.createWindowsIcon (icons, Path.combine (destination, "favicon.ico"))) {
//
// context.favicons.push ({ rel: "icon", type: "image/x-icon", href: "./favicon.ico" });
//
// }
if (IconHelper.createIcon(icons, 192, 192, Path.combine(destination, "favicon.png")))
{
context.favicons.push({rel: "shortcut icon", type: "image/png", href: "./favicon.png"});
}
for (dependency in project.dependencies)
{
if (!dependency.embed)
{
if (StringTools.endsWith(dependency.name, ".js"))
{
context.linkedLibraries.push(dependency.name);
}
else if (StringTools.endsWith(dependency.path, ".js") && FileSystem.exists(dependency.path))
{
var name = Path.withoutDirectory(dependency.path);
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
}
}
}
for (asset in project.assets)
{
var path = Path.combine(targetDirectory + "/obj/assets", asset.targetPath);
@@ -486,11 +401,10 @@ class WebAssemblyPlatform extends PlatformTarget
}
}
ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/template", destination, context);
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/template", destination, context);
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/hxml", targetDirectory + "/haxe", context);
// ProjectHelper.recursiveSmartCopyTemplate(project, "webassembly/cpp", targetDirectory + "/obj", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "cpp/static", targetDirectory + "/obj", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/hxml", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/cpp", targetDirectory + "/obj", context);
for (asset in project.assets)
{