Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made webidl work with the EMSDK environment variable #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.hl
*.js
*.bc
.vscode
37 changes: 26 additions & 11 deletions webidl/Generate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ template<typename T> pref<T> *_alloc_const( const T *value ) {
if( ret != 0 ) throw "Command '" + cmd + "' has exit with error code " + ret;
}

static function createDirectories(pathToFile) {
sys.FileSystem.createDirectory(haxe.io.Path.directory(pathToFile));
}

public static function generateJs( opts : Options, sources : Array<String>, ?params : Array<String> ) {
if( params == null )
params = [];
Expand All @@ -419,32 +423,43 @@ template<typename T> pref<T> *_alloc_const( const T *value ) {
var lib = opts.nativeLib;

var emSdk = Sys.getEnv("EMSCRIPTEN");
if( emSdk == null )
throw "Missing EMSCRIPTEN environment variable. Install emscripten";
if( emSdk == null ) {
emSdk = Sys.getEnv("EMSDK");
if (emSdk == null) {
throw "Missing EMSCRIPTEN and EMSDK environment variable. Install emscripten";
}

emSdk += "/upstream/emscripten";
}

emSdk = StringTools.replace(emSdk, "\\", "/");

var emcc = emSdk + "/emcc";

// build sources BC files
var outFiles = [];
sources.push(lib+".cpp");
//sources.push(lib+".cpp");
for( cfile in sources ) {
var out = opts.outputDir + cfile.substr(0, -4) + ".bc";
createDirectories(out);
var args = params.concat(["-c", cfile, "-o", out]);
command( emcc, args);
outFiles.push(out);
}

// link : because too many files, generate Makefile
var tmp = opts.outputDir + "Makefile.tmp";
// link : because too many files, create source file.
var tmp = opts.outputDir + "Sources.tmp";
var args = params.concat([
"-s", 'EXPORT_NAME="\'$lib\'"', "-s", "MODULARIZE=1",
'@$tmp',
"-s", 'EXPORT_NAME="$lib"', "-s", "MODULARIZE=1",
"--memory-init-file", "0",
"-o", '$lib.js'
]);
var output = "SOURCES = " + outFiles.join(" ") + "\n";
output += "all:\n";
output += "\t"+emcc+" $(SOURCES) " + args.join(" ");
sys.io.File.saveContent(tmp, output);
command("make", ["-f", tmp]);
var sourcesOutput = outFiles.join(" ") + "\n";
sys.io.File.saveContent(tmp, sourcesOutput);

command(emcc, args);

sys.FileSystem.deleteFile(tmp);
}

Expand Down
4 changes: 2 additions & 2 deletions webidl/Module.hx
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ class Module {
});

// For HL no initialization is required so execute the callback immediately
} else if (Context.defined("hl")) {
} else {
types.push(macro class Init {
public static function init(onReady:Void->Void) {
onReady();
}
});
}

Context.defineModule(module, types);
Context.registerModuleDependency(module, file);

Expand Down