zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d6e84e325bab360c6b6980dc2d57df872b9affdc (tree)
parent bcce77700fe0967b4dd796a3a21605868b6f9aa2
Author: Marc Tiehuis <marctiehuis@gmail.com>
Date:   Tue, 13 Mar 2018 21:53:42 +1300

Add WebAssembly output workaround for LLVM 6

Diffstat:
Msrc/target.cpp | 25+++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/target.cpp b/src/target.cpp @@ -503,10 +503,27 @@ void get_target_triple(Buf *triple, const ZigTarget *target) { get_arch_name(arch_name, &target->arch); buf_resize(triple, 0); - buf_appendf(triple, "%s-%s-%s-%s", arch_name, - ZigLLVMGetVendorTypeName(target->vendor), - ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)), - ZigLLVMGetEnvironmentTypeName(target->env_type)); + + // LLVM WebAssembly output support requires the target to be activated at + // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly. + // + // LLVM determines the output format based on the environment suffix, + // defaulting to an object based on the architecture. The default format in + // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to + // explicitly set this ourself in order for it to work. + // + // This is fixed in LLVM 7 and you will be able to get wasm output by + // using the target triple `wasm32-unknown-unknown-unknown`. + if (!strncmp(arch_name, "wasm", 4)) { + buf_appendf(triple, "%s-%s-%s-wasm", arch_name, + ZigLLVMGetVendorTypeName(target->vendor), + ZigLLVMGetOSTypeName(get_llvm_os_type(target->os))); + } else { + buf_appendf(triple, "%s-%s-%s-%s", arch_name, + ZigLLVMGetVendorTypeName(target->vendor), + ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)), + ZigLLVMGetEnvironmentTypeName(target->env_type)); + } } static bool is_os_darwin(ZigTarget *target) {