打造一个“hello,world”风格的程序,看看我是否可以通过在 emscripten运行它来获取 asm.js输出在网络上使用 Swift. 问题是当我编译它时,它的bitcode试图链接动态库.它似乎不需要这样做,或者似
问题是当我编译它时,它的bitcode试图链接动态库.它似乎不需要这样做,或者似乎有人理解所有这些部分如何组合在一起可以告诉我如何提供它需要的文件(我愿意实现它所依赖的一些功能)在JavaScript中,如有必要).
我对环境here有了更全面的解释,但这是基础知识:
文件:
$cat f.swift var message = 1
将其编译为bitcode:
$xcrun swiftc -emit-bc f.swift -o f.bc
无法将bitcode编译为asm.js:
$emcc f.bc WARNING: Linking two modules of different data layouts: '/Users/josh/.emscripten_cache/libc.bc' is 'e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128' whereas '/Users/josh/deleteme/swift-play/f.bc' is 'e-m:o-i64:64-f80:128-n8:16:32:64-S128' WARNING: Linking two modules of different target triples: /Users/josh/.emscripten_cache/libc.bc' is 'asmjs-unknown-emscripten' whereas '/Users/josh/deleteme/swift-play/f.bc' is 'x86_64-apple-darwin13.2.0' Unknown specifier in datalayout string UNREACHABLE executed at /Users/clb/emscripten-fastcomp/lib/IR/DataLayout.cpp:300! 0 opt 0x00000001086d04ae llvm::sys::PrintStackTrace(__sFILE*) + 46 1 opt 0x00000001086d07bb PrintStackTraceSignalHandler(void*) + 27 2 opt 0x00000001086d0b4c SignalHandler(int) + 412 3 libsystem_platform.dylib 0x00007fff8b0e35aa _sigtramp + 26 4 libsystem_platform.dylib 0x00007fff6492d380 _sigtramp + 3649347056 5 opt 0x00000001086d07eb raise + 27 6 opt 0x00000001086d08a2 abort + 18 7 opt 0x000000010865a7a6 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 198 8 opt 0x0000000108416b74 llvm::DataLayout::parseSpecifier(llvm::StringRef) + 2804 9 opt 0x0000000108415c57 llvm::DataLayout::init(llvm::StringRef) + 471 10 opt 0x000000010749b47e llvm::DataLayout::DataLayout(llvm::StringRef) + 158 11 opt 0x0000000107482ba5 llvm::DataLayout::DataLayout(llvm::StringRef) + 37 12 opt 0x000000010747943c main + 3756 13 libdyld.dylib 0x00007fff8a2865fd start + 1 Stack dump: 0. Program arguments: /Users/josh/code/emsdk_portable/clang/e1.25.0_64bit/opt /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/tmp93OFuV/a.out.bc -strip-debug -internalize -internalize-public-api-list=main,malloc,free -globaldce -pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt -enable-emscripten-cxx-exceptions -o /var/folders/7g/mbft22555w3_2nqs_h1kbglw0000gn/T/tmp93OFuV/a.out.bc.opt.bc Traceback (most recent call last): File "/Users/josh/code/emsdk_portable/emscripten/1.25.0/emcc", line 1224, in <module> shared.Building.llvm_opt(final, link_opts) File "/Users/josh/code/emsdk_portable/emscripten/1.25.0/tools/shared.py", line 1357, in llvm_opt assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output AssertionError: Failed to run llvm optimizations:看起来你在这里运气不好. IR编译器生成的不是标准的 – 它包括一些未被上流的私有Apple更改(特别是,数据布局字符串至少是非标准的).
不,它不是试图链接任何动态库.它试图静态地(在LLVM IR级别)链接所有必要的东西,特别是C标准库.