authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-03-13 21:53:42+13:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-03-13 21:53:42+13:00
logd6e84e325bab360c6b6980dc2d57df872b9affdc
tree3a13ddf90e1a808ff4e359ef9dfff13c5b4cbe21
parentbcce77700fe0967b4dd796a3a21605868b6f9aa2

Add WebAssembly output workaround for LLVM 6


1 files changed, 21 insertions(+), 4 deletions(-)

src/target.cpp+21-4
......@@ -503,10 +503,27 @@ void get_target_triple(Buf *triple, const ZigTarget *target) {
503503 get_arch_name(arch_name, &target->arch);
504504
505505 buf_resize(triple, 0);
506 buf_appendf(triple, "%s-%s-%s-%s", arch_name,
507 ZigLLVMGetVendorTypeName(target->vendor),
508 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
509 ZigLLVMGetEnvironmentTypeName(target->env_type));
506
507 // LLVM WebAssembly output support requires the target to be activated at
508 // build type with -DCMAKE_LLVM_EXPIERMENTAL_TARGETS_TO_BUILD=WebAssembly.
509 //
510 // LLVM determines the output format based on the environment suffix,
511 // defaulting to an object based on the architecture. The default format in
512 // LLVM 6 sets the wasm arch output incorrectly to ELF. We need to
513 // explicitly set this ourself in order for it to work.
514 //
515 // This is fixed in LLVM 7 and you will be able to get wasm output by
516 // using the target triple `wasm32-unknown-unknown-unknown`.
517 if (!strncmp(arch_name, "wasm", 4)) {
518 buf_appendf(triple, "%s-%s-%s-wasm", arch_name,
519 ZigLLVMGetVendorTypeName(target->vendor),
520 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)));
521 } else {
522 buf_appendf(triple, "%s-%s-%s-%s", arch_name,
523 ZigLLVMGetVendorTypeName(target->vendor),
524 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
525 ZigLLVMGetEnvironmentTypeName(target->env_type));
526 }
510527}
511528
512529static bool is_os_darwin(ZigTarget *target) {