def deps(**kwargs): print("[START] - deps") print("Checking for needed commands: " + ", ".join(c[0] for c in NEEDED_COMMANDS)) ensure_needed_commands() print("Creating build directory: '%s'" % BUILD_DIR_ABS) util.mkdir(BUILD_DIR_ABS) llvmdir = get_llvm_dir() print("Checking for LLVM: '%s'" % llvmdir) if not os.path.isdir(util.abspath_join(llvmdir, "lib")): util.svn_co(conf.LLVM_URL, llvmdir) clangdir = util.abspath_join(llvmdir, "tools/clang") print("Checking for Clang: '%s'" % clangdir) if not os.path.isdir(util.abspath_join(clangdir, "lib")): util.svn_co(conf.CLANG_URL, clangdir) compilerrtdir = util.abspath_join(llvmdir, "projects/compiler-rt") print("Checking for Compiler RT: '%s'" % compilerrtdir) if not os.path.isdir(util.abspath_join(compilerrtdir, "lib")): util.svn_co(conf.COMPILER_RT_URL, compilerrtdir) if not os.path.exists(util.abspath_join(llvmdir, "Makefile.config")): util.run_command(["./configure"], cwd=llvmdir) clang_path = get_clang_path() clangpp_path = get_clangpp_path() clang_found = util.is_exe(clang_path) and util.is_exe(clangpp_path) if not clang_found: util.run_command(["make"], cwd=llvmdir) clang_found = util.is_exe(clang_path) and util.is_exe(clangpp_path) if not clang_found: sys.stderr.write("Failed to build LLVM clang/clang++\n") sys.exit(1) print("Using clang: " + clang_path) print("Using clang++: " + clangpp_path) v8dir = util.abspath_join(BUILD_DIR_ABS, conf.V8_DIR) print("Checking for V8: '%s'" % v8dir) if not os.path.isdir(util.abspath_join(v8dir, "src")): util.svn_co(conf.V8_URL, v8dir) v8_path = get_v8_path() if not util.is_exe(v8_path): util.run_command(["scons", "d8"], cwd=v8dir) if not util.is_exe(v8_path): sys.stderr.write("Failed to build v8 d8 executable\n") sys.exit(1) print("Using d8: " + v8_path) closure_compiler_dir = util.abspath_join(BUILD_DIR_ABS, conf.CLOSURE_COMPILER_DIR) util.mkdir(closure_compiler_dir) closure_compiler_zip = util.abspath_join(closure_compiler_dir, "compiler-latest.zip") if not os.path.isfile(closure_compiler_zip): print("Downloading '%s' -> '%s'" % (conf.CLOSURE_COMPILER_URL, closure_compiler_zip)) urllib.urlretrieve(conf.CLOSURE_COMPILER_URL, closure_compiler_zip) closure_compiler = get_closure_compiler_path() if not os.path.isfile(closure_compiler): z = zipfile.ZipFile(closure_compiler_zip) z.extractall(path=closure_compiler_dir) if not os.path.isfile(closure_compiler): sys.stderr.write("Failed to get closure compiler\n") sys.exit(1) print("Using compiler.jar: " + closure_compiler) spidermonkey_dir = util.abspath_join(BUILD_DIR_ABS, conf.SPIDERMONKEY_DIR) print("Checking for SpiderMonkey: '%s'" % spidermonkey_dir) if not os.path.isdir(util.abspath_join(spidermonkey_dir, "browser")): util.hg_clone(conf.SPIDERMONKEY_URL, spidermonkey_dir, conf.SPIDERMONKEY_TAG) spidermonkey_build_dir = util.abspath_join(spidermonkey_dir, "js/src") spidermonkey_path = get_spidermonkey_path() if not os.path.isfile(util.abspath_join(spidermonkey_build_dir, "configure")): util.run_command(["autoreconf2.13"], cwd=spidermonkey_build_dir) if not os.path.isfile(util.abspath_join(spidermonkey_build_dir, "Makefile")): util.run_command(["./configure"], cwd=spidermonkey_build_dir) if not util.is_exe(spidermonkey_path): util.run_command(["make"], cwd=spidermonkey_build_dir) if not util.is_exe(spidermonkey_path): sys.stderr.write("Failed to build SpiderMonkey js executable\n") sys.exit(1) print("Using js: " + spidermonkey_path) nodejs_dir = util.abspath_join(BUILD_DIR_ABS, conf.NODEJS_DIR) util.mkdir(nodejs_dir) nodejs_tgz = util.abspath_join(nodejs_dir, os.path.basename(conf.NODEJS_URL)) if not os.path.isfile(nodejs_tgz): print("Downloading '%s' -> '%s'" % (conf.NODEJS_URL, nodejs_tgz)) urllib.urlretrieve(conf.NODEJS_URL, nodejs_tgz) nodejs_dir_path = get_nodejs_dir() if not os.path.isfile(util.abspath_join(nodejs_dir_path, "./configure")): print("Extracting '%s' -> '%s'" % (nodejs_tgz, nodejs_dir)) t = tarfile.open(nodejs_tgz) t.extractall(path=nodejs_dir) nodejs_path = get_nodejs_path() if not util.is_exe(nodejs_path): util.run_command(["./configure"], cwd=nodejs_dir_path) util.run_command(["make"], cwd=nodejs_dir_path) if not util.is_exe(nodejs_path): sys.stderr.write("Failed to build nodejs.\n") sys.exit(1) print("Using node: " + nodejs_path) emscripten_dir = get_emscripten_dir() print("Checking for emscripten: '%s'" % emscripten_dir) if not util.is_exe(util.abspath_join(emscripten_dir, "emscripten.py")): sys.stderr.write("Could not find emscripten.py in emscripten directory '%s'.\n" % emscripten_dir) sys.stderr.write("Did you forget to run 'git submodule update --init --recursive' after cloning?\n") sys.exit(1) emscripten.write_emscripten_config(get_llvm_bindir(), get_v8_path(), get_closure_compiler_path(), get_emscripten_dir(), get_spidermonkey_path(), get_nodejs_path()) print("[DONE] - deps")
def compile(**kwargs): print("[START] - compile") mozdir = util.abspath_join(BUILD_DIR_ABS, conf.MOZILLA_CENTRAL_DIR) js_src_dir = util.abspath_join(mozdir, "js/src") if not os.path.isdir(util.abspath_join(mozdir, "browser")): util.hg_clone(conf.MOZILLA_CENTRAL_URL, mozdir, conf.MOZILLA_CENTRAL_TAG) print("Using mozilla-central js/src directory: '%s'" % js_src_dir) if kwargs.get('clean', False): try: shutil.rmtree(js_src_dir) except OSError: pass util.run_command(["hg", "revert", "js/src"], cwd=mozdir) if not util.is_exe(util.abspath_join(js_src_dir, "./configure")): util.run_command(["autoreconf2.13"], cwd=js_src_dir) emconfigure = get_emconfigure_path() configure_line = [emconfigure, "./configure", "--disable-methodjit", "--disable-monoic", "--disable-polyic", "--disable-tracejit", "--disable-methodjit-spew", "--disable-tests", "--disable-debug", "--disable-optimize" ] makefile_path = util.abspath_join(js_src_dir, "./Makefile") if not os.path.isfile(makefile_path): util.run_command(configure_line, cwd=js_src_dir) filter_file(makefile_path, compile_filters.makefile_filters) jsapi_h_path = util.abspath_join(js_src_dir, "./jsapi.h") filter_file(jsapi_h_path, compile_filters.jsapi_filters) MacroAssemblerX86Common_h_path = util.abspath_join(js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.h") filter_file(MacroAssemblerX86Common_h_path, compile_filters.MacroAssemblerX86Common_filters) MacroAssemblerX86Common_cpp_path = util.abspath_join(js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.cpp") filter_file(MacroAssemblerX86Common_cpp_path, compile_filters.MacroAssemblerX86Common_cpp_filters) expandlibs_config_path = util.abspath_join(js_src_dir, "./config/expandlibs_config.py") filter_file(expandlibs_config_path, compile_filters.expandlibs_config_filters) jsgcchunk_cpp_path = util.abspath_join(js_src_dir, "./jsgcchunk.cpp") filter_file(jsgcchunk_cpp_path, compile_filters.jsgchunk_cpp_filters) jsinfer_cpp_path = util.abspath_join(js_src_dir, "./jsinfer.cpp") filter_file(jsinfer_cpp_path, compile_filters.jsinfer_cpp_filters) platform_h_path = util.abspath_join(js_src_dir, "./assembler/wtf/Platform.h") filter_file(platform_h_path, compile_filters.platform_h_filters) pcre_exec_cpp_path = util.abspath_join(js_src_dir, "./yarr/pcre/pcre_exec.cpp") filter_file(pcre_exec_cpp_path, compile_filters.pcre_exec_cpp_filters) jsval_h_path = util.abspath_join(js_src_dir, "./jsval.h") filter_file(jsval_h_path, compile_filters.jsval_h_filters) jsinterp_cpp_path = util.abspath_join(js_src_dir, "./jsinterp.cpp") filter_file(jsinterp_cpp_path, compile_filters.jsinterp_cpp_filters) js_shell_bc_out = util.abspath_join(js_src_dir, "./shell/js") libjs_static_out = util.abspath_join(js_src_dir, "./libjs_static.a") make_success = os.path.exists(libjs_static_out) and os.path.exists(js_shell_bc_out) if not make_success: util.run_command(["make", "-C", "config"], cwd=js_src_dir) util.run_command(["make", "jsautocfg.h"], cwd=js_src_dir) jscpucfg_h_path = util.abspath_join(js_src_dir, "./jscpucfg.h") filter_file(jscpucfg_h_path, compile_filters.jscpucfg_filters) jsautocfg_h_path = util.abspath_join(js_src_dir, "./jsautocfg.h") filter_file(jsautocfg_h_path, compile_filters.jscpucfg_filters) jsconfig_h_path = util.abspath_join(js_src_dir, "./js-config.h") filter_file(jsconfig_h_path, compile_filters.jsconfig_filters) jsconfdefs_h_path = util.abspath_join(js_src_dir, "./js-confdefs.h") filter_file(jsconfdefs_h_path, compile_filters.jsconfdefs_filters) jstypes_h_path = util.abspath_join(js_src_dir, "./jstypes.h") filter_file(jstypes_h_path, compile_filters.jstypes_h_filters) util.run_command(["make"], cwd=js_src_dir, added_env={"EMCC_DEBUG": "1"}) make_success = os.path.exists(libjs_static_out) and os.path.exists(js_shell_bc_out) if not make_success: sys.stderr.write("Failed to build spidermonkey. Exiting.\n") sys.exit(1) o_files = subprocess.check_output([get_llvm_ar_path(), 't', libjs_static_out]).strip().split("\n") js_combined_bc = util.abspath_join(BUILD_DIR_ABS, "./js_combined.bc") js_combined_ll = util.abspath_join(BUILD_DIR_ABS, "./js_combined.ll") libjs_ll = util.abspath_join(BUILD_DIR_ABS, "./libjs.ll") libjs_bc = util.abspath_join(BUILD_DIR_ABS, "./libjs.bc") command = [get_llvm_link_path(), '-o', libjs_bc] command.extend(o_files) util.run_command(command, cwd=js_src_dir) util.run_command([get_llvm_dis_path(), '-show-annotations', '-o', libjs_ll, libjs_bc]) js_shell_o_out = util.abspath_join(js_src_dir, "./shell/js.o") jsheaptools_o = util.abspath_join(js_src_dir, "./shell/jsheaptools.o") jsoptparse_o = util.abspath_join(js_src_dir, "./shell/jsoptparse.o") jsworkers_o = util.abspath_join(js_src_dir, "./shell/jsworkers.o") util.run_command([get_llvm_link_path(), '-o', js_combined_bc, libjs_bc, js_shell_o_out, jsheaptools_o, jsoptparse_o, jsworkers_o]) util.run_command([get_llvm_dis_path(), '-show-annotations', '-o', js_combined_ll, js_combined_bc]) if not os.path.isfile(js_combined_ll): sys.stderr.write("Failed to build combined LLVM file.\n") sys.exit(1) print("Built LLVM file:\n -- %s" % js_combined_ll) print(" -- %g MB" % (float(os.path.getsize(js_combined_ll)) / 1024 / 1024,)) print("[DONE] - compile")
def compile(**kwargs): print("[START] - compile") mozdir = util.abspath_join(BUILD_DIR_ABS, conf.MOZILLA_CENTRAL_DIR) js_src_dir = util.abspath_join(mozdir, "js/src") if not os.path.isdir(util.abspath_join(mozdir, "browser")): util.hg_clone(conf.MOZILLA_CENTRAL_URL, mozdir, conf.MOZILLA_CENTRAL_TAG) print("Using mozilla-central js/src directory: '%s'" % js_src_dir) if kwargs.get('clean', False): try: shutil.rmtree(js_src_dir) except OSError: pass util.run_command(["hg", "revert", "js/src"], cwd=mozdir) if not util.is_exe(util.abspath_join(js_src_dir, "./configure")): util.run_command(["autoreconf2.13"], cwd=js_src_dir) emconfigure = get_emconfigure_path() configure_line = [ emconfigure, "./configure", "--disable-methodjit", "--disable-monoic", "--disable-polyic", "--disable-tracejit", "--disable-methodjit-spew", "--disable-tests", "--disable-debug", "--disable-optimize" ] makefile_path = util.abspath_join(js_src_dir, "./Makefile") if not os.path.isfile(makefile_path): util.run_command(configure_line, cwd=js_src_dir) filter_file(makefile_path, compile_filters.makefile_filters) jsapi_h_path = util.abspath_join(js_src_dir, "./jsapi.h") filter_file(jsapi_h_path, compile_filters.jsapi_filters) MacroAssemblerX86Common_h_path = util.abspath_join( js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.h") filter_file(MacroAssemblerX86Common_h_path, compile_filters.MacroAssemblerX86Common_filters) MacroAssemblerX86Common_cpp_path = util.abspath_join( js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.cpp") filter_file(MacroAssemblerX86Common_cpp_path, compile_filters.MacroAssemblerX86Common_cpp_filters) expandlibs_config_path = util.abspath_join( js_src_dir, "./config/expandlibs_config.py") filter_file(expandlibs_config_path, compile_filters.expandlibs_config_filters) jsgcchunk_cpp_path = util.abspath_join(js_src_dir, "./jsgcchunk.cpp") filter_file(jsgcchunk_cpp_path, compile_filters.jsgchunk_cpp_filters) jsinfer_cpp_path = util.abspath_join(js_src_dir, "./jsinfer.cpp") filter_file(jsinfer_cpp_path, compile_filters.jsinfer_cpp_filters) platform_h_path = util.abspath_join(js_src_dir, "./assembler/wtf/Platform.h") filter_file(platform_h_path, compile_filters.platform_h_filters) pcre_exec_cpp_path = util.abspath_join(js_src_dir, "./yarr/pcre/pcre_exec.cpp") filter_file(pcre_exec_cpp_path, compile_filters.pcre_exec_cpp_filters) jsval_h_path = util.abspath_join(js_src_dir, "./jsval.h") filter_file(jsval_h_path, compile_filters.jsval_h_filters) jsinterp_cpp_path = util.abspath_join(js_src_dir, "./jsinterp.cpp") filter_file(jsinterp_cpp_path, compile_filters.jsinterp_cpp_filters) js_shell_bc_out = util.abspath_join(js_src_dir, "./shell/js") libjs_static_out = util.abspath_join(js_src_dir, "./libjs_static.a") make_success = os.path.exists(libjs_static_out) and os.path.exists( js_shell_bc_out) if not make_success: util.run_command(["make", "-C", "config"], cwd=js_src_dir) util.run_command(["make", "jsautocfg.h"], cwd=js_src_dir) jscpucfg_h_path = util.abspath_join(js_src_dir, "./jscpucfg.h") filter_file(jscpucfg_h_path, compile_filters.jscpucfg_filters) jsautocfg_h_path = util.abspath_join(js_src_dir, "./jsautocfg.h") filter_file(jsautocfg_h_path, compile_filters.jscpucfg_filters) jsconfig_h_path = util.abspath_join(js_src_dir, "./js-config.h") filter_file(jsconfig_h_path, compile_filters.jsconfig_filters) jsconfdefs_h_path = util.abspath_join(js_src_dir, "./js-confdefs.h") filter_file(jsconfdefs_h_path, compile_filters.jsconfdefs_filters) jstypes_h_path = util.abspath_join(js_src_dir, "./jstypes.h") filter_file(jstypes_h_path, compile_filters.jstypes_h_filters) util.run_command(["make"], cwd=js_src_dir, added_env={"EMCC_DEBUG": "1"}) make_success = os.path.exists(libjs_static_out) and os.path.exists( js_shell_bc_out) if not make_success: sys.stderr.write("Failed to build spidermonkey. Exiting.\n") sys.exit(1) o_files = subprocess.check_output( [get_llvm_ar_path(), 't', libjs_static_out]).strip().split("\n") js_combined_bc = util.abspath_join(BUILD_DIR_ABS, "./js_combined.bc") js_combined_ll = util.abspath_join(BUILD_DIR_ABS, "./js_combined.ll") libjs_ll = util.abspath_join(BUILD_DIR_ABS, "./libjs.ll") libjs_bc = util.abspath_join(BUILD_DIR_ABS, "./libjs.bc") command = [get_llvm_link_path(), '-o', libjs_bc] command.extend(o_files) util.run_command(command, cwd=js_src_dir) util.run_command( [get_llvm_dis_path(), '-show-annotations', '-o', libjs_ll, libjs_bc]) js_shell_o_out = util.abspath_join(js_src_dir, "./shell/js.o") jsheaptools_o = util.abspath_join(js_src_dir, "./shell/jsheaptools.o") jsoptparse_o = util.abspath_join(js_src_dir, "./shell/jsoptparse.o") jsworkers_o = util.abspath_join(js_src_dir, "./shell/jsworkers.o") util.run_command([ get_llvm_link_path(), '-o', js_combined_bc, libjs_bc, js_shell_o_out, jsheaptools_o, jsoptparse_o, jsworkers_o ]) util.run_command([ get_llvm_dis_path(), '-show-annotations', '-o', js_combined_ll, js_combined_bc ]) if not os.path.isfile(js_combined_ll): sys.stderr.write("Failed to build combined LLVM file.\n") sys.exit(1) print("Built LLVM file:\n -- %s" % js_combined_ll) print(" -- %g MB" % (float(os.path.getsize(js_combined_ll)) / 1024 / 1024, )) print("[DONE] - compile")
def deps(**kwargs): print("[START] - deps") print("Checking for needed commands: " + ", ".join(c[0] for c in NEEDED_COMMANDS)) ensure_needed_commands() print("Creating build directory: '%s'" % BUILD_DIR_ABS) util.mkdir(BUILD_DIR_ABS) llvmdir = get_llvm_dir() print("Checking for LLVM: '%s'" % llvmdir) if not os.path.isdir(util.abspath_join(llvmdir, "lib")): util.svn_co(conf.LLVM_URL, llvmdir) clangdir = util.abspath_join(llvmdir, "tools/clang") print("Checking for Clang: '%s'" % clangdir) if not os.path.isdir(util.abspath_join(clangdir, "lib")): util.svn_co(conf.CLANG_URL, clangdir) compilerrtdir = util.abspath_join(llvmdir, "projects/compiler-rt") print("Checking for Compiler RT: '%s'" % compilerrtdir) if not os.path.isdir(util.abspath_join(compilerrtdir, "lib")): util.svn_co(conf.COMPILER_RT_URL, compilerrtdir) if not os.path.exists(util.abspath_join(llvmdir, "Makefile.config")): util.run_command(["./configure"], cwd=llvmdir) clang_path = get_clang_path() clangpp_path = get_clangpp_path() clang_found = util.is_exe(clang_path) and util.is_exe(clangpp_path) if not clang_found: util.run_command(["make"], cwd=llvmdir) clang_found = util.is_exe(clang_path) and util.is_exe(clangpp_path) if not clang_found: sys.stderr.write("Failed to build LLVM clang/clang++\n") sys.exit(1) print("Using clang: " + clang_path) print("Using clang++: " + clangpp_path) v8dir = util.abspath_join(BUILD_DIR_ABS, conf.V8_DIR) print("Checking for V8: '%s'" % v8dir) if not os.path.isdir(util.abspath_join(v8dir, "src")): util.svn_co(conf.V8_URL, v8dir) v8_path = get_v8_path() if not util.is_exe(v8_path): util.run_command(["scons", "d8"], cwd=v8dir) if not util.is_exe(v8_path): sys.stderr.write("Failed to build v8 d8 executable\n") sys.exit(1) print("Using d8: " + v8_path) closure_compiler_dir = util.abspath_join(BUILD_DIR_ABS, conf.CLOSURE_COMPILER_DIR) util.mkdir(closure_compiler_dir) closure_compiler_zip = util.abspath_join(closure_compiler_dir, "compiler-latest.zip") if not os.path.isfile(closure_compiler_zip): print("Downloading '%s' -> '%s'" % (conf.CLOSURE_COMPILER_URL, closure_compiler_zip)) urllib.urlretrieve(conf.CLOSURE_COMPILER_URL, closure_compiler_zip) closure_compiler = get_closure_compiler_path() if not os.path.isfile(closure_compiler): z = zipfile.ZipFile(closure_compiler_zip) z.extractall(path=closure_compiler_dir) if not os.path.isfile(closure_compiler): sys.stderr.write("Failed to get closure compiler\n") sys.exit(1) print("Using compiler.jar: " + closure_compiler) spidermonkey_dir = util.abspath_join(BUILD_DIR_ABS, conf.SPIDERMONKEY_DIR) print("Checking for SpiderMonkey: '%s'" % spidermonkey_dir) if not os.path.isdir(util.abspath_join(spidermonkey_dir, "browser")): util.hg_clone(conf.SPIDERMONKEY_URL, spidermonkey_dir, conf.SPIDERMONKEY_TAG) spidermonkey_build_dir = util.abspath_join(spidermonkey_dir, "js/src") spidermonkey_path = get_spidermonkey_path() if not os.path.isfile( util.abspath_join(spidermonkey_build_dir, "configure")): util.run_command(["autoreconf2.13"], cwd=spidermonkey_build_dir) if not os.path.isfile(util.abspath_join(spidermonkey_build_dir, "Makefile")): util.run_command(["./configure"], cwd=spidermonkey_build_dir) if not util.is_exe(spidermonkey_path): util.run_command(["make"], cwd=spidermonkey_build_dir) if not util.is_exe(spidermonkey_path): sys.stderr.write("Failed to build SpiderMonkey js executable\n") sys.exit(1) print("Using js: " + spidermonkey_path) nodejs_dir = util.abspath_join(BUILD_DIR_ABS, conf.NODEJS_DIR) util.mkdir(nodejs_dir) nodejs_tgz = util.abspath_join(nodejs_dir, os.path.basename(conf.NODEJS_URL)) if not os.path.isfile(nodejs_tgz): print("Downloading '%s' -> '%s'" % (conf.NODEJS_URL, nodejs_tgz)) urllib.urlretrieve(conf.NODEJS_URL, nodejs_tgz) nodejs_dir_path = get_nodejs_dir() if not os.path.isfile(util.abspath_join(nodejs_dir_path, "./configure")): print("Extracting '%s' -> '%s'" % (nodejs_tgz, nodejs_dir)) t = tarfile.open(nodejs_tgz) t.extractall(path=nodejs_dir) nodejs_path = get_nodejs_path() if not util.is_exe(nodejs_path): util.run_command(["./configure"], cwd=nodejs_dir_path) util.run_command(["make"], cwd=nodejs_dir_path) if not util.is_exe(nodejs_path): sys.stderr.write("Failed to build nodejs.\n") sys.exit(1) print("Using node: " + nodejs_path) emscripten_dir = get_emscripten_dir() print("Checking for emscripten: '%s'" % emscripten_dir) if not util.is_exe(util.abspath_join(emscripten_dir, "emscripten.py")): sys.stderr.write( "Could not find emscripten.py in emscripten directory '%s'.\n" % emscripten_dir) sys.stderr.write( "Did you forget to run 'git submodule update --init --recursive' after cloning?\n" ) sys.exit(1) emscripten.write_emscripten_config(get_llvm_bindir(), get_v8_path(), get_closure_compiler_path(), get_emscripten_dir(), get_spidermonkey_path(), get_nodejs_path(), ['-Wno-return-type-c-linkage']) print("[DONE] - deps")
def compile(**kwargs): print("[START] - compile") mozdir = util.abspath_join(BUILD_DIR_ABS, conf.SPIDERMONKEY_DIR) js_src_dir = util.abspath_join(mozdir, "js/src") spidermonkey_build_path = util.abspath_join(js_src_dir, "results_js") print("Using SpiderMonkey js/src directory: '%s'" % js_src_dir) # clean up the spidermonkey folder if os.path.exists(spidermonkey_build_path): shutil.rmtree(spidermonkey_build_path) os.makedirs(spidermonkey_build_path) #util.run_command(["hg", "revert"], cwd=mozdir) #os.remove(util.abspath_join(js_src_dir, "configure")) if not util.is_exe(util.abspath_join(js_src_dir, "./configure")): util.run_command(["autoreconf2.13"], cwd=js_src_dir) emconfigure = get_emconfigure_path() configure_line = [emconfigure, "../configure", "--disable-methodjit", "--disable-monoic", "--disable-polyic", "--disable-tracejit", "--disable-methodjit-spew", "--disable-tests", "--disable-debug", "--disable-optimize" ] os.environ['EMCC_LLVM_TARGET'] = 'i386-pc-linux-gnu' # Avoid vaarg type issues in Emscripten makefile_path = util.abspath_join(spidermonkey_build_path, "./Makefile") if not os.path.isfile(makefile_path): util.run_command(configure_line, cwd=spidermonkey_build_path) filter_file(makefile_path, compile_filters.makefile_filters) jsapi_h_path = util.abspath_join(js_src_dir, "./jsapi.h") filter_file(jsapi_h_path, compile_filters.jsapi_filters) MacroAssemblerX86Common_h_path = util.abspath_join(js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.h") filter_file(MacroAssemblerX86Common_h_path, compile_filters.MacroAssemblerX86Common_filters) MacroAssemblerX86Common_cpp_path = util.abspath_join(js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.cpp") filter_file(MacroAssemblerX86Common_cpp_path, compile_filters.MacroAssemblerX86Common_cpp_filters) ExecutableAllocator_h_path = util.abspath_join(js_src_dir, "./assembler/jit/ExecutableAllocator.h") filter_file(ExecutableAllocator_h_path, compile_filters.ExecutableAllocator_filters) expandlibs_config_path = util.abspath_join(spidermonkey_build_path, "./config/expandlibs_config.py") filter_file(expandlibs_config_path, compile_filters.expandlibs_config_filters) jsgcchunk_cpp_path = util.abspath_join(js_src_dir, "./jsgcchunk.cpp") filter_file(jsgcchunk_cpp_path, compile_filters.jsgchunk_cpp_filters) jsinfer_cpp_path = util.abspath_join(js_src_dir, "./jsinfer.cpp") filter_file(jsinfer_cpp_path, compile_filters.jsinfer_cpp_filters) platform_h_path = util.abspath_join(js_src_dir, "./assembler/wtf/Platform.h") filter_file(platform_h_path, compile_filters.platform_h_filters) pcre_exec_cpp_path = util.abspath_join(js_src_dir, "./yarr/pcre/pcre_exec.cpp") filter_file(pcre_exec_cpp_path, compile_filters.pcre_exec_cpp_filters) jsval_h_path = util.abspath_join(js_src_dir, "./jsval.h") filter_file(jsval_h_path, compile_filters.jsval_h_filters) jsinterp_cpp_path = util.abspath_join(js_src_dir, "./jsinterp.cpp") filter_file(jsinterp_cpp_path, compile_filters.jsinterp_cpp_filters) js_shell_bc_out = util.abspath_join(spidermonkey_build_path, "./shell/js") libjs_static_out = util.abspath_join(spidermonkey_build_path, "./libjs_static.a") make_success = os.path.exists(libjs_static_out) and os.path.exists(js_shell_bc_out) if not make_success: js_dist_path = util.abspath_join(spidermonkey_build_path, "dist") if not os.path.exists(js_dist_path): os.makedirs(js_dist_path) js_bin_path = util.abspath_join(js_dist_path, "bin") if not os.path.islink(js_bin_path): os.symlink(util.abspath_join(get_native_spidermonkey_exes_path(), "dist/bin"), js_bin_path) util.run_command(["make", "-C", "config"], cwd=spidermonkey_build_path) util.run_command(["make", "jsautocfg.h"], cwd=spidermonkey_build_path) jscpucfg_h_path = util.abspath_join(js_src_dir, "./jscpucfg.h") filter_file(jscpucfg_h_path, compile_filters.jscpucfg_filters) jsautocfg_h_path = util.abspath_join(spidermonkey_build_path, "./jsautocfg.h") filter_file(jsautocfg_h_path, compile_filters.jscpucfg_filters) jsconfig_h_path = util.abspath_join(spidermonkey_build_path, "./js-config.h") filter_file(jsconfig_h_path, compile_filters.jsconfig_filters) jsconfdefs_h_path = util.abspath_join(spidermonkey_build_path, "./js-confdefs.h") filter_file(jsconfdefs_h_path, compile_filters.jsconfdefs_filters) jstypes_h_path = util.abspath_join(js_src_dir, "./jstypes.h") filter_file(jstypes_h_path, compile_filters.jstypes_h_filters) build_args = ['make'] opt_level = kwargs['O'] if opt_level != 0: build_args.extend(['-j7']) util.run_command(build_args, cwd=spidermonkey_build_path, added_env={"EMCC_DEBUG": "1"}) make_success = os.path.exists(libjs_static_out) and os.path.exists(js_shell_bc_out) if not make_success: sys.stderr.write("Failed to build spidermonkey. Exiting.\n") sys.exit(1) o_files = subprocess.check_output([get_llvm_ar_path(), 't', libjs_static_out]).strip().split("\n") js_combined_bc = util.abspath_join(BUILD_DIR_ABS, "./js_combined.bc") js_combined_ll = util.abspath_join(BUILD_DIR_ABS, "./js_combined.ll") libjs_ll = util.abspath_join(BUILD_DIR_ABS, "./libjs.ll") libjs_bc = util.abspath_join(BUILD_DIR_ABS, "./libjs.bc") command = [get_llvm_link_path(), '-o', libjs_bc] command.extend(o_files) util.run_command(command, cwd=spidermonkey_build_path) util.run_command([get_llvm_dis_path(), '-show-annotations', '-o', libjs_ll, libjs_bc]) js_shell_o_out = util.abspath_join(spidermonkey_build_path, "./shell/js.o") jsheaptools_o = util.abspath_join(spidermonkey_build_path, "./shell/jsheaptools.o") jsoptparse_o = util.abspath_join(spidermonkey_build_path, "./shell/jsoptparse.o") jsworkers_o = util.abspath_join(spidermonkey_build_path, "./shell/jsworkers.o") util.run_command([get_llvm_link_path(), '-o', js_combined_bc, libjs_bc, js_shell_o_out, jsheaptools_o, jsoptparse_o, jsworkers_o]) util.run_command([get_llvm_dis_path(), '-show-annotations', '-o', js_combined_ll, js_combined_bc]) if not os.path.isfile(js_combined_ll): sys.stderr.write("Failed to build combined LLVM file.\n") sys.exit(1) print("Built LLVM file:\n -- %s" % js_combined_ll) print(" -- %g MB" % (float(os.path.getsize(js_combined_ll)) / 1024 / 1024,)) print("[DONE] - compile")
def compile(**kwargs): print("[START] - compile") mozdir = util.abspath_join(BUILD_DIR_ABS, conf.SPIDERMONKEY_DIR) js_src_dir = util.abspath_join(mozdir, "js/src") spidermonkey_build_path = util.abspath_join(js_src_dir, "results_js") print("Using SpiderMonkey js/src directory: '%s'" % js_src_dir) # clean up the spidermonkey folder if os.path.exists(spidermonkey_build_path): shutil.rmtree(spidermonkey_build_path) os.makedirs(spidermonkey_build_path) #util.run_command(["hg", "revert"], cwd=mozdir) #os.remove(util.abspath_join(js_src_dir, "configure")) if not util.is_exe(util.abspath_join(js_src_dir, "./configure")): util.run_command(["autoreconf2.13"], cwd=js_src_dir) emconfigure = get_emconfigure_path() configure_line = [ emconfigure, "../configure", "--disable-methodjit", "--disable-monoic", "--disable-polyic", "--disable-tracejit", "--disable-methodjit-spew", "--disable-tests", "--disable-debug", "--disable-optimize" ] os.environ[ 'EMCC_LLVM_TARGET'] = 'i386-pc-linux-gnu' # Avoid vaarg type issues in Emscripten makefile_path = util.abspath_join(spidermonkey_build_path, "./Makefile") if not os.path.isfile(makefile_path): util.run_command(configure_line, cwd=spidermonkey_build_path) filter_file(makefile_path, compile_filters.makefile_filters) jsapi_h_path = util.abspath_join(js_src_dir, "./jsapi.h") filter_file(jsapi_h_path, compile_filters.jsapi_filters) MacroAssemblerX86Common_h_path = util.abspath_join( js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.h") filter_file(MacroAssemblerX86Common_h_path, compile_filters.MacroAssemblerX86Common_filters) MacroAssemblerX86Common_cpp_path = util.abspath_join( js_src_dir, "./assembler/assembler/MacroAssemblerX86Common.cpp") filter_file(MacroAssemblerX86Common_cpp_path, compile_filters.MacroAssemblerX86Common_cpp_filters) ExecutableAllocator_h_path = util.abspath_join( js_src_dir, "./assembler/jit/ExecutableAllocator.h") filter_file(ExecutableAllocator_h_path, compile_filters.ExecutableAllocator_filters) expandlibs_config_path = util.abspath_join( spidermonkey_build_path, "./config/expandlibs_config.py") filter_file(expandlibs_config_path, compile_filters.expandlibs_config_filters) jsgcchunk_cpp_path = util.abspath_join(js_src_dir, "./jsgcchunk.cpp") filter_file(jsgcchunk_cpp_path, compile_filters.jsgchunk_cpp_filters) jsinfer_cpp_path = util.abspath_join(js_src_dir, "./jsinfer.cpp") filter_file(jsinfer_cpp_path, compile_filters.jsinfer_cpp_filters) platform_h_path = util.abspath_join(js_src_dir, "./assembler/wtf/Platform.h") filter_file(platform_h_path, compile_filters.platform_h_filters) pcre_exec_cpp_path = util.abspath_join(js_src_dir, "./yarr/pcre/pcre_exec.cpp") filter_file(pcre_exec_cpp_path, compile_filters.pcre_exec_cpp_filters) jsval_h_path = util.abspath_join(js_src_dir, "./jsval.h") filter_file(jsval_h_path, compile_filters.jsval_h_filters) jsinterp_cpp_path = util.abspath_join(js_src_dir, "./jsinterp.cpp") filter_file(jsinterp_cpp_path, compile_filters.jsinterp_cpp_filters) js_shell_bc_out = util.abspath_join(spidermonkey_build_path, "./shell/js") libjs_static_out = util.abspath_join(spidermonkey_build_path, "./libjs_static.a") make_success = os.path.exists(libjs_static_out) and os.path.exists( js_shell_bc_out) if not make_success: js_dist_path = util.abspath_join(spidermonkey_build_path, "dist") if not os.path.exists(js_dist_path): os.makedirs(js_dist_path) js_bin_path = util.abspath_join(js_dist_path, "bin") if not os.path.islink(js_bin_path): os.symlink( util.abspath_join(get_native_spidermonkey_exes_path(), "dist/bin"), js_bin_path) util.run_command(["make", "-C", "config"], cwd=spidermonkey_build_path) util.run_command(["make", "jsautocfg.h"], cwd=spidermonkey_build_path) jscpucfg_h_path = util.abspath_join(js_src_dir, "./jscpucfg.h") filter_file(jscpucfg_h_path, compile_filters.jscpucfg_filters) jsautocfg_h_path = util.abspath_join(spidermonkey_build_path, "./jsautocfg.h") filter_file(jsautocfg_h_path, compile_filters.jscpucfg_filters) jsconfig_h_path = util.abspath_join(spidermonkey_build_path, "./js-config.h") filter_file(jsconfig_h_path, compile_filters.jsconfig_filters) jsconfdefs_h_path = util.abspath_join(spidermonkey_build_path, "./js-confdefs.h") filter_file(jsconfdefs_h_path, compile_filters.jsconfdefs_filters) jstypes_h_path = util.abspath_join(js_src_dir, "./jstypes.h") filter_file(jstypes_h_path, compile_filters.jstypes_h_filters) build_args = ['make'] opt_level = kwargs['O'] if opt_level != 0: build_args.extend(['-j7']) util.run_command(build_args, cwd=spidermonkey_build_path, added_env={"EMCC_DEBUG": "1"}) make_success = os.path.exists(libjs_static_out) and os.path.exists( js_shell_bc_out) if not make_success: sys.stderr.write("Failed to build spidermonkey. Exiting.\n") sys.exit(1) o_files = subprocess.check_output( [get_llvm_ar_path(), 't', libjs_static_out]).strip().split("\n") js_combined_bc = util.abspath_join(BUILD_DIR_ABS, "./js_combined.bc") js_combined_ll = util.abspath_join(BUILD_DIR_ABS, "./js_combined.ll") libjs_ll = util.abspath_join(BUILD_DIR_ABS, "./libjs.ll") libjs_bc = util.abspath_join(BUILD_DIR_ABS, "./libjs.bc") command = [get_llvm_link_path(), '-o', libjs_bc] command.extend(o_files) util.run_command(command, cwd=spidermonkey_build_path) util.run_command( [get_llvm_dis_path(), '-show-annotations', '-o', libjs_ll, libjs_bc]) js_shell_o_out = util.abspath_join(spidermonkey_build_path, "./shell/js.o") jsheaptools_o = util.abspath_join(spidermonkey_build_path, "./shell/jsheaptools.o") jsoptparse_o = util.abspath_join(spidermonkey_build_path, "./shell/jsoptparse.o") jsworkers_o = util.abspath_join(spidermonkey_build_path, "./shell/jsworkers.o") util.run_command([ get_llvm_link_path(), '-o', js_combined_bc, libjs_bc, js_shell_o_out, jsheaptools_o, jsoptparse_o, jsworkers_o ]) util.run_command([ get_llvm_dis_path(), '-show-annotations', '-o', js_combined_ll, js_combined_bc ]) if not os.path.isfile(js_combined_ll): sys.stderr.write("Failed to build combined LLVM file.\n") sys.exit(1) print("Built LLVM file:\n -- %s" % js_combined_ll) print(" -- %g MB" % (float(os.path.getsize(js_combined_ll)) / 1024 / 1024, )) print("[DONE] - compile")