From aaa00d97396dac9eee9dacddb2a91ab610c576c5 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Mon, 5 Feb 2024 23:45:15 +0900 Subject: [PATCH] Support WebR (#57) --- .github/workflows/build-wasm.yml | 20 ++++++++++++++++++++ configure | 10 ++++++++++ configure.win | 4 ++++ src/Makevars.in | 16 ++++++++++++---- src/Makevars.win.in | 5 ++--- 5 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/build-wasm.yml diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 0000000..a9c2d74 --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -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::. diff --git a/configure b/configure index 3586297..054ae9f 100755 --- a/configure +++ b/configure @@ -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 diff --git a/configure.win b/configure.win index afc4456..e37306d 100755 --- a/configure.win +++ b/configure.win @@ -21,6 +21,8 @@ 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 @@ -28,6 +30,8 @@ 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 diff --git a/src/Makevars.in b/src/Makevars.in index f281805..8dd0db8 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -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 @@ -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: diff --git a/src/Makevars.win.in b/src/Makevars.win.in index 450c706..1de05ba 100644 --- a/src/Makevars.win.in +++ b/src/Makevars.win.in @@ -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