Skip to content

Commit

Permalink
⚡ Emscripten build parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
riidefi committed Aug 11, 2020
1 parent a80ed3d commit 6ad41e6
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions build_emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import sys
from itertools import chain

from multiprocessing.dummy import Pool as ThreadPool
import time

gPool = ThreadPool(4)

def require_dir(path):
# TODO: if not isdir, delete
if not os.path.exists(path):
Expand Down Expand Up @@ -121,20 +126,20 @@ def format_out(source, int_dir):
source.replace(".cpp", ".o").replace(".cxx", ".o").replace(".c", ".o").replace("\\", "_").replace("/", "_"))

def compile(source, int_dir, debug, config):

args = "em++ -I./ "
print("BUILD %s" % source)
args = "em++ -Wno-deprecated-volatile -Wno-inconsistent-missing-override -Wno-ambiguous-reversed-operator -I./ "
for proj in PROJECTS:
args += " -I./source/" + proj["name"] + " "
for d in DEFINES + defines(config):
args += " -D" + d
for incl in INCLUDES:
args += " -I./" + incl + " "
args += " -Wall -std=c++20 -D\"__debugbreak()\"=\"\""
args += " -s USE_SDL=2 -Wno-inconsistent-missing-override"
args += " -s USE_SDL=2 "
if debug:
args += " -g4 -O0 "
else:
args += " -O3 -flto "
args += " -O3 -flto"
args += " -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1 -c -o"
dst = format_out(source, int_dir)
args += " " + dst + " " + source
Expand All @@ -161,20 +166,22 @@ def build_project(name, type, config, proj=None):

cpp = get_sources("source/" + name, "**/*.cpp")
cxx = get_sources("source/" + name, "**/*.cxx")

for source in chain(cpp, cxx):
if "pybind11\\tests" in source:
continue

sources = chain(cpp, cxx)
sources = list(filter(lambda x: "pybind11\\tests" not in x, sources))
for source in sources:
locals_objs.append(format_out(source, bin_int_dir))
sources = list(filter(lambda x: not gHashManager.check(x, config), sources))
do_compile = lambda source: [ compile(source, bin_int_dir, debug, config), gHashManager.save(source, config)]

if gHashManager.check(source, config):
continue

compile(source, bin_int_dir, debug, config)
gHashManager.save(source, config)
if len(sources):
gPool.map(do_compile, sources)

if type == "main_app":
# Main app must be last
gPool.close()
gPool.join()
print("LINKING")

link_cmd = " -o " + bin_dir + "out.html -s USE_SDL=2 -s MAX_WEBGL_VERSION=2 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 --bind"
link_cmd += " --shell-file " + bin_dir + "/shell_minimal.html "
objs = locals_objs
Expand Down Expand Up @@ -207,6 +214,10 @@ def build_projects(config, rebuild):
cfg = "RELEASE"
if len(sys.argv) > 1:
cfg = sys.argv[1].upper()

start = time.time()
build_projects(cfg, len(sys.argv) > 2 and sys.argv[2] == "-rebuild")

gHashManager.store_to_file()
end = time.time()
print("Operation took %ss" % (end - start))

0 comments on commit 6ad41e6

Please sign in to comment.