From 16125272b28ba8a6a65ddde81924aa894d65080b Mon Sep 17 00:00:00 2001 From: Jacob Gravelle Date: Wed, 30 May 2018 16:41:59 -0700 Subject: [PATCH 1/3] Support for building upstream LLVM from source --- emsdk | 21 +++++++++++++++++++-- emsdk_manifest.json | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/emsdk b/emsdk index d203c1d..7ede1de 100755 --- a/emsdk +++ b/emsdk @@ -791,7 +791,16 @@ def xcode_sdk_version(): return subprocess.checkplatform.mac_ver()[0].split('.') def build_fastcomp_tool(tool): - if VERBOSE: print('build_fastcomp_tool(' + str(tool) + ')') + return build_llvm_tool(tool, build_js=True) + +def build_upstream_llvm_tool(tool): + global ENABLE_WASM + # Upstream LLVM has no JSBackend, relies on wasm backend + ENABLE_WASM = True + return build_llvm_tool(tool, build_js=False) + +def build_llvm_tool(tool, build_js): + if VERBOSE: print('build_llvm_tool(' + str(tool) + ')') fastcomp_root = tool.installation_path() fastcomp_src_root = os.path.join(fastcomp_root, 'src') if hasattr(tool, 'git_branch'): # Does this tool want to be git cloned from github? @@ -800,6 +809,10 @@ def build_fastcomp_tool(tool): clang_root = os.path.join(fastcomp_src_root, 'tools/clang') success = git_clone_checkout_and_pull(tool.clang_url, clang_root, tool.git_branch) if not success: return False + if hasattr(tool, 'lld_url'): + lld_root = os.path.join(fastcomp_src_root, 'tools/lld') + success = git_clone_checkout_and_pull(tool.lld_url, lld_root, tool.git_branch) + if not success: return False else: # Not a git cloned tool, so instead download from git tagged releases success = download_and_unzip(tool.download_url(), fastcomp_src_root, filename_prefix='llvm-e') if not success: return False @@ -821,7 +834,8 @@ def build_fastcomp_tool(tool): enable_assertions = ENABLE_LLVM_ASSERTIONS.lower() == 'on' or (ENABLE_LLVM_ASSERTIONS == 'auto' and build_type.lower() != 'release' and build_type.lower() != 'minsizerel') - args = ['-DLLVM_TARGETS_TO_BUILD=X86;JSBackend', '-DLLVM_INCLUDE_EXAMPLES=OFF', '-DCLANG_INCLUDE_EXAMPLES=OFF', '-DLLVM_INCLUDE_TESTS=' + tests_arg, '-DCLANG_INCLUDE_TESTS=' + tests_arg, '-DLLVM_ENABLE_ASSERTIONS=' + ('ON' if enable_assertions else 'OFF')] + js_target = ';JSBackend' if build_js else '' + args = ['-DLLVM_TARGETS_TO_BUILD=X86' + js_target, '-DLLVM_INCLUDE_EXAMPLES=OFF', '-DCLANG_INCLUDE_EXAMPLES=OFF', '-DLLVM_INCLUDE_TESTS=' + tests_arg, '-DCLANG_INCLUDE_TESTS=' + tests_arg, '-DLLVM_ENABLE_ASSERTIONS=' + ('ON' if enable_assertions else 'OFF')] if ENABLE_WASM: args += ['-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly'] if os.environ.get('LLVM_CMAKE_ARGS'): @@ -1337,6 +1351,8 @@ class Tool: if hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_fastcomp': success = build_fastcomp_tool(self) + elif hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_llvm': + success = build_upstream_llvm_tool(self) elif hasattr(self, 'git_branch'): success = git_clone_checkout_and_pull(url, self.installation_path(), self.git_branch) elif url.endswith('zip') or url.endswith('.tar') or url.endswith('.gz') or url.endswith('.xz'): @@ -1350,6 +1366,7 @@ class Tool: if success and hasattr(self, 'custom_install_script'): if self.custom_install_script == 'build_optimizer': success = build_optimizer_tool(self) elif self.custom_install_script == 'build_fastcomp': pass # 'build_fastcomp' is a special one that does the download on its own, others do the download manually. + elif self.custom_install_script == 'build_llvm': pass # 'build_llvm' is like 'build_fastcomp' elif self.custom_install_script == 'build_binaryen': success = build_binaryen_tool(self) else: raise Exception('Unknown custom_install_script command "' + self.custom_install_script + '"!') diff --git a/emsdk_manifest.json b/emsdk_manifest.json index dc01af8..f8a871d 100644 --- a/emsdk_manifest.json +++ b/emsdk_manifest.json @@ -145,6 +145,34 @@ "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", "cmake_build_type": "Release" }, + { + "id": "upstream-clang", + "version": "master", + "bitness": 32, + "install_path": "clang/upstream", + "git_branch": "master", + "url": "https://github.com/llvm-mirror/llvm.git", + "clang_url": "https://github.com/llvm-mirror/clang.git", + "lld_url": "https://github.com/llvm-mirror/clang.git", + "custom_install_script": "build_llvm", + "activated_path": "%installation_dir%/%fastcomp_build_bin_dir%", + "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", + "cmake_build_type": "Release" + }, + { + "id": "upstream-clang", + "version": "master", + "bitness": 64, + "install_path": "clang/upstream", + "git_branch": "master", + "url": "https://github.com/llvm-mirror/llvm.git", + "clang_url": "https://github.com/llvm-mirror/clang.git", + "lld_url": "https://github.com/llvm-mirror/lld.git", + "custom_install_script": "build_llvm", + "activated_path": "%installation_dir%/%fastcomp_build_bin_dir%", + "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", + "cmake_build_type": "Release" + }, { "id": "clang", "version": "e1.13.0", From e54a0dc5ae4091dfa0a49aa34b30146592b70261 Mon Sep 17 00:00:00 2001 From: Jacob Gravelle Date: Wed, 20 Jun 2018 08:42:22 -0700 Subject: [PATCH 2/3] Fix 32-bit lld_url --- emsdk_manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emsdk_manifest.json b/emsdk_manifest.json index f8a871d..faa0724 100644 --- a/emsdk_manifest.json +++ b/emsdk_manifest.json @@ -153,7 +153,7 @@ "git_branch": "master", "url": "https://github.com/llvm-mirror/llvm.git", "clang_url": "https://github.com/llvm-mirror/clang.git", - "lld_url": "https://github.com/llvm-mirror/clang.git", + "lld_url": "https://github.com/llvm-mirror/lld.git", "custom_install_script": "build_llvm", "activated_path": "%installation_dir%/%fastcomp_build_bin_dir%", "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", From 3310027d35a99d116c211f8a7ca0b31efcf6a0fc Mon Sep 17 00:00:00 2001 From: Jacob Gravelle Date: Wed, 20 Jun 2018 09:07:48 -0700 Subject: [PATCH 3/3] Use only_supports_wasm flag instead of separate install script --- emsdk | 25 ++++++++----------------- emsdk_manifest.json | 6 ++++-- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/emsdk b/emsdk index 7ede1de..ea3aa12 100755 --- a/emsdk +++ b/emsdk @@ -790,16 +790,7 @@ def xcode_sdk_version(): except: return subprocess.checkplatform.mac_ver()[0].split('.') -def build_fastcomp_tool(tool): - return build_llvm_tool(tool, build_js=True) - -def build_upstream_llvm_tool(tool): - global ENABLE_WASM - # Upstream LLVM has no JSBackend, relies on wasm backend - ENABLE_WASM = True - return build_llvm_tool(tool, build_js=False) - -def build_llvm_tool(tool, build_js): +def build_llvm_tool(tool): if VERBOSE: print('build_llvm_tool(' + str(tool) + ')') fastcomp_root = tool.installation_path() fastcomp_src_root = os.path.join(fastcomp_root, 'src') @@ -834,9 +825,12 @@ def build_llvm_tool(tool, build_js): enable_assertions = ENABLE_LLVM_ASSERTIONS.lower() == 'on' or (ENABLE_LLVM_ASSERTIONS == 'auto' and build_type.lower() != 'release' and build_type.lower() != 'minsizerel') - js_target = ';JSBackend' if build_js else '' - args = ['-DLLVM_TARGETS_TO_BUILD=X86' + js_target, '-DLLVM_INCLUDE_EXAMPLES=OFF', '-DCLANG_INCLUDE_EXAMPLES=OFF', '-DLLVM_INCLUDE_TESTS=' + tests_arg, '-DCLANG_INCLUDE_TESTS=' + tests_arg, '-DLLVM_ENABLE_ASSERTIONS=' + ('ON' if enable_assertions else 'OFF')] - if ENABLE_WASM: + only_supports_wasm = hasattr(tool, 'only_supports_wasm') + targets_to_build = 'X86' + if not only_supports_wasm: + targets_to_build += ';JSBackend' + args = ['-DLLVM_TARGETS_TO_BUILD=' + targets_to_build, '-DLLVM_INCLUDE_EXAMPLES=OFF', '-DCLANG_INCLUDE_EXAMPLES=OFF', '-DLLVM_INCLUDE_TESTS=' + tests_arg, '-DCLANG_INCLUDE_TESTS=' + tests_arg, '-DLLVM_ENABLE_ASSERTIONS=' + ('ON' if enable_assertions else 'OFF')] + if ENABLE_WASM or only_supports_wasm: args += ['-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly'] if os.environ.get('LLVM_CMAKE_ARGS'): extra_args = os.environ['LLVM_CMAKE_ARGS'].split(',') @@ -1350,9 +1344,7 @@ class Tool: url = self.download_url() if hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_fastcomp': - success = build_fastcomp_tool(self) - elif hasattr(self, 'custom_install_script') and self.custom_install_script == 'build_llvm': - success = build_upstream_llvm_tool(self) + success = build_llvm_tool(self) elif hasattr(self, 'git_branch'): success = git_clone_checkout_and_pull(url, self.installation_path(), self.git_branch) elif url.endswith('zip') or url.endswith('.tar') or url.endswith('.gz') or url.endswith('.xz'): @@ -1366,7 +1358,6 @@ class Tool: if success and hasattr(self, 'custom_install_script'): if self.custom_install_script == 'build_optimizer': success = build_optimizer_tool(self) elif self.custom_install_script == 'build_fastcomp': pass # 'build_fastcomp' is a special one that does the download on its own, others do the download manually. - elif self.custom_install_script == 'build_llvm': pass # 'build_llvm' is like 'build_fastcomp' elif self.custom_install_script == 'build_binaryen': success = build_binaryen_tool(self) else: raise Exception('Unknown custom_install_script command "' + self.custom_install_script + '"!') diff --git a/emsdk_manifest.json b/emsdk_manifest.json index faa0724..500dd6d 100644 --- a/emsdk_manifest.json +++ b/emsdk_manifest.json @@ -154,7 +154,8 @@ "url": "https://github.com/llvm-mirror/llvm.git", "clang_url": "https://github.com/llvm-mirror/clang.git", "lld_url": "https://github.com/llvm-mirror/lld.git", - "custom_install_script": "build_llvm", + "custom_install_script": "build_fastcomp", + "only_supports_wasm": true, "activated_path": "%installation_dir%/%fastcomp_build_bin_dir%", "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", "cmake_build_type": "Release" @@ -168,7 +169,8 @@ "url": "https://github.com/llvm-mirror/llvm.git", "clang_url": "https://github.com/llvm-mirror/clang.git", "lld_url": "https://github.com/llvm-mirror/lld.git", - "custom_install_script": "build_llvm", + "custom_install_script": "build_fastcomp", + "only_supports_wasm": true, "activated_path": "%installation_dir%/%fastcomp_build_bin_dir%", "activated_cfg": "LLVM_ROOT='%installation_dir%/%fastcomp_build_bin_dir%'", "cmake_build_type": "Release"