rust-cross / cargo-zigbuild

Compile Cargo project with zig as linker
MIT License
1.55k stars 57 forks source link

Failed to build rust wasmtime under Linux #131

Closed kevi-sun closed 1 year ago

kevi-sun commented 1 year ago

Environment:

OS: based ubuntu 20.04 docker
Linux builder.docker 5.15.49-linuxkit #1 SMP Tue Sep 13 07:51:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
cargo-zigbuild version: v0.16.7
rust / cargo --version: cargo 1.66.1 (ad779e08b 2023-01-10)
wasmtime: https://github.com/bytecodealliance/wasmtime , with v8.0.1
psm: https://github.com/rust-lang/stacker

When I try to compiler wasmtime in Linux for target x86_64-unknown-linux-gnu, I found it fails to compiler crate psm, I cloned psm repo and compiler that, the same error happen.

I tried "cargo zigbuild" without target, then it works, so maybe related with target or some configuration, if someone know how to solve this would be highly appreciated.

root@builder:/opt/work/stacker# cargo zigbuild --target x86_64-unknown-linux-gnu --release
   Compiling cc v1.0.79
   Compiling libc v0.2.144
   Compiling cfg-if v1.0.0
   Compiling psm v0.1.21 (/opt/work/stacker/psm)
   Compiling stacker v0.1.15 (/opt/work/stacker)
The following warnings were emitted during compilation:

warning: zig: warning: '-x assembler-with-cpp' after last input file has no effect [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-ffunction-sections' [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-D __GLIBC_MINOR__=19' [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-fdata-sections' [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-D CFG_TARGET_OS_linux' [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-D CFG_TARGET_ARCH_x86_64' [-Wunused-command-line-argument]
warning: zig: warning: argument unused during compilation: '-D CFG_TARGET_ENV_gnu' [-Wunused-command-line-argument]
warning: src/arch/x86_64.s:23:1: error: invalid instruction mnemonic 'globl'
warning: GLOBL(rust_psm_stack_direction)
warning: ^~~~~
warning: src/arch/x86_64.s:25:1: error: invalid instruction mnemonic 'type'
warning: TYPE(rust_psm_stack_direction)
warning: ^~~~
warning: src/arch/x86_64.s:26:35: error: unexpected token in argument list
warning: FUNCTION(rust_psm_stack_direction):
warning:                                   ^
warning: src/arch/x86_64.s:27:1: error: unexpected token at start of statement
warning: /* extern "sysv64" fn() -> u8 (%al) */
warning: ^
warning: src/arch/x86_64.s:32:30: error: expected ')'
warning: SIZE(rust_psm_stack_direction,.rust_psm_stack_direction_end)
warning:                              ^
warning: src/arch/x86_64.s:36:1: error: invalid instruction mnemonic 'globl'
warning: GLOBL(rust_psm_stack_pointer)
warning: ^~~~~
warning: src/arch/x86_64.s:38:1: error: invalid instruction mnemonic 'type'
warning: TYPE(rust_psm_stack_pointer)
warning: ^~~~
warning: src/arch/x86_64.s:39:33: error: unexpected token in argument list
warning: FUNCTION(rust_psm_stack_pointer):
warning:                                 ^
warning: src/arch/x86_64.s:40:1: error: unexpected token at start of statement
warning: /* extern "sysv64" fn() -> *mut u8 (%rax) */
warning: ^
warning: src/arch/x86_64.s:45:28: error: expected ')'
warning: SIZE(rust_psm_stack_pointer,.rust_psm_stack_pointer_end)
warning:                            ^
warning: src/arch/x86_64.s:49:1: error: invalid instruction mnemonic 'globl'
warning: GLOBL(rust_psm_replace_stack)
warning: ^~~~~
warning: src/arch/x86_64.s:51:1: error: invalid instruction mnemonic 'type'
warning: TYPE(rust_psm_replace_stack)
warning: ^~~~
warning: src/arch/x86_64.s:52:33: error: unexpected token in argument list
warning: FUNCTION(rust_psm_replace_stack):
warning:                                 ^
warning: src/arch/x86_64.s:53:1: error: unexpected token at start of statement
warning: /* extern "sysv64" fn(%rdi: usize, %rsi: extern "sysv64" fn(usize), %rdx: *mut u8) */
warning: ^
warning: src/arch/x86_64.s:64:28: error: expected ')'
warning: SIZE(rust_psm_replace_stack,.rust_psm_replace_stack_end)
warning:                            ^
warning: src/arch/x86_64.s:68:1: error: invalid instruction mnemonic 'globl'
warning: GLOBL(rust_psm_on_stack)
warning: ^~~~~
warning: src/arch/x86_64.s:70:1: error: invalid instruction mnemonic 'type'
warning: TYPE(rust_psm_on_stack)
warning: ^~~~
warning: src/arch/x86_64.s:71:28: error: unexpected token in argument list
warning: FUNCTION(rust_psm_on_stack):
warning:                            ^
warning: src/arch/x86_64.s:72:1: error: unexpected token at start of statement
warning: /* extern "sysv64" fn(%rdi: usize, %rsi: usize, %rdx: extern "sysv64" fn(usize, usize), %rcx: *mut u8) */
warning: ^
warning: src/arch/x86_64.s:86:23: error: expected ')'
warning: SIZE(rust_psm_on_stack,.rust_psm_on_stack_end)
warning:                       ^

error: failed to run custom build command for `psm v0.1.21 (/opt/work/stacker/psm)`

Caused by:
  process didn't exit successfully: `/opt/work/stacker/target/release/build/psm-b02afe7eef4ad119/build-script-build` (exit status: 1)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = Some("/root/.cache/cargo-zigbuild/0.16.7/zigcc-x86_64-unknown-linux-gnu.sh")
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  cargo:rustc-cfg=asm
  cargo:rustc-cfg=switchable_stack
  running: "/root/.cache/cargo-zigbuild/0.16.7/zigcc-x86_64-unknown-linux-gnu.sh" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-xassembler-with-cpp" "-DCFG_TARGET_OS_linux" "-DCFG_TARGET_ARCH_x86_64" "-DCFG_TARGET_ENV_gnu" "-o" "/opt/work/stacker/target/x86_64-unknown-linux-gnu/release/build/psm-05ea1d2672336117/out/src/arch/x86_64.o" "-c" "src/arch/x86_64.s"
  cargo:warning=zig: warning: '-x assembler-with-cpp' after last input file has no effect [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-ffunction-sections' [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-D __GLIBC_MINOR__=19' [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-fdata-sections' [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-D CFG_TARGET_OS_linux' [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-D CFG_TARGET_ARCH_x86_64' [-Wunused-command-line-argument]
  cargo:warning=zig: warning: argument unused during compilation: '-D CFG_TARGET_ENV_gnu' [-Wunused-command-line-argument]
  cargo:warning=src/arch/x86_64.s:23:1: error: invalid instruction mnemonic 'globl'
  cargo:warning=GLOBL(rust_psm_stack_direction)
  cargo:warning=^~~~~
  cargo:warning=src/arch/x86_64.s:25:1: error: invalid instruction mnemonic 'type'
  cargo:warning=TYPE(rust_psm_stack_direction)
  cargo:warning=^~~~
  cargo:warning=src/arch/x86_64.s:26:35: error: unexpected token in argument list
  cargo:warning=FUNCTION(rust_psm_stack_direction):
  cargo:warning=                                  ^
  cargo:warning=src/arch/x86_64.s:27:1: error: unexpected token at start of statement
  cargo:warning=/* extern "sysv64" fn() -> u8 (%al) */
  cargo:warning=^
  cargo:warning=src/arch/x86_64.s:32:30: error: expected ')'
  cargo:warning=SIZE(rust_psm_stack_direction,.rust_psm_stack_direction_end)
  cargo:warning=                             ^
  cargo:warning=src/arch/x86_64.s:36:1: error: invalid instruction mnemonic 'globl'
  cargo:warning=GLOBL(rust_psm_stack_pointer)
  cargo:warning=^~~~~
  cargo:warning=src/arch/x86_64.s:38:1: error: invalid instruction mnemonic 'type'
  cargo:warning=TYPE(rust_psm_stack_pointer)
  cargo:warning=^~~~
  cargo:warning=src/arch/x86_64.s:39:33: error: unexpected token in argument list
  cargo:warning=FUNCTION(rust_psm_stack_pointer):
  cargo:warning=                                ^
  cargo:warning=src/arch/x86_64.s:40:1: error: unexpected token at start of statement
  cargo:warning=/* extern "sysv64" fn() -> *mut u8 (%rax) */
  cargo:warning=^
  cargo:warning=src/arch/x86_64.s:45:28: error: expected ')'
  cargo:warning=SIZE(rust_psm_stack_pointer,.rust_psm_stack_pointer_end)
  cargo:warning=                           ^
  cargo:warning=src/arch/x86_64.s:49:1: error: invalid instruction mnemonic 'globl'
  cargo:warning=GLOBL(rust_psm_replace_stack)
  cargo:warning=^~~~~
  cargo:warning=src/arch/x86_64.s:51:1: error: invalid instruction mnemonic 'type'
  cargo:warning=TYPE(rust_psm_replace_stack)
  cargo:warning=^~~~
  cargo:warning=src/arch/x86_64.s:52:33: error: unexpected token in argument list
  cargo:warning=FUNCTION(rust_psm_replace_stack):
  cargo:warning=                                ^
  cargo:warning=src/arch/x86_64.s:53:1: error: unexpected token at start of statement
  cargo:warning=/* extern "sysv64" fn(%rdi: usize, %rsi: extern "sysv64" fn(usize), %rdx: *mut u8) */
  cargo:warning=^
  cargo:warning=src/arch/x86_64.s:64:28: error: expected ')'
  cargo:warning=SIZE(rust_psm_replace_stack,.rust_psm_replace_stack_end)
  cargo:warning=                           ^
  cargo:warning=src/arch/x86_64.s:68:1: error: invalid instruction mnemonic 'globl'
  cargo:warning=GLOBL(rust_psm_on_stack)
  cargo:warning=^~~~~
  cargo:warning=src/arch/x86_64.s:70:1: error: invalid instruction mnemonic 'type'
  cargo:warning=TYPE(rust_psm_on_stack)
  cargo:warning=^~~~
  cargo:warning=src/arch/x86_64.s:71:28: error: unexpected token in argument list
  cargo:warning=FUNCTION(rust_psm_on_stack):
  cargo:warning=                           ^
  cargo:warning=src/arch/x86_64.s:72:1: error: unexpected token at start of statement
  cargo:warning=/* extern "sysv64" fn(%rdi: usize, %rsi: usize, %rdx: extern "sysv64" fn(usize, usize), %rcx: *mut u8) */
  cargo:warning=^
  cargo:warning=src/arch/x86_64.s:86:23: error: expected ')'
  cargo:warning=SIZE(rust_psm_on_stack,.rust_psm_on_stack_end)
  cargo:warning=                      ^
  exit status: 1

  --- stderr

  error occurred: Command "/root/.cache/cargo-zigbuild/0.16.7/zigcc-x86_64-unknown-linux-gnu.sh" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-xassembler-with-cpp" "-DCFG_TARGET_OS_linux" "-DCFG_TARGET_ARCH_x86_64" "-DCFG_TARGET_ENV_gnu" "-o" "/opt/work/stacker/target/x86_64-unknown-linux-gnu/release/build/psm-05ea1d2672336117/out/src/arch/x86_64.o" "-c" "src/arch/x86_64.s" with args "zigcc-x86_64-unknown-linux-gnu.sh" did not execute successfully (status code exit status: 1).
messense commented 1 year ago

I'm not familiar with ASM, I'm not sure what's going on.

kevi-sun commented 1 year ago

@messense thanks for your checking

messense commented 1 year ago

Probably related to https://github.com/ziglang/zig/issues/10411

kevi-sun commented 1 year ago

thanks @messense , I tested with zig 2023-06-01 dev version, and don;t find this compiler error, it might related with: https://github.com/ziglang/zig/issues/14467 I'll close this ticket.