Skip to content

Commit

Permalink
add rcmdcheck to suggests update makevars templates to check for NOT_…
Browse files Browse the repository at this point in the history
…CRAN != true
  • Loading branch information
JosiahParry committed Nov 15, 2024
1 parent 1e10ecc commit 4404db8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 58 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Imports:
withr
Suggests:
devtools,
rcmdcheck,
knitr,
lintr,
rmarkdown,
Expand Down
6 changes: 3 additions & 3 deletions inst/templates/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ VENDOR_DIR = $(CURDIR)/vendor
# CRAN note: Cargo and Rustc versions are reported during
# configure via tools/msrv.R.
#
# When on CRAN, the vendor.tar.xz file is unzipped and used
# for offline compilation. It is ignored when NOT_CRAN != false
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
# is unzipped and used for offline compilation.
$(STATLIB):

# Check if NOT_CRAN is false and unzip vendor.tar.xz if so
if [ "$(NOT_CRAN)" = "false" ]; then \
if [ "$(NOT_CRAN)" != "true" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
Expand Down
5 changes: 3 additions & 2 deletions inst/templates/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ $(STATLIB):
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a

# Handle NOT_CRAN case: If NOT_CRAN is false, vendor tarball should be handled
if [ "$(NOT_CRAN)" = "false" ]; then \
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
# is unzipped and used for offline compilation.
if [ "$(NOT_CRAN)" != "true" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
Expand Down
91 changes: 38 additions & 53 deletions tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
v Adding "src/rust/vendor" to '.gitignore'.
v Adding "^src/Makevars$" to '.Rbuildignore'.
v Adding "src/Makevars" to '.gitignore'.
v Adding "^src/Makevars\\.win$" to '.Rbuildignore'.
v Adding "src/Makevars.win" to '.gitignore'.
v Finished configuring extendr for package testpkg.
* Please run `rextendr::document()` for changes to take effect.

Expand Down Expand Up @@ -69,12 +71,12 @@
# CRAN note: Cargo and Rustc versions are reported during
# configure via tools/msrv.R.
#
# When on CRAN, the vendor.tar.xz file is unzipped and used
# for offline compilation. It is ignored when NOT_CRAN != false
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
# is unzipped and used for offline compilation.
$(STATLIB):
# Check if NOT_CRAN is false and unzip vendor.tar.xz if so
if [ "$(NOT_CRAN)" = "false" ]; then \
if [ "$(NOT_CRAN)" != "true" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
Expand All @@ -87,13 +89,7 @@
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
# Always clean up CARGOTMP
rm -Rf $(CARGOTMP)
if [ "$(NOT_CRAN)" != "false" ]; then \
rm -Rf $(VENDOR_DIR); \
rm -Rf $(TARGET_DIR); \
rm -Rf $(LIBDIR)/build; \
fi
rm -Rf $(CARGOTMP);
C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
Expand All @@ -120,45 +116,40 @@
CARGOTMP = $(CURDIR)/.cargo
$(STATLIB):
mkdir -p $(TARGET_DIR)/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
#
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
# Handle NOT_CRAN case: If NOT_CRAN is false, vendor tarball should be handled
if [ "$(NOT_CRAN)" = "false" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
fi; \
fi
# CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2
# Build the project using Cargo with additional flags
export CARGO_HOME=$(CARGOTMP) && \
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo @CRAN_FLAGS@ build --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
mkdir -p $(TARGET_DIR)/libgcc_mock
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
# `libgcc_eh` due to the compilation settings. So, in order to please the
# compiler, we need to add empty `libgcc_eh` to the library search paths.
#
# For more details, please refer to
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
# is unzipped and used for offline compilation.
if [ "$(NOT_CRAN)" != "true" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \
fi; \
fi
# Always clean up CARGOTMP
rm -Rf $(CARGOTMP)
# CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2
# Build the project using Cargo with additional flags
export CARGO_HOME=$(CARGOTMP) && \
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo @CRAN_FLAGS@ build --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
if [ "$(NOT_CRAN)" != "false" ]; then \
rm -Rf $(VENDOR_DIR); \
rm -Rf $(TARGET_DIR); \
rm -Rf $(LIBDIR)/build; \
fi
# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)

---

Expand Down Expand Up @@ -320,12 +311,12 @@
# CRAN note: Cargo and Rustc versions are reported during
# configure via tools/msrv.R.
#
# When on CRAN, the vendor.tar.xz file is unzipped and used
# for offline compilation. It is ignored when NOT_CRAN != false
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
# is unzipped and used for offline compilation.
$(STATLIB):
# Check if NOT_CRAN is false and unzip vendor.tar.xz if so
if [ "$(NOT_CRAN)" = "false" ]; then \
if [ "$(NOT_CRAN)" != "true" ]; then \
if [ -f ./rust/vendor.tar.xz ]; then \
tar xf rust/vendor.tar.xz && \
mkdir -p $(CARGOTMP) && \
Expand All @@ -338,13 +329,7 @@
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
# Always clean up CARGOTMP
rm -Rf $(CARGOTMP)
if [ "$(NOT_CRAN)" != "false" ]; then \
rm -Rf $(VENDOR_DIR); \
rm -Rf $(TARGET_DIR); \
rm -Rf $(LIBDIR)/build; \
fi
rm -Rf $(CARGOTMP);
C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
Expand Down

0 comments on commit 4404db8

Please sign in to comment.