-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default scaffolding with
savvy::savvy_init()
. (#7)
* Default scaffolding with `savvy::savvy_init()`. * Update configure Co-authored-by: Jackson Hoffart <[email protected]> --------- Co-authored-by: Jackson Hoffart <[email protected]>
- Loading branch information
Showing
20 changed files
with
672 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ | |
^_pkgdown\.yml$ | ||
^docs$ | ||
^pkgdown$ | ||
|
||
^src/rust/.cargo$ | ||
^src/rust/target$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method("$<-",savvy_multiverse__sealed) | ||
S3method("[[<-",savvy_multiverse__sealed) | ||
S3method(print,Person__bundle) | ||
export(int_times_int) | ||
export(to_upper) | ||
useDynLib(multiverse, .registration = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Generated by savvy: do not edit by hand | ||
# | ||
# Note: | ||
# This wrapper file is named as `000-wrappers.R` so that this file is loaded | ||
# first, which allows users to override the functions defined here (e.g., a | ||
# print() method for an enum). | ||
|
||
#' @useDynLib multiverse, .registration = TRUE | ||
#' @keywords internal | ||
NULL | ||
|
||
# Check class and extract the external pointer embedded in the environment | ||
.savvy_extract_ptr <- function(e, class) { | ||
if(is.null(e)) { | ||
return(NULL) | ||
} | ||
|
||
if(inherits(e, class)) { | ||
e$.ptr | ||
} else { | ||
msg <- paste0("Expected ", class, ", got ", class(e)[1]) | ||
stop(msg, call. = FALSE) | ||
} | ||
} | ||
|
||
# Prohibit modifying environments | ||
|
||
#' @export | ||
`$<-.savvy_multiverse__sealed` <- function(x, name, value) { | ||
class <- gsub("__bundle$", "", class(x)[1]) | ||
stop(class, " cannot be modified", call. = FALSE) | ||
} | ||
|
||
#' @export | ||
`[[<-.savvy_multiverse__sealed` <- function(x, i, value) { | ||
class <- gsub("__bundle$", "", class(x)[1]) | ||
stop(class, " cannot be modified", call. = FALSE) | ||
} | ||
|
||
#' Convert Input To Upper-Case | ||
#' | ||
#' @param x A character vector. | ||
#' @returns A character vector with upper case version of the input. | ||
#' @export | ||
`to_upper` <- function(`x`) { | ||
.Call(savvy_to_upper__impl, `x`) | ||
} | ||
|
||
#' Multiply Input By Another Input | ||
#' | ||
#' @param x An integer vector. | ||
#' @param y An integer to multiply. | ||
#' @returns An integer vector with values multiplied by `y`. | ||
#' @export | ||
`int_times_int` <- function(`x`, `y`) { | ||
.Call(savvy_int_times_int__impl, `x`, `y`) | ||
} | ||
|
||
### wrapper functions for Person | ||
|
||
`Person_set_name` <- function(self) { | ||
function(`name`) { | ||
invisible(.Call(savvy_Person_set_name__impl, `self`, `name`)) | ||
} | ||
} | ||
|
||
`Person_name` <- function(self) { | ||
function() { | ||
.Call(savvy_Person_name__impl, `self`) | ||
} | ||
} | ||
|
||
`.savvy_wrap_Person` <- function(ptr) { | ||
e <- new.env(parent = emptyenv()) | ||
e$.ptr <- ptr | ||
e$`set_name` <- `Person_set_name`(ptr) | ||
e$`name` <- `Person_name`(ptr) | ||
|
||
class(e) <- c("Person", "savvy_multiverse__sealed") | ||
e | ||
} | ||
|
||
|
||
|
||
`Person` <- new.env(parent = emptyenv()) | ||
|
||
### associated functions for Person | ||
|
||
`Person`$`new` <- function() { | ||
.savvy_wrap_Person(.Call(savvy_Person_new__impl)) | ||
} | ||
|
||
`Person`$`associated_function` <- function() { | ||
.Call(savvy_Person_associated_function__impl) | ||
} | ||
|
||
|
||
class(`Person`) <- c("Person__bundle", "savvy_multiverse__sealed") | ||
|
||
#' @export | ||
`print.Person__bundle` <- function(x, ...) { | ||
cat('Person') | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rm -f src/Makevars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rm -f src/Makevars.win |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Even when `cargo` is on `PATH`, `rustc` might not be in some cases. This adds | ||
# ~/.cargo/bin to PATH to address such cases. Note that is not always available | ||
# (e.g. or on Ubuntu with Rust installed via APT). | ||
if [ -d "${HOME}/.cargo/bin" ]; then | ||
export PATH="${PATH}:${HOME}/.cargo/bin" | ||
fi | ||
|
||
CARGO_VERSION="$(cargo --version)" | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "-------------- ERROR: CONFIGURATION FAILED --------------------" | ||
echo "" | ||
echo "The cargo command is not available. To install Rust, please refer" | ||
echo "to the official instruction:" | ||
echo "" | ||
echo "https://www.rust-lang.org/tools/install" | ||
echo "" | ||
echo "---------------------------------------------------------------" | ||
|
||
exit 1 | ||
fi | ||
|
||
# There's a little chance that rustc is not available on PATH while cargo is. | ||
# So, just ignore the error case. | ||
RUSTC_VERSION="$(rustc --version || true)" | ||
|
||
# Report the version of Rustc to comply with the CRAN policy | ||
echo "using Rust package manager: '${CARGO_VERSION}'" | ||
echo "using Rust compiler: '${RUSTC_VERSION}'" | ||
|
||
if [ "$(uname)" = "Emscripten" ]; then | ||
TARGET="wasm32-unknown-emscripten" | ||
fi | ||
|
||
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll() | ||
if [ "${DEBUG}" = "true" ]; then | ||
PROFILE=dev | ||
else | ||
PROFILE=release | ||
fi | ||
|
||
sed \ | ||
-e "s/@TARGET@/${TARGET}/" \ | ||
-e "s/@PROFILE@/${PROFILE}/" \ | ||
src/Makevars.in > src/Makevars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CARGO_VERSION="$(cargo --version)" | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "-------------- ERROR: CONFIGURATION FAILED --------------------" | ||
echo "" | ||
echo "The cargo command is not available. To install Rust, please refer" | ||
echo "to the official instruction:" | ||
echo "" | ||
echo "https://www.rust-lang.org/tools/install" | ||
echo "" | ||
echo "---------------------------------------------------------------" | ||
|
||
exit 1 | ||
fi | ||
|
||
# There's a little chance that rustc is not available on PATH while cargo is. | ||
# So, just ignore the error case. | ||
RUSTC_VERSION="$(rustc --version || true)" | ||
|
||
# Report the version of Rustc to comply with the CRAN policy | ||
echo "using Rust package manager: '${CARGO_VERSION}'" | ||
echo "using Rust compiler: '${RUSTC_VERSION}'" | ||
|
||
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll() | ||
if [ "${DEBUG}" = "true" ]; then | ||
PROFILE=dev | ||
else | ||
PROFILE=release | ||
fi | ||
|
||
sed \ | ||
-e "s/@TARGET@/x86_64-pc-windows-gnu/" \ | ||
-e "s/@PROFILE@/${PROFILE}/" \ | ||
src/Makevars.win.in > src/Makevars.win |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.o | ||
*.so | ||
*.dll | ||
target | ||
|
||
Makevars | ||
Makevars.win |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
TARGET = @TARGET@ | ||
|
||
PROFILE = @PROFILE@ | ||
|
||
# Add flags if necessary | ||
RUSTFLAGS = | ||
|
||
TARGET_DIR = $(CURDIR)/rust/target | ||
LIBDIR = $(TARGET_DIR)/$(TARGET)/$(subst dev,debug,$(PROFILE)) | ||
STATLIB = $(LIBDIR)/libmultiverse.a | ||
PKG_LIBS = -L$(LIBDIR) -lmultiverse | ||
|
||
CARGO_BUILD_ARGS = --lib --profile $(PROFILE) --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) | ||
|
||
all: C_clean | ||
|
||
$(SHLIB): $(STATLIB) | ||
|
||
$(STATLIB): | ||
# In some environments, ~/.cargo/bin might not be included in PATH, so we need | ||
# to set it here to ensure cargo can be invoked. It is appended to PATH and | ||
# therefore is only used if cargo is absent from the user's PATH. | ||
export PATH="$(PATH):$(HOME)/.cargo/bin" && \ | ||
export CC="$(CC)" && \ | ||
export CFLAGS="$(CFLAGS)" && \ | ||
export RUSTFLAGS="$(RUSTFLAGS)" && \ | ||
if [ "$(TARGET)" != "wasm32-unknown-emscripten" ]; then \ | ||
cargo build $(CARGO_BUILD_ARGS); \ | ||
else \ | ||
export CARGO_PROFILE_DEV_PANIC="abort" && \ | ||
export CARGO_PROFILE_RELEASE_PANIC="abort" && \ | ||
cargo +nightly build $(CARGO_BUILD_ARGS) --target $(TARGET) -Zbuild-std=panic_abort,std; \ | ||
fi | ||
|
||
C_clean: | ||
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) | ||
|
||
clean: | ||
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
TARGET = @TARGET@ | ||
|
||
PROFILE = @PROFILE@ | ||
|
||
# Add flags if necessary | ||
RUSTFLAGS = | ||
|
||
TARGET_DIR = $(CURDIR)/rust/target | ||
LIBDIR = $(TARGET_DIR)/$(TARGET)/$(subst dev,debug,$(PROFILE)) | ||
STATLIB = $(LIBDIR)/libmultiverse.a | ||
PKG_LIBS = -L$(LIBDIR) -lmultiverse -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll | ||
|
||
# Rtools doesn't have the linker in the location that cargo expects, so we need | ||
# to overwrite it via configuration. | ||
CARGO_LINKER = x86_64-w64-mingw32.static.posix-gcc.exe | ||
|
||
all: C_clean | ||
|
||
$(SHLIB): $(STATLIB) | ||
|
||
$(STATLIB): | ||
# When the GNU toolchain is used (i.e. on CRAN), -lgcc_eh is specified for | ||
# building proc-macro2, but Rtools doesn't contain libgcc_eh. This isn't used | ||
# in actual, but we need this tweak to please the compiler. | ||
mkdir -p $(LIBDIR)/libgcc_mock && touch $(LIBDIR)/libgcc_mock/libgcc_eh.a | ||
|
||
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \ | ||
export LIBRARY_PATH="$${LIBRARY_PATH};$(LIBDIR)/libgcc_mock" && \ | ||
export CC="$(CC)" && \ | ||
export CFLAGS="$(CFLAGS)" && \ | ||
export RUSTFLAGS="$(RUSTFLAGS)" && \ | ||
cargo build --target $(TARGET) --lib --profile $(PROFILE) --manifest-path ./rust/Cargo.toml --target-dir $(TARGET_DIR) | ||
|
||
C_clean: | ||
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) | ||
|
||
clean: | ||
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target |
Oops, something went wrong.