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

Bug in `make symbols.rds` causes duckdb to fail #13

Closed jeroen closed 6 months ago

jeroen commented 8 months ago

The duckdb package does something rare where it invokes the rule make symbols.rds which fails because it tries to execute an R command in webr instead of host-R. See for example build log.

This rule is defined in a base R in share/make/shlib.mk as follows:

symbols.rds: $(OBJECTS)
    @$(ECHO) "tools:::.shlib_objects_symbol_tables()" | \
      $(R_HOME)/bin/R --vanilla --no-echo --args $(OBJECTS)

I am not sure what would be the correct way to override this. Perhaps we just need to replace it with a dummy rule because reading symbols from the wasm objects probably won't work anyway, even if we run the script in host-R.

I tried creating a dummy rule for symbols.rds in webr-vars which worked but gave a warning for every package build, so that is not very elegant either.

/opt/R/4.3.2/lib/R/site-library/rwasm/webr-vars.mk:123: warning: overriding recipe for target 'symbols.rds'
/opt/R/4.3.2/lib/R/share/make/shlib.mk:24: warning: ignoring old recipe for target 'symbols.rds'
georgestagg commented 7 months ago

Surprisingly, it looks like R can read the symbols from object files output by emcc, at least the names:

$ cat obj.c
int f() {
        return 0;
}
$ emcc -c obj.c -o obj.o                                              
$ clang -c obj.c -o host.o
$ echo "tools:::read_symbols_from_object_file('host.o')" | R --vanilla --quiet
> tools:::read_symbols_from_object_file('host.o')
     name type value size
[1,] "_f" "T"  "0"   "0" 
> 
$ echo "tools:::read_symbols_from_object_file('obj.o')" | R --vanilla --quiet
> tools:::read_symbols_from_object_file('obj.o')
     name type value size
[1,] "f"  "T"  "1"   "0" 
> 

So, perhaps this could be made to work!

I suppose we could patch the R source as part of the webR build process to use $(R_HOST_EXE) for this particular rule, since we already set that Makevar for other purposes elsewhere. That would silence the override error I think.