mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

Meson cannot cross compile with wasi-sdk-11.0 if static libraries are linked #7489

Open gheift opened 4 years ago

gheift commented 4 years ago

Describe the bug Meson cannot cross compile with wasi-sdk-11.0 if static libraries are linked.

To Reproduce Download the SDK from: https://github.com/WebAssembly/wasi-sdk/releases

Create a project: wasi-demo.tar.gz

meson.build:

project('wasi-demo', 'c', default_options: [
    'b_lundef=false',
    'b_asneeded=false',
])
executable('wasi-demo-obj', files( 'main.c', 'call.c'))
static_lib = static_library('static-call', files('call.c'))
executable('wasi-demo-static', 'main.c', link_with: static_lib)

wasi-sdk-11.0.cross:

[host_machine] 
system = 'wasi'
cpu_family = 'wasm32'[wasi-demo.tar.gz](https://github.com/mesonbuild/meson/files/4959028/wasi-demo.tar.gz)

cpu = 'wasm32'
endian = 'little'
[binaries]
c =       '$HOME/.local/opt/wasi-sdk-11.0/bin/clang'
ar =      '$HOME/.local/opt/wasi-sdk-11.0/bin/ar'
ld =      '$HOME/.local/opt/wasi-sdk-11.0/bin/wasm-ld'
[properties]
c_args =      [ '--target=wasm32-unknown-wasi', '--sysroot', '$HOME/.local/opt/wasi-sdk-11.0/share/wasi-sysroot', ] 
c_link_args = [ '--target=wasm32-unknown-wasi', '--sysroot', '$HOME/.local/opt/wasi-sdk-11.0/share/wasi-sysroot', ]

main.c:

#include <stdio.h>
extern char * lib_call(void);
int main(int argc, char **argv) {
  printf("Hello World: %s!\n", lib_call());
  return 0;
}

call.c:

char * lib_call(void) {
  return "called!";
}

Expected behavior I expect both executables to be built, but the one which links the static library fails. Working (link both object files directly):

$HOME/.local/opt/wasi-sdk-11.0/bin/clang  -o wasi-demo-obj wasi-demo-obj.p/main.c.o wasi-demo-obj.p/call.c.o --target=wasm32-unknown-wasi --sysroot $HOME/.local/opt/wasi-sdk-11.0/share/wasi-sysroot

Fails (link main.o directly, call.o via the static library):

$HOME/.local/opt/wasi-sdk-11.0/bin/clang  -o wasi-demo-static wasi-demo-static.p/main.c.o --target=wasm32-unknown-wasi --sysroot $HOME/.local/opt/wasi-sdk-11.0/share/wasi-sysroot -Wl,--start-group libstatic-call.a -Wl,--end-group '-Wl,-rpath,$ORIGIN/' -Wl,-rpath-link,$HOME/Projects/wasi-demo/builddir/

Errors given:

wasm-ld: error: unknown argument: --start-group
wasm-ld: error: unknown argument: --end-group
wasm-ld: error: unknown argument: -rpath
wasm-ld: error: unknown argument: -rpath-link
wasm-ld: error: cannot open $ORIGIN/: No such file or directory
wasm-ld: error: cannot open $HOME/Projects/wasi-demo/builddir/: Is a directory
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

system parameters

Log:

meson --cross-file wasi-sdk-11.0.cross builddir
The Meson build system
Version: 0.55.0
Source dir: /Users/gerhard/Projects/wasi-demo
Build dir: /Users/gerhard/Projects/wasi-demo/builddir
Build type: cross build
Project name: wasi-demo
Project version: undefined
C compiler for the build machine: ccache cc (clang 11.0.3 "Apple clang version 11.0.3 (clang-1103.0.32.62)")
C linker for the build machine: cc ld64 556.6
C compiler for the host machine: $HOME/.local/opt/wasi-sdk-11.0/bin/clang (clang 10.0.0 "clang version 10.0.0 (https://github.com/llvm/llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28)")
C linker for the host machine: $HOME/.local/opt/wasi-sdk-11.0/bin/clang ld.lld 10.0.0
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: wasm32
Host machine cpu: wasm32
Target machine cpu family: wasm32
Target machine cpu: wasm32
Build targets in project: 3
jcaesar commented 3 years ago

(Persist for wasi-sdk-12. But I don't think this is a meson bug. [Edit:] NVM. Meson could just not pass these arguments.)