Skip to content

Commit

Permalink
Extra options for Emscripten modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Maratyszcza committed Feb 26, 2017
1 parent f144955 commit 6e4b714
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
35 changes: 25 additions & 10 deletions confu/builds/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def _executable(self, name, object_files):
if self.target.is_wasm:
emflags += ["-s", "BINARYEN_METHOD=\\\"interpret-binary\\\""]
executable = CollectionResult("bin", name, object_files,
libraries=self._deps_libraries, filename=name + ".js",
libraries=self._deps_libraries, filename=name + self.target.executable_ext,
rule="executable", variables={
"linker": "$cxx", "emflags": " ".join(emflags)})
return executable

def plugin(self, name, object_files, functions=None, memory_size=None, aborting_malloc=True, no_exit_runtime=True, pre_js=None, post_js=None):
def plugin(self, name, object_files, functions=None, memory_size=None, aborting_malloc=True, no_exit_runtime=True, include_filesystem=None,
pre_js=None, post_js=None):

if not isinstance(object_files, (list, tuple)):
object_files = [object_files]
emflags = [
Expand All @@ -34,6 +36,7 @@ def plugin(self, name, object_files, functions=None, memory_size=None, aborting_
]
if self.target.is_wasm:
emflags += ["-s", "BINARYEN_METHOD=\\\"native-wasm\\\""]
emflags += ["-s", "BINARYEN_IMPRECISE=1"]
else:
emflags += ["-s", "PRECISE_F32=2"]

Expand All @@ -51,18 +54,30 @@ def plugin(self, name, object_files, functions=None, memory_size=None, aborting_
if memory_size is not all:
emflags += ["-s", "ABORTING_MALLOC=" + str(int(bool(aborting_malloc)))]

if pre_js is not None:
from confu.validators import validate_source_path
pre_js = validate_source_path(pre_js, self.source_dir)
emflags += ["--pre-js", pre_js]
if no_exit_runtime:
emflags += ["-s", "NO_EXIT_RUNTIME=1"]

if include_filesystem is not None:
if include_filesystem:
emflags += ["-s", "FORCE_FILESYSTEM=1"]
else:
emflags += ["-s", "NO_FILESYSTEM=1"]

extra_deps = list()
if pre_js is not None:
from confu.validators import validate_source_paths
for js_path in validate_source_paths(pre_js, self.source_dir):
extra_deps.append(js_path)
emflags += ["--pre-js", js_path]
if post_js is not None:
post_js = validate_source_path(post_js, self.source_dir)
emflags += ["--post-js", post_js]
from confu.validators import validate_source_paths
for js_path in validate_source_paths(post_js, self.source_dir):
extra_deps.append(js_path)
emflags += ["--post-js", js_path]

plugin = CollectionResult("out", name, object_files,
libraries=self._deps_libraries, filename=name + ".js",
rule="executable", variables={
libraries=self._deps_libraries, filename=name + self.target.executable_ext,
rule="executable", extra_deps=extra_deps, variables={
"linker": "$cxx", "emflags": " ".join(emflags)})
self.active_module.plugins.append(plugin)
return plugin
5 changes: 3 additions & 2 deletions confu/results/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class CollectionResult(BuildResult):
def __init__(self, subdir, name, objects, libraries=None, filename=None, rule=None, variables=dict()):
def __init__(self, subdir, name, objects, libraries=None, filename=None, rule=None, extra_deps=list(), variables=dict()):
super(CollectionResult, self).__init__()
if not isinstance(subdir, str):
raise TypeError("Unsupported type of subdir argument: string expected")
Expand All @@ -26,6 +26,7 @@ def __init__(self, subdir, name, objects, libraries=None, filename=None, rule=No
self.objects = objects
self.libraries = libraries
self.rule = rule
self.extra_deps = extra_deps
self.variables = variables

def get_target_path(self):
Expand All @@ -47,7 +48,7 @@ def generate(self, ninja):
object_files.append(object.get_target_path())

library_files = list()
implicit_deps = list()
implicit_deps = list(self.extra_deps)
if self.libraries:
for library in self.libraries:
assert isinstance(library, (CollectionResult, str))
Expand Down
13 changes: 13 additions & 0 deletions confu/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ def validate_source_path(source_path, source_dir):
return source_path


def validate_source_paths(source_paths, source_dir):
import collections
if isinstance(source_paths, str):
return [validate_source_path(source_paths, source_dir)]
elif isinstance(source_paths, collections.Mapping):
return sum((validate_source_paths(source_paths_collection, source_dir)
for source_paths_collection, platform_match in six.iteritems(source_paths) if platform_match), list())
elif isinstance(source_paths, collections.Iterable):
return [validate_source_path(source_path, source_dir) for source_path in source_paths]
else:
raise TypeError("Invalid type of source paths: string, mapping, or iterable expected")


def validate_export_function(name):
if not isinstance(name, str):
raise TypeError("Invalid type of function name: string expected")
Expand Down

0 comments on commit 6e4b714

Please sign in to comment.