docs icon indicating copy to clipboard operation
docs copied to clipboard

[question]How to use CMake with Emscripten and Conan 2

Open Astral-Yang opened this issue 1 year ago • 6 comments

I've seen an example of emscripten in conan1, but it doesn't seem to be in conan2, what can I do to compile wasm in conan2?

Astral-Yang avatar Oct 29 '24 07:10 Astral-Yang

this would be a duplicate of https://github.com/conan-io/docs/issues/3829

memsharded avatar Oct 29 '24 10:10 memsharded

this would be a duplicate of #3829

but i have some error, when i run conan install . --profile:host=emscripten.profile --profile:build=default --build=missing got

wasm-ld: error: blocksort.c.obj: section too large emcc: error: '/usr/local/Cellar/emscripten/3.1.70/libexec/llvm/bin/wasm-ld -o bzip2.wasm -L/usr/local/Cellar/emscripten/3.1.70/libexec/cache/sysroot/lib/wasm32-emscripten CMakeFiles/bzip2.dir/src/bzip2.c.obj libbz2.a -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/q5/66ml___x5631tmxr9d5bhpcw0000gn/T/tmp2l82pu1wlibemscripten_js_symbols.so --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1' failed (returned 1) make[2]: *** [bzip2] Error 1 make[1]: *** [CMakeFiles/bzip2.dir/all] Error 2 make: *** [all] Error 2 bzip2/1.0.8: ERROR: Package '1c6dc9642a08a8abcc6d2dfdb73ea8d1443da9c7' build failed bzip2/1.0.8: WARN: Build folder /Users/astralyang/.conan2/p/b/bzip23e0455484a97c/b/build/Debug ERROR: bzip2/1.0.8: Error in build() method, line 64 cmake.build() ConanException: Error 2 while executing

this emscripten.profile

[settings] arch=wasm build_type=Release compiler=apple-clang compiler.cppstd=gnu17 compiler.version=14 compiler.libcxx=libc++ os=Emscripten [platform_tool_requires] cmake/3.28.1 [buildenv] CC=emcc CXX=em++

this default [settings] arch=x86_64 build_type=Release compiler=apple-clang compiler.cppstd=gnu17 compiler.libcxx=libc++ compiler.version=14 os=Macos

please help me,thank you

Astral-Yang avatar Nov 04 '24 03:11 Astral-Yang

I am afraid that this is not enough information. You'd need to provide:

  • the conanfile that you are using. Ideally a minimal one to reproduce, do not provide one with tons of [requires], the best would be only 1
  • It would be better to reproduce things with template projects, for example created with conan new cmake_lib command. Recipes, packages and third party libraries out there might not support wasm in their build systems at all, so this might not be a Conan issue, but an issue of those specific projects. So to report against Conan tool, it is better with a minimalistic project
  • Report all the system details, including conan version command, your compiler details, etc
  • Report the full output

Regarding point 2, the output in wasm-ld: error: blocksort.c.obj: section too large seems to indicate this is a compilation error, not a Conan error. Maybe that project cannot be compiled with wasm at all.

memsharded avatar Nov 04 '24 10:11 memsharded

I am afraid that this is not enough information. You'd need to provide:

  • the that you are using. Ideally a minimal one to reproduce, do not provide one with tons of , the best would be only 1conanfile``[requires]
  • It would be better to reproduce things with template projects, for example created with command. Recipes, packages and third party libraries out there might not support wasm in their build systems at all, so this might not be a Conan issue, but an issue of those specific projects. So to report against Conan tool, it is better with a minimalistic projectconan new cmake_lib
  • Report all the system details, including command, your compiler details, etcconan version
  • Report the full output

Regarding point 2, the output in seems to indicate this is a compilation error, not a Conan error. Maybe that project cannot be compiled with wasm at all.wasm-ld: error: blocksort.c.obj: section too large

thank you for your reply,i fix it,but i do not know how to disable TensorflowLite's pthread in conan because i got an error when i compile

pthre7a01f8928a0fa/b/src/src/memory.c:44:7: error: call to undeclared function 'posix_memalign'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

Astral-Yang avatar Nov 05 '24 01:11 Astral-Yang

This also looks like a compilation error, and pthread might not build at all for wasm. In tensorflow-lite recipe the code is:

if Version(self.version) >= "2.12.0" or self.options.with_xnnpack:
     self.requires("pthreadpool/cci.20231129")

So for versions >=2.12 it seems the requirement to pthreadpool is mandatory, it cannot be skipped

memsharded avatar Nov 05 '24 08:11 memsharded

这看起来也像一个编译错误,pthread 可能根本不为 wasm 构建。在 tensorflow-lite 配方中,代码为:

if Version(self.version) >= "2.12.0" or self.options.with_xnnpack:
     self.requires("pthreadpool/cci.20231129")

因此,对于版本 >=2.12,似乎要求是强制性的,不能跳过pthreadpool

Thanks for your help, could you give me a minimal example of compiling wasm? like conan1.x example

Astral-Yang avatar Nov 05 '24 09:11 Astral-Yang