Skip to content

Commit

Permalink
Support WebR (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation authored Feb 5, 2024
1 parent 3ab4dd4 commit aaa00d9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: Build WASM

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout calling repository
uses: actions/checkout@v4

- name: Build wasm packages
uses: yutannihilation/r-wasm-actions/build-rwasm@main
with:
packages: |
local::.
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ fi
if [ "${NOT_CRAN}" != "true" ]; then
BEFORE_CARGO_BUILD="${BEFORE_CARGO_BUILD}"' export CARGO_HOME="$(PWD)/.cargo" \&\&'
AFTER_CARGO_BUILD="${AFTER_CARGO_BUILD}"'rm -Rf $(PWD)/.cargo $(LIBDIR)/build'
VENDORING="yes"
OFFLINE_OPTION="--offline"
else
echo "*** Detected NOT_CRAN=true, do not override CARGO_HOME"
fi

# Handle webR
if [ "$(uname)" = "Emscripten" ]; then
WEBR="yes"
fi

sed \
-e "s|@BEFORE_CARGO_BUILD@|${BEFORE_CARGO_BUILD}|" \
-e "s|@AFTER_CARGO_BUILD@|${AFTER_CARGO_BUILD}|" \
-e "s|@VENDORING@|${VENDORING}|" \
-e "s|@OFFLINE_OPTION@|${OFFLINE_OPTION}|" \
-e "s|@WEBR@|${WEBR}|" \
src/Makevars.in > src/Makevars

# Uncomment this to debug
Expand Down
4 changes: 4 additions & 0 deletions configure.win
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ BEFORE_CARGO_BUILD="${BEFORE_CARGO_BUILD}"' export LIBRARY_PATH="$${LIBRARY_PATH
if [ "${NOT_CRAN}" != "true" ]; then
BEFORE_CARGO_BUILD="${BEFORE_CARGO_BUILD}"' export CARGO_HOME="$(PWD)/.cargo" \&\&'
AFTER_CARGO_BUILD="${AFTER_CARGO_BUILD}"'rm -Rf $(PWD)/.cargo $(LIBDIR)/build'
VENDORING="yes"
OFFLINE_OPTION="--offline"
else
echo "*** Detected NOT_CRAN=true, do not override CARGO_HOME"
fi

sed \
-e "s|@BEFORE_CARGO_BUILD@|${BEFORE_CARGO_BUILD}|" \
-e "s|@AFTER_CARGO_BUILD@|${AFTER_CARGO_BUILD}|" \
-e "s|@VENDORING@|${VENDORING}|" \
-e "s|@OFFLINE_OPTION@|${OFFLINE_OPTION}|" \
src/Makevars.win.in > src/Makevars.win

# Uncomment this to debug
Expand Down
16 changes: 12 additions & 4 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO
VENDORING = yes
OFFLINE_OPTION = --offline
WEBR = @WEBR@

VENDORING = @VENDORING@
OFFLINE_OPTION = @OFFLINE_OPTION@

LIBDIR = ./rust/target/release
PKG_LIBS = -L$(LIBDIR) -lstring2path
Expand All @@ -19,7 +20,14 @@ $(STATLIB):
cp ./cargo_vendor_config.toml ./rust/.cargo/config.toml; \
fi

@BEFORE_CARGO_BUILD@ cd ./rust && cargo build --jobs 1 --lib --release $(OFFLINE_OPTION)
if [ "$(TARGET)" != "wasm32-unknown-emscripten" ]; then \
@BEFORE_CARGO_BUILD@ cd ./rust && cargo build --jobs 1 --lib --release $(OFFLINE_OPTION); \
else \
export CC="$(CC)" && \
export CFLAGS="$(CFLAGS)" && \
export CARGO_PROFILE_RELEASE_PANIC="abort" && \
@BEFORE_CARGO_BUILD@ cd ./rust && cargo +nightly build --lib --release --target wasm32-unknown-emscripten -Zbuild-std=panic_abort,std $(OFFLINE_OPTION); \
fi
@AFTER_CARGO_BUILD@

C_clean:
Expand Down
5 changes: 2 additions & 3 deletions src/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ TARGET = x86_64-pc-windows-gnu
# need to overwrite it via configuration.
CARGO_LINKER = x86_64-w64-mingw32.static.posix-gcc.exe

# TODO
VENDORING = yes
OFFLINE_OPTION = --offline
VENDORING = @VENDORING@
OFFLINE_OPTION = @OFFLINE_OPTION@

LIBDIR = ./rust/target/$(TARGET)/release
PKG_LIBS = -L$(LIBDIR) -lstring2path -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll
Expand Down

0 comments on commit aaa00d9

Please sign in to comment.