weixin_39891438
2020-12-01 12:53 阅读 1

Does rustc need a wasm target?

The issue with isize failing on 64-bit systems that was recently fixed (#34) got me thinking, does rustc itself need to know it's compiling for Wasm? I feel like WebAssembly is really its own platform, so for example we should always use i32 for isize regardless of the host architecture. Can this be done just by having mir2wasm pass certain flags to the code it imports from rustc, or does rustc actually need to be modified to have a WebAssembly platform target?

该提问来源于开源项目:brson/miri

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • weixin_39682697 weixin_39682697 2020-12-01 12:53

    It does need a wasm platform target. I'm not sure the triple but will know (I'd expect wasm-unknown-emscripten for wasm + the emscripten runtime).

    The compiler already has a target for asm.js, asmjs-unknown-emscripten. This target sets target_pointer_width = "32", target_os = "emscripten", target_arch = "asmjs". For wasm the target spec can probably be exactly the same except that target_arch = "wasm".

    The best way for mir2wasm to proceed for now is probably to create its own target spec and pass that to the session config (or wherever it goes).

    点赞 评论 复制链接分享
  • weixin_39636609 weixin_39636609 2020-12-01 12:53

    Should we need an LLVM target triple in this case? We are not using LLVM in this path. Or is the triple used in some other way?

    点赞 评论 复制链接分享
  • weixin_39682697 weixin_39682697 2020-12-01 12:53

    target triples are also how rustc thinks about targets. It may be true that mir2wasm can get by without actually defining a string that is a target triple, but mir2wasm's ultimate destiny is as a rustc backend.

    点赞 评论 复制链接分享
  • weixin_39682697 weixin_39682697 2020-12-01 12:53

    In rustc a target triple is shorthand for a 'target spec', and that's the thing that we really do need to define since it impacts a variety of things, like the pointer width and various definitions used for conditional compilation.

    点赞 评论 复制链接分享
  • weixin_39636609 weixin_39636609 2020-12-01 12:53

    Oh ok, got it.

    点赞 评论 复制链接分享

相关推荐