Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

georgestagg
Copy link
Member

@georgestagg georgestagg commented Dec 13, 2023

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:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/utsname.h>

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
Copy link
Member Author

@jeroen How does this look?

@jeroen
Copy link
Contributor

jeroen commented Dec 13, 2023

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.

@georgestagg georgestagg merged commit 6450768 into main Dec 13, 2023
6 checks passed
@georgestagg georgestagg deleted the shim-build-tools branch December 13, 2023 15:00
@jeroen
Copy link
Contributor

jeroen commented Dec 13, 2023

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
Copy link
Member Author

georgestagg commented Dec 14, 2023

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 b8415c1. Technically, tac is already available in the Linux container, but I want to be sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants