@@ -503,10 +503,27 @@ void get_target_triple(Buf *triple, const ZigTarget *target) {
503
503
get_arch_name (arch_name, &target->arch );
504
504
505
505
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
+ }
510
527
}
511
528
512
529
static bool is_os_darwin (ZigTarget *target) {
0 commit comments