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

Shim `uname` and `pkg-config` for Wasm package build #9

Closed georgestagg closed 9 months ago

georgestagg commented 9 months ago

When cross-compiling packages for Wasm, ensure that the uname command outputs "Emscripten" and the pkg-config command outputs a unique list of libraries suitable for static linking.

This should improve compatibility with several R packages' configure scripts.

The output for uname has been selected based on Emscripten's own implementation of the uname syscall. Some details below.

See `emscripten-core/emscripten/system/lib/libc/emscripten_syscall_stubs.c` for implementation details. With that, the following C code: ```c #include #include #include #include int main(void) { struct utsname buffer; errno = 0; if (uname(&buffer) < 0) { perror("uname"); exit(EXIT_FAILURE); } printf("system name = %s\n", buffer.sysname); printf("node name = %s\n", buffer.nodename); printf("release = %s\n", buffer.release); printf("version = %s\n", buffer.version); printf("machine = %s\n", buffer.machine); return EXIT_SUCCESS; } ``` when compiled with Emscripten, outputs: ``` $ node main.js system name = Emscripten node name = emscripten release = 3.1.47 version = #1 machine = wasm32 ```
georgestagg commented 9 months ago

@jeroen How does this look?

jeroen commented 9 months ago

I think this looks good. You could consider setting EM_PKG_CONFIG_PATH in this shim instead of webr_env but I don't think it matters too much.

After you merge it I'll run a bunch test builds and let you know if I find any regressions.

jeroen commented 9 months ago

Hmm I think this use of tail is not portable. I see a lot of these:

configure: sh -c "./configure.orig --host=wasm32-unknown-emscripten"
tail: invalid option -- 'r'
Try 'tail --help' for more information.
tail: invalid option -- 'r'
Try 'tail --help' for more information.
xargs: echo: terminated by signal 13
tail: invalid option -- 'r'
Try 'tail --help' for more information.
tail: invalid option -- 'r'
Try 'tail --help' for more information.
xargs: echo: terminated by signal 13

Eg: https://github.com/r-universe-org/build-wasm/actions/runs/7198206097/job/19607201772

georgestagg commented 9 months ago

Ah, drat! Looks like -r is BSD and not POSIX, yet. Thanks, I'll replace it with something else.

EDIT: tail -r has been replaced with a shell function in https://github.com/r-wasm/rwasm/commit/b8415c1c61c053462ec0ade07019ac58c3953672. Technically, tac is already available in the Linux container, but I want to be sure.