Skip to content

Commit 35a0612

Browse files
jibarozzojdhoffa
andauthored
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]>
1 parent cc66a7a commit 35a0612

20 files changed

+672
-0
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
^_pkgdown\.yml$
77
^docs$
88
^pkgdown$
9+
10+
^src/rust/.cargo$
11+
^src/rust/target$

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Config/testthat/edition: 3
1414
Encoding: UTF-8
1515
Roxygen: list(markdown = TRUE)
1616
RoxygenNote: 7.3.2
17+
SystemRequirements: Cargo (Rust's package manager), rustc

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method("$<-",savvy_multiverse__sealed)
4+
S3method("[[<-",savvy_multiverse__sealed)
5+
S3method(print,Person__bundle)
6+
export(int_times_int)
7+
export(to_upper)
8+
useDynLib(multiverse, .registration = TRUE)

R/000-wrappers.R

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Generated by savvy: do not edit by hand
2+
#
3+
# Note:
4+
# This wrapper file is named as `000-wrappers.R` so that this file is loaded
5+
# first, which allows users to override the functions defined here (e.g., a
6+
# print() method for an enum).
7+
8+
#' @useDynLib multiverse, .registration = TRUE
9+
#' @keywords internal
10+
NULL
11+
12+
# Check class and extract the external pointer embedded in the environment
13+
.savvy_extract_ptr <- function(e, class) {
14+
if(is.null(e)) {
15+
return(NULL)
16+
}
17+
18+
if(inherits(e, class)) {
19+
e$.ptr
20+
} else {
21+
msg <- paste0("Expected ", class, ", got ", class(e)[1])
22+
stop(msg, call. = FALSE)
23+
}
24+
}
25+
26+
# Prohibit modifying environments
27+
28+
#' @export
29+
`$<-.savvy_multiverse__sealed` <- function(x, name, value) {
30+
class <- gsub("__bundle$", "", class(x)[1])
31+
stop(class, " cannot be modified", call. = FALSE)
32+
}
33+
34+
#' @export
35+
`[[<-.savvy_multiverse__sealed` <- function(x, i, value) {
36+
class <- gsub("__bundle$", "", class(x)[1])
37+
stop(class, " cannot be modified", call. = FALSE)
38+
}
39+
40+
#' Convert Input To Upper-Case
41+
#'
42+
#' @param x A character vector.
43+
#' @returns A character vector with upper case version of the input.
44+
#' @export
45+
`to_upper` <- function(`x`) {
46+
.Call(savvy_to_upper__impl, `x`)
47+
}
48+
49+
#' Multiply Input By Another Input
50+
#'
51+
#' @param x An integer vector.
52+
#' @param y An integer to multiply.
53+
#' @returns An integer vector with values multiplied by `y`.
54+
#' @export
55+
`int_times_int` <- function(`x`, `y`) {
56+
.Call(savvy_int_times_int__impl, `x`, `y`)
57+
}
58+
59+
### wrapper functions for Person
60+
61+
`Person_set_name` <- function(self) {
62+
function(`name`) {
63+
invisible(.Call(savvy_Person_set_name__impl, `self`, `name`))
64+
}
65+
}
66+
67+
`Person_name` <- function(self) {
68+
function() {
69+
.Call(savvy_Person_name__impl, `self`)
70+
}
71+
}
72+
73+
`.savvy_wrap_Person` <- function(ptr) {
74+
e <- new.env(parent = emptyenv())
75+
e$.ptr <- ptr
76+
e$`set_name` <- `Person_set_name`(ptr)
77+
e$`name` <- `Person_name`(ptr)
78+
79+
class(e) <- c("Person", "savvy_multiverse__sealed")
80+
e
81+
}
82+
83+
84+
85+
`Person` <- new.env(parent = emptyenv())
86+
87+
### associated functions for Person
88+
89+
`Person`$`new` <- function() {
90+
.savvy_wrap_Person(.Call(savvy_Person_new__impl))
91+
}
92+
93+
`Person`$`associated_function` <- function() {
94+
.Call(savvy_Person_associated_function__impl)
95+
}
96+
97+
98+
class(`Person`) <- c("Person__bundle", "savvy_multiverse__sealed")
99+
100+
#' @export
101+
`print.Person__bundle` <- function(x, ...) {
102+
cat('Person')
103+
}
104+

cleanup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -f src/Makevars

cleanup.win

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -f src/Makevars.win

configure

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Even when `cargo` is on `PATH`, `rustc` might not be in some cases. This adds
2+
# ~/.cargo/bin to PATH to address such cases. Note that is not always available
3+
# (e.g. or on Ubuntu with Rust installed via APT).
4+
if [ -d "${HOME}/.cargo/bin" ]; then
5+
export PATH="${PATH}:${HOME}/.cargo/bin"
6+
fi
7+
8+
CARGO_VERSION="$(cargo --version)"
9+
10+
if [ $? -ne 0 ]; then
11+
echo "-------------- ERROR: CONFIGURATION FAILED --------------------"
12+
echo ""
13+
echo "The cargo command is not available. To install Rust, please refer"
14+
echo "to the official instruction:"
15+
echo ""
16+
echo "https://www.rust-lang.org/tools/install"
17+
echo ""
18+
echo "---------------------------------------------------------------"
19+
20+
exit 1
21+
fi
22+
23+
# There's a little chance that rustc is not available on PATH while cargo is.
24+
# So, just ignore the error case.
25+
RUSTC_VERSION="$(rustc --version || true)"
26+
27+
# Report the version of Rustc to comply with the CRAN policy
28+
echo "using Rust package manager: '${CARGO_VERSION}'"
29+
echo "using Rust compiler: '${RUSTC_VERSION}'"
30+
31+
if [ "$(uname)" = "Emscripten" ]; then
32+
TARGET="wasm32-unknown-emscripten"
33+
fi
34+
35+
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
36+
if [ "${DEBUG}" = "true" ]; then
37+
PROFILE=dev
38+
else
39+
PROFILE=release
40+
fi
41+
42+
sed \
43+
-e "s/@TARGET@/${TARGET}/" \
44+
-e "s/@PROFILE@/${PROFILE}/" \
45+
src/Makevars.in > src/Makevars

configure.win

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CARGO_VERSION="$(cargo --version)"
2+
3+
if [ $? -ne 0 ]; then
4+
echo "-------------- ERROR: CONFIGURATION FAILED --------------------"
5+
echo ""
6+
echo "The cargo command is not available. To install Rust, please refer"
7+
echo "to the official instruction:"
8+
echo ""
9+
echo "https://www.rust-lang.org/tools/install"
10+
echo ""
11+
echo "---------------------------------------------------------------"
12+
13+
exit 1
14+
fi
15+
16+
# There's a little chance that rustc is not available on PATH while cargo is.
17+
# So, just ignore the error case.
18+
RUSTC_VERSION="$(rustc --version || true)"
19+
20+
# Report the version of Rustc to comply with the CRAN policy
21+
echo "using Rust package manager: '${CARGO_VERSION}'"
22+
echo "using Rust compiler: '${RUSTC_VERSION}'"
23+
24+
# catch DEBUG envvar, which is passed from pkgbuild::compile_dll()
25+
if [ "${DEBUG}" = "true" ]; then
26+
PROFILE=dev
27+
else
28+
PROFILE=release
29+
fi
30+
31+
sed \
32+
-e "s/@TARGET@/x86_64-pc-windows-gnu/" \
33+
-e "s/@PROFILE@/${PROFILE}/" \
34+
src/Makevars.win.in > src/Makevars.win

man/int_times_int.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/to_upper.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)