Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp11 dynlib #1921

Merged
merged 7 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
^internal$
^revdep-cloud$
^CRAN-SUBMISSION$
^\.vscode$
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
pachadotdev marked this conversation as resolved.
Show resolved Hide resolved
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Implicit usage of `numeric_version()` via comparison now always provides
character input. This is in response to a request from CRAN to anticipate
future solutions to <https://bugs.r-project.org/show_bug.cgi?id=18548>.
* `use_cpp11()` creates/edits DESCRIPTION and NAMESPACE, allowing to use C++
code directly.
* `.gitignore` now ignores `.vscode` for those who contribute to `usethis` from
pachadotdev marked this conversation as resolved.
Show resolved Hide resolved
that editor.

# usethis 2.2.1

Expand Down
15 changes: 15 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use_cpp11 <- function() {

check_cpp_register_deps()

check_cpp_dynlib()

invisible()
}

Expand All @@ -40,3 +42,16 @@ check_cpp_register_deps <- function() {
ui_todo("Now install {ui_value(cpp_register_deps[!installed])} to use cpp11.")
}
}

get_cpp_dynlib <- function() {
desc <- desc::desc(package = NULL)
desc$get_list("Package")[[1]]
}

check_cpp_dynlib <- function() {
pkgname <- get_cpp_dynlib()
roxygen_ns_append(
sprintf("@useDynLib %s, .registration = TRUE", pkgname)
pachadotdev marked this conversation as resolved.
Show resolved Hide resolved
)
roxygen_update_ns()
}
3 changes: 3 additions & 0 deletions tests/testthat/test-cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ test_that("use_cpp11() creates files/dirs, edits DESCRIPTION and .gitignore", {

ignores <- read_utf8(proj_path("src", ".gitignore"))
expect_true(all(c("*.o", "*.so", "*.dll") %in% ignores))

namespace <- read_utf8(proj_path("NAMESPACE"))
expect_true("# Generated by roxygen2: do not edit by hand" %in% namespace)
})

test_that("check_cpp_register_deps is silent if all installed, emits todo if not", {
Expand Down
Loading