r-wasm / rwasm

Build R packages for WebAssembly and create a CRAN-like repo for distribution.
https://r-wasm.github.io/rwasm/
Other
54 stars 4 forks source link

Trouble building xgboost; underlying folders needed for building #37

Open erikvona opened 2 months ago

erikvona commented 2 months ago

I'm trying to build xgboost using rwasm.

I've gotten this far

# Download xgboost
git clone --recursive https://github.com/dmlc/xgboost
# Remove a check which errors on cross compiling, ideally I'd have a better solution here
cp  xgboost/R-package/configure  xgboost/R-package/configure_old
sed '2799s/yes/sabotaged/' xgboost/R-package/configure_old > xgboost/R-package/configure 
R
> rwasm::build("./xgboost/R-package")

The problem, however, is that the xgboost C++ code makes reference to files in the xgboost folder, but wasm_build is copying the sources to a temporary folder. Thus, the build fails:

...
Makevars:19: -DDMLC_LOG_CUSTOMIZE=1
em++ -std=gnu++17 -DNDEBUG -I../..//include -I../..//dmlc-core/include -I../../ -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=1 -DDMLC_DISABLE_STDIN=1 -DDMLC_LOG_CUSTOMIZE=1  -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.4.1/build/include -I/opt/webr/R/build/R-4.4.1/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -DDMLC_CMAKE_LITTLE_ENDIAN=0 -pthread -fvisibility=hidden -fpic  -std=gnu++17 -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -DRCPP_DEMANGLER_ENABLED=0 -D__STRICT_ANSI__  -c xgboost_R.cc -o xgboost_R.o
xgboost_R.cc:4:10: fatal error: 'dmlc/common.h' file not found
    4 | #include <dmlc/common.h>
      |          ^~~~~~~~~~~~~~~
1 error generated.
em++: error: '/opt/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -mllvm -combiner-global-alias-analysis=false -mllvm -wasm-enable-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_SHARED_MEMORY__=1 -DEMSCRIPTEN --sysroot=/opt/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -std=gnu++17 -DNDEBUG -I../..//include -I../..//dmlc-core/include -I../../ -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=1 -DDMLC_DISABLE_STDIN=1 -DDMLC_LOG_CUSTOMIZE=1 -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.4.1/build/include -I/opt/webr/R/build/R-4.4.1/src/include -DDMLC_CMAKE_LITTLE_ENDIAN=0 -pthread -fvisibility=hidden -fpic -std=gnu++17 -Oz -fPIC -fwasm-exceptions -DRCPP_DEMANGLER_ENABLED=0 -D__STRICT_ANSI__ -c -matomics -mbulk-memory xgboost_R.cc -o xgboost_R.o' failed (returned 1)
make: *** [/opt/R/4.4.1/lib/R/etc/Makeconf:202: xgboost_R.o] Error 1
ERROR: compilation failed for package 'xgboost'
* removing '/tmp/RtmpIa1YGR/filef4c19d57d04/xgboost'
Error in wasm_build(pkg, tarball_path, out_dir) :
  Building wasm binary for package 'xgboost' failed.

This is even though the call to em++ is valid, as can be seen:

cd xgboost/R-package/src
em++ -std=gnu++17 -DNDEBUG -I../..//include -I../..//dmlc-core/include -I../../ -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=1 -DDMLC_DISABLE_STDIN=1 -DDMLC_LOG_CUSTOMIZE=1  -I/opt/webr/wasm/include -I/opt/webr/R/build/R-4.4.1/build/include -I/opt/webr/R/build/R-4.4.1/src/include -s USE_BZIP2=1 -s USE_ZLIB=1 -DDMLC_CMAKE_LITTLE_ENDIAN=0 -pthread -fvisibility=hidden -fpic  -std=gnu++17 -Oz -fPIC -fwasm-exceptions -s SUPPORT_LONGJMP=wasm -DRCPP_DEMANGLER_ENABLED=0 -D__STRICT_ANSI__  -c xgboost_R.cc -o xgboost_R.o

This returns without error and creates xgboost_R.o

I'm not sure how to proceed. Perhaps a function could be created that allows copying of underlying directories?