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

The nloptr package fails to cross-compile on macOS #31

Open bbolker opened 5 months ago

bbolker commented 5 months ago

I see that the nloptr package isn't available for webR. It's required for lme4, so if there's anything I can do to help troubleshoot let me know. (nloptr does generally require cmake to build ...)

It would be possible to create a version of lme4 where nloptr was optional, but it would be tedious and wouldn't perform as well without nloptr ...

georgestagg commented 5 months ago

The nloptr package failed to build for WebAssembly during my last set of R package upgrades. Checking logs, a problem happened during the cmake build of libnlopt.a. It looks like the Emscripten compiler does not like one of the flags passed to it during the linking step:

wasm-ld: error: unknown argument: -headerpad_max_install_names

Investigating this more just now, it looks like this might be due to the fact that I'm cross-compiling packages for Wasm from my macOS machine. This might actually work better in Linux. Let me spin up a webR development Docker container and try there...

Nice, the build is indeed successful under Linux! I'll upload the package to the webR binary repository now.

It seems to work:

Screenshot 2024-04-03 at 10 23 33


It would be good to fix the -headerpad_max_install_names issue when cross-compiling from macOS to WebAssembly, but I'm not entirely sure how that could be done. It would probably require some tweaking to how the nlopt library's cmake scripts are invoked during the R package build, with a workaround that kicks in only when the host machine is Darwin, and the target machine is Emscripten.

Perhaps it does not matter so much, most people building Wasm packages will be doing so from inside the reproducible Linux environment provided by the webR development Docker container in any case.