Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@
"config.R",
save_as = file.path("tools", "config.R"),
quiet = quiet,
overwrite = overwrite
overwrite = overwrite,
data = list(pkg_name = pkg_name)
)

# add configure and configure.win templates
Expand All @@ -222,7 +223,8 @@
)

# create settings.json file
if (is_vscode() || is_positron()) {
if (!identical(Sys.getenv("TESTTHAT"), "true") &&
(is_vscode() || is_positron())) {

Check warning on line 227 in R/use_extendr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_extendr.R,line=227,col=4,[indentation_linter] Indentation should be 8 spaces but is 4 spaces.
use_vscode()
}

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(STATLIB):

export CARGO_HOME=$(CARGOTMP) && \
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@ @FEATURES@

# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $(STATLIB):
# Build the project using Cargo with additional flags
export CARGO_HOME=$(CARGOTMP) && \
export LIBRARY_PATH="$(LIBRARY_PATH);$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib @PROFILE@ --manifest-path=rust/Cargo.toml --target-dir=$(TARGET_DIR)
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib @PROFILE@ --manifest-path=rust/Cargo.toml --target-dir=$(TARGET_DIR) @FEATURES@

# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
Expand Down
38 changes: 37 additions & 1 deletion inst/templates/config.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
args <- commandArgs(TRUE) # configure-args

# Note: Any variables prefixed with `.` are used for text
# replacement in the Makevars.in and Makevars.win.in

# check the packages MSRV first
source("tools/msrv.R")

# Configure arguments
input_profile <- args[[1L]]
input_features <- args[[2L]]

if (!nzchar(input_profile)) {
input_profile <- Sys.getenv("{{{pkg_name}}}}_PROFILE")
}

if (!nzchar(input_features)) {
input_features <- Sys.getenv("{{{pkg_name}}}}_FEATURES")
}

# check DEBUG and NOT_CRAN environment variables
env_debug <- Sys.getenv("DEBUG")
env_not_cran <- Sys.getenv("NOT_CRAN")
Expand Down Expand Up @@ -34,7 +48,28 @@ if (!is_not_cran) {
)

# when DEBUG env var is present we use `--debug` build
.profile <- ifelse(is_debug, "", "--release")
.profile <- if (nzchar(input_profile)) {
message("Using input profile: --", input_profile)
sprintf("--%s", input_profile)
} else if (is_debug) {
""
} else {
"--release"
}

if (nzchar(input_features)) {
.features <- unique(strsplit(input_features, "[, ]")[[1L]])
.features <- .features[nzchar(.features)]
if (length(.features)) {
# Space or comma separated list of features to activate
.features <- paste(.features, collapse = ",")
message("Using input features: ", .features)
.features <- sprintf("--features %s", .features)
}
} else {
.features <- ""
}

.clean_targets <- ifelse(is_debug, "", "$(TARGET_DIR)")

# We specify this target when building for webR
Expand Down Expand Up @@ -99,6 +134,7 @@ mv_txt <- readLines(mv_fp)
# replace placeholder values
new_txt <- gsub("@CRAN_FLAGS@", .cran_flags, mv_txt) |>
gsub("@PROFILE@", .profile, x = _) |>
gsub("@FEATURES@", .features, x = _) |>
gsub("@CLEAN_TARGET@", .clean_targets, x = _) |>
gsub("@LIBDIR@", .libdir, x = _) |>
gsub("@TARGET@", .target, x = _) |>
Expand Down
28 changes: 27 additions & 1 deletion inst/templates/configure
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
#!/usr/bin/env sh

# Initialize variables
FEATURES=""
PROFILE=""

# Parse and validate configure arguments
for arg in "$@"; do
case $arg in
--with-features=*)
value="${arg#*=}"
if [ -n "$FEATURES" ]; then
FEATURES="${FEATURES},${value}"
else
FEATURES="${value}"
fi
;;
--with-profile=*)
PROFILE="${arg#*=}"
;;
*)
echo "configure: error: unknown argument: $arg" >&2
exit 1
;;
esac
done

: "${R_HOME=`R RHOME`}"
"${R_HOME}/bin/Rscript" tools/config.R
"${R_HOME}/bin/Rscript" tools/config.R "${PROFILE}" "${FEATURES}"
28 changes: 26 additions & 2 deletions inst/templates/configure.win
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
#!/usr/bin/env sh
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/config.R
# Initialize variables
FEATURES=""
PROFILE=""

# Parse and validate configure arguments
for arg in "$@"; do
case $arg in
--with-features=*)
value="${arg#*=}"
if [ -n "$FEATURES" ]; then
FEATURES="${FEATURES},${value}"
else
FEATURES="${value}"
fi
;;
--with-profile=*)
PROFILE="${arg#*=}"
;;
*)
echo "configure.win: error: unknown argument: $arg" >&2
exit 1
;;
esac
done

"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/config.R "${PROFILE}" "${FEATURES}"
62 changes: 56 additions & 6 deletions tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,66 @@
cat_file("configure")
Output
#!/usr/bin/env sh

# Initialize variables
FEATURES=""
PROFILE=""

# Parse and validate configure arguments
for arg in "$@"; do
case $arg in
--with-features=*)
value="${arg#*=}"
if [ -n "$FEATURES" ]; then
FEATURES="${FEATURES},${value}"
else
FEATURES="${value}"
fi
;;
--with-profile=*)
PROFILE="${arg#*=}"
;;
*)
echo "configure: error: unknown argument: $arg" >&2
exit 1
;;
esac
done

: "${R_HOME=`R RHOME`}"
"${R_HOME}/bin/Rscript" tools/config.R
"${R_HOME}/bin/Rscript" tools/config.R "${PROFILE}" "${FEATURES}"

---

Code
cat_file("configure.win")
Output
#!/usr/bin/env sh
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/config.R
# Initialize variables
FEATURES=""
PROFILE=""

# Parse and validate configure arguments
for arg in "$@"; do
case $arg in
--with-features=*)
value="${arg#*=}"
if [ -n "$FEATURES" ]; then
FEATURES="${FEATURES},${value}"
else
FEATURES="${value}"
fi
;;
--with-profile=*)
PROFILE="${arg#*=}"
;;
*)
echo "configure.win: error: unknown argument: $arg" >&2
exit 1
;;
esac
done

"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" tools/config.R "${PROFILE}" "${FEATURES}"

---

Expand Down Expand Up @@ -223,7 +273,7 @@

export CARGO_HOME=$(CARGOTMP) && \
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@ @FEATURES@

# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
Expand Down Expand Up @@ -282,7 +332,7 @@
# Build the project using Cargo with additional flags
export CARGO_HOME=$(CARGOTMP) && \
export LIBRARY_PATH="$(LIBRARY_PATH);$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib @PROFILE@ --manifest-path=rust/Cargo.toml --target-dir=$(TARGET_DIR)
RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --target=$(TARGET) --lib @PROFILE@ --manifest-path=rust/Cargo.toml --target-dir=$(TARGET_DIR) @FEATURES@

# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
Expand Down Expand Up @@ -453,7 +503,7 @@

export CARGO_HOME=$(CARGOTMP) && \
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@
@PANIC_EXPORTS@RUSTFLAGS="$(RUSTFLAGS) --print=native-static-libs" cargo build @CRAN_FLAGS@ --lib @PROFILE@ --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) @TARGET@ @FEATURES@

# Always clean up CARGOTMP
rm -Rf $(CARGOTMP);
Expand Down
Loading