emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.86k stars 3.32k forks source link

Build boost library to emscripten #22767

Open juanlanuzag opened 1 month ago

juanlanuzag commented 1 month ago

Hello, I am trying to port an existing program to wasm and this program uses boost program options. I downloaded and boostrapped boost and I'm running ` ./b2 toolset=emscripten link=static threading=multi --with-program_options

I am getting the following warning for multiple files

emcc: warning: .bc output file suffix used without -flto or -emit-llvm.  Consider using .o extension since emcc will output an object file, not a bitcode file [-Wemcc]
emscripten.compile.c++ bin.v2/libs/program_options/build/emscripten-3.1.69/release/link-static/threading-multi/visibility-hidden/split.bc

and the following error

emscripten.archive bin.v2/libs/program_options/build/emscripten-3.1.69/release/link-static/threading-multi/visibility-hidden/libboost_program_options.bc
bin.v2/libs/program_options/build/emscripten-3.1.69/release/link-static/threading-multi/visibility-hidden/cmdline.bc:1:2: error: expected top-level entity
    1 | <U+0000>asm<U+0001><U+0000><U+0000><U+0000><U+0001>ƀ<80><80><U+0000><U+000B>`

Any idea what is this issue? Is my approach correct?

Version of emscripten/emsdk:

emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.69 (c55ff404dbe1eb9f263c48b584d5ba627224763a)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 50866e84d1da8462aeb96607bf6d9e5bbd5869c5)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/myuser/emsdk/upstream/bin
sbc100 commented 1 month ago

Looks like the build system needs to be updated to switch from .bc to .o for the object file extension.

manin commented 1 week ago

You'll have to update "tools/build/src/tools/emscripten.jam". This is the diff for the boost version i'm using (1.79.0)

--- a/tools/build/src/tools/emscripten.jam
+++ b/tools/build/src/tools/emscripten.jam
@@ -6,6 +6,7 @@
 import feature ;
 import os ;
 import toolset ;
+import generators ;
 import common ;
 import gcc ;
 import type ;
@@ -49,10 +50,11 @@ toolset.inherit-flags emscripten : gcc
         <debug-symbols>off <debug-symbols>on
         <rtti>off <rtti>on
         ;
-
+generators.override builtin.lib-generator : emscripten.prebuilt ;
+generators.override emscripten.searched-lib-generator : searched-lib-generator ;
 type.set-generated-target-suffix EXE : <toolset>emscripten : "js" ;
-type.set-generated-target-suffix OBJ : <toolset>emscripten : "bc" ;
-type.set-generated-target-suffix STATIC_LIB : <toolset>emscripten : "bc" ;
+type.set-generated-target-suffix OBJ : <toolset>emscripten : "o" ;
+type.set-generated-target-suffix STATIC_LIB : <toolset>emscripten : "a" ;

 toolset.flags emscripten.compile OPTIONS <flags> ;
 toolset.flags emscripten.compile OPTIONS <cflags> ;
@@ -94,7 +96,7 @@ actions compile.c++

 actions archive
 {
-    "$(CONFIG_COMMAND)" $(AROPTIONS) -r -o "$(<)" "$(>)"
+    emar -r $(AROPTIONS) "$(<)" "$(>)"
 }

 toolset.flags emscripten.link USER_OPTIONS <linkflags> ;