Meson cannot cross compile with wasi-sdk-11.0 if static libraries are linked
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 1.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 33
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with meson.build, wasi-sdk-11.0.cross, main.c, and call.c using Meson 0.55.0 and the linked wasi-sdk archive. Start by inspecting the generated linker command and Meson’s cross-compilation and static-library handling; done means the static-library executable builds without unsupported linker arguments and the reported reproduction succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, wasm
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100