Skip to content

Commit 94d9ca8

Browse files
committed
chore: Attempt R CMD check fix
1 parent 7f5d345 commit 94d9ca8

File tree

5 files changed

+97
-50
lines changed

5 files changed

+97
-50
lines changed

configure

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
11
#!/usr/bin/env sh
22
: "${R_HOME=`R RHOME`}"
3-
"${R_HOME}/bin/Rscript" tools/msrv.R
4-
5-
# Set CRAN_FLAGS based on the NOT_CRAN value
6-
if [ "${NOT_CRAN}" != "true" ] && [ -f ./src/rust/vendor.tar.xz ]; then
7-
export CRAN_FLAGS="-j 2 --offline"
8-
else
9-
export CRAN_FLAGS=""
10-
fi
11-
12-
# delete Makevars if it is present
13-
[ -f src/Makevars ] && rm src/Makevars
14-
15-
# Substitute @CRAN_FLAGS@ in Makevars.in with the actual value of $CRAN_FLAGS
16-
sed -e "s|@CRAN_FLAGS@|$CRAN_FLAGS|" src/Makevars.in > src/Makevars
3+
"${R_HOME}/bin/Rscript" tools/config.R

configure.win

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
11
#!/usr/bin/env sh
2-
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/msrv.R
3-
4-
# Set CRAN_FLAGS based on the NOT_CRAN value
5-
if [ "${NOT_CRAN}" != "true" ] && [ -f ./src/rust/vendor.tar.xz ]; then
6-
export CRAN_FLAGS="-j 2 --offline"
7-
else
8-
export CRAN_FLAGS=""
9-
fi
10-
11-
# delete Makevars.win if it is present
12-
[ -f src/Makevars.win ] && rm src/Makevars.win
13-
14-
# Substitute @CRAN_FLAGS@ in Makevars.in with the actual value of $CRAN_FLAGS
15-
sed -e "s|@CRAN_FLAGS@|$CRAN_FLAGS|" src/Makevars.win.in > src/Makevars.win
2+
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/config.R

src/Makevars.in

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
TARGET_DIR = ./rust/target
2-
LIBDIR = $(TARGET_DIR)/release
2+
LIBDIR = $(TARGET_DIR)/@LIBDIR@
33
STATLIB = $(LIBDIR)/libtap_lock.a
44
PKG_LIBS = -L$(LIBDIR) -ltap_lock
55

6-
all: C_clean
6+
all: $(SHLIB) rust_clean
7+
8+
.PHONY: $(STATLIB)
79

810
$(SHLIB): $(STATLIB)
911

@@ -32,13 +34,13 @@ $(STATLIB):
3234

3335
export CARGO_HOME=$(CARGOTMP) && \
3436
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
35-
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
37+
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
3638

3739
# Always clean up CARGOTMP
3840
rm -Rf $(CARGOTMP);
3941

40-
C_clean:
41-
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
42+
rust_clean: $(SHLIB)
43+
rm -Rf $(CARGOTMP) $(VENDOR_DIR) @CLEAN_TARGET@
4244

4345
clean:
44-
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR) $(VENDOR_DIR)
46+
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)

src/Makevars.win.in

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
TARGET = $(subst 64,x86_64,$(subst 32,i686,$(WIN)))-pc-windows-gnu
22

33
TARGET_DIR = ./rust/target
4-
LIBDIR = $(TARGET_DIR)/$(TARGET)/release
4+
LIBDIR = $(TARGET_DIR)/$(TARGET)/@LIBDIR@
55
STATLIB = $(LIBDIR)/libtap_lock.a
6-
PKG_LIBS = -L$(LIBDIR) -ltap_lock -lws2_32 -lntdll -lbcrypt -luserenv
6+
PKG_LIBS = -L$(LIBDIR) -ltap_lock -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll
77

8-
all: C_clean
8+
all: $(SHLIB) rust_clean
9+
10+
.PHONY: $(STATLIB)
911

1012
$(SHLIB): $(STATLIB)
1113

1214
CARGOTMP = $(CURDIR)/.cargo
15+
VENDOR_DIR = vendor
1316

1417
$(STATLIB):
1518
mkdir -p $(TARGET_DIR)/libgcc_mock
16-
# `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have
17-
# `libgcc_eh` due to the compilation settings. So, in order to please the
18-
# compiler, we need to add empty `libgcc_eh` to the library search paths.
19-
#
20-
# For more details, please refer to
21-
# https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316
2219
touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a
2320

24-
# When the NOT_CRAN flag is *not* set, the vendor.tar.xz, if present,
25-
# is unzipped and used for offline compilation.
2621
if [ "$(NOT_CRAN)" != "true" ]; then \
2722
if [ -f ./rust/vendor.tar.xz ]; then \
2823
tar xf rust/vendor.tar.xz && \
@@ -33,15 +28,14 @@ $(STATLIB):
3328

3429
# Build the project using Cargo with additional flags
3530
export CARGO_HOME=$(CARGOTMP) && \
36-
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \
37-
export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
38-
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
31+
export LIBRARY_PATH="$(LIBRARY_PATH);$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
32+
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib @PROFILE@ --manifest-path=rust/Cargo.toml --target-dir=$(TARGET_DIR)
3933

4034
# Always clean up CARGOTMP
4135
rm -Rf $(CARGOTMP);
4236

43-
C_clean:
44-
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
37+
rust_clean: $(SHLIB)
38+
rm -Rf $(CARGOTMP) $(VENDOR_DIR) @CLEAN_TARGET@
4539

4640
clean:
4741
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)

tools/config.R

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# check the packages MSRV first
2+
source("tools/msrv.R")
3+
4+
# check DEBUG and NOT_CRAN environment variables
5+
env_debug <- Sys.getenv("DEBUG")
6+
env_not_cran <- Sys.getenv("NOT_CRAN")
7+
8+
# check if the vendored zip file exists
9+
vendor_exists <- file.exists("src/rust/vendor.tar.xz")
10+
11+
is_not_cran <- env_not_cran != ""
12+
is_debug <- env_debug != ""
13+
14+
if (is_debug) {
15+
# if we have DEBUG then we set not cran to true
16+
# CRAN is always release build
17+
is_not_cran <- TRUE
18+
message("Creating DEBUG build.")
19+
}
20+
21+
if (!is_not_cran) {
22+
message("Building for CRAN.")
23+
}
24+
25+
# we set cran flags only if NOT_CRAN is empty and if
26+
# the vendored crates are present.
27+
.cran_flags <- ifelse(
28+
!is_not_cran && vendor_exists,
29+
"-j 2 --offline",
30+
""
31+
)
32+
33+
# when DEBUG env var is present we use `--debug` build
34+
.profile <- ifelse(is_debug, "", "--release")
35+
.clean_targets <- ifelse(is_debug, "", "$(TARGET_DIR)")
36+
37+
# when we are using a debug build we need to use target/debug instead of target/release
38+
.libdir <- ifelse(is_debug, "debug", "release")
39+
40+
# read in the Makevars.in file
41+
is_windows <- .Platform[["OS.type"]] == "windows"
42+
43+
# if windows we replace in the Makevars.win.in
44+
mv_fp <- ifelse(
45+
is_windows,
46+
"src/Makevars.win.in",
47+
"src/Makevars.in"
48+
)
49+
50+
# set the output file
51+
mv_ofp <- ifelse(
52+
is_windows,
53+
"src/Makevars.win",
54+
"src/Makevars"
55+
)
56+
57+
# delete the existing Makevars{.win}
58+
if (file.exists(mv_ofp)) {
59+
message("Cleaning previous `", mv_ofp, "`.")
60+
invisible(file.remove(mv_ofp))
61+
}
62+
63+
# read as a single string
64+
mv_txt <- readLines(mv_fp)
65+
66+
# replace placeholder values
67+
new_txt <- gsub("@CRAN_FLAGS@", .cran_flags, mv_txt) |>
68+
gsub("@PROFILE@", .profile, x = _) |>
69+
gsub("@CLEAN_TARGET@", .clean_targets, x = _) |>
70+
gsub("@LIBDIR@", .libdir, x = _)
71+
72+
message("Writing `", mv_ofp, "`.")
73+
con <- file(mv_ofp, open = "wb")
74+
writeLines(new_txt, con, sep = "\n")
75+
close(con)
76+
77+
message("`tools/config.R` has finished.")

0 commit comments

Comments
 (0)