proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
140 stars 68 forks source link

Using an external library (in my case, librdkafka) #137

Open MMahdiSetak opened 2 years ago

MMahdiSetak commented 2 years ago

Hi I've been trying to add librdkafka as an external library and use it inside my cpp code but when I try to compile it and generate the wasm file, I get this error:

wasm-ld: error: unknown file type: /usr/lib/x86_64-linux-gnu/librdkafka++.a(ConfImpl.o)
em++: error: '/emsdk/upstream/bin/wasm-ld -o OUTPUT.wasm /tmp/emscripten_temp_1xep1tez/myproject_0.o /tmp/emscripten_temp_1xep1tez/proxy_wasm_intrinsics_lite.pb_1.o /tmp/emscripten_temp_1xep1tez/struct_lite.pb_2.o /tmp/emscripten_temp_1xep1tez/proxy_wasm_intrinsics_3.o /sdk/libprotobuf-lite.a /usr/lib/x86_64-linux-gnu/librdkafka++.a -L/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto /emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/crt1_reactor.o -lGL -lal -lhtml5 -lstandalonewasm -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=malloc --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=malloc --export-table -z stack-size=5242880 --initial-memory=16777216 --entry=_initialize --max-memory=16777216 --global-base=1024' failed (returned 1)
make: *** [OUTPUT.wasm] Error 1
Makefile:15: recipe for target 'OUTPUT.wasm' failed

I've searched about the error and according to this link, it seems that adding some link files to em++ options is not possible. How can I do so? Is there a better way for reading a request and sending a Kafka message in envoy? I've also attached the files that I made some changes to them here: sample.zip

PiotrSikora commented 2 years ago

You're trying to link together Proxy-Wasm plugin (built for wasm32 architecture) and system library (built for x86_64 architecture). This won't work, you need to build librdkafka++ from sources for wasm32 target as part of the plugin itself.

amirEBD commented 2 years ago

I had the same issue with proxy-wasm as @MMahdiSetak mentioned, how can I get a wasm32 build for librdkafa++. @PiotrSikora Thansk for any help :)

PiotrSikora commented 2 years ago

You need to build it from sources as part of the plugin build process (assuming it even compiles to wasm32, since that's not guaranteed).