Skip to content

Commit d6e84e3

Browse files
committedMar 13, 2018
Add WebAssembly output workaround for LLVM 6
1 parent bcce777 commit d6e84e3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed
 

‎src/target.cpp

+21-4
Original file line numberDiff line numberDiff line change
@@ -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

512529
static bool is_os_darwin(ZigTarget *target) {

0 commit comments

Comments
 (0)
Please sign in to comment.