【问题标题】:Nix's clang won't build wasmNix 的 clang 不会构建 wasm
【发布时间】:2021-09-03 03:15:17
【问题描述】:

我有一个具有以下导入的 C Wasm 模块:

__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);

我在 Linux 上使用 Clang 12.0.0 进行编译:

clang --target=wasm32 --no-standard-libraries \
      -c -Ofast -o out.o in.c

使用我的包管理器 (xbps) 中的包,这可以正常工作。然而,在 Nix 中(推导见下文)(Clang 12.0.1),我在nix-build 上收到以下警告:

tests/test.h:1:16: warning: unknown attribute 'import_module' ignored [-Wunknown-attributes]
__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);
               ^~~~~~~~~~~~~~~~~~~~

tests/test.h:1:38: warning: unknown attribute 'import_name' ignored [-Wunknown-attributes]
__attribute__((import_module("env"), import_name("runtime_exit"))) void exit(int);

这只是一个警告,但稍后链接失败:实际上,clang 正在尝试链接 ld,而不是 wasm-ld 甚至 lld

我的default.nix 指定:

{ pkgs ? import <nixpkgs> {} }:

let
  stdenv = pkgs.llvmPackages_12.stdenv;
  src = ./.; # etc, etc
in
  stdenv.mkDerivation {
    # --- snip ---
    buildPhase = ''
      clang --target=wasm32 --no-standard-libraries \
            -c -Ofast -o $out/out.o in.c
    '';
    
    # --- snip ---

    buildInputs = [ pkgs.clang_12 pkgs.lld_12 ];
  }

我不明白为什么这不起作用,但我尝试使用的所有不同的包变体似乎表明我在 LLVM 工具链上的理解不正确。

如果这些信息还不够,请告诉我。谢谢!

编辑

看起来 Nix 不尊重 --target 参数:

$ nix-shell
[nix-shell:~/...]$ clang -target wasm32 --print-target-triple
x86_64-unknown-linux-gnu
[nix-shell:~/...]$ exit
$ clang --target=wasm32 --print-target-triple
wasm32

尽管如此,clang wasm32 作为可用目标。

【问题讨论】:

    标签: clang webassembly nix


    【解决方案1】:

    Nix 提供的 clang 包装脚本似乎做了一些事情。应该使用clang-[VERSION] 而不是clang 调用编译器,例如:

    clang-12 --target=wasm32 --no-standard-libraries   \
             -c -std=c99 -Ofast -Wall -Werror -pedantic \
             input.c -o output.o
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      • 2021-10-01
      相关资源
      最近更新 更多