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

Try adding back RcppArmadillo #78

Merged
merged 7 commits into from
Sep 3, 2024
Merged

Try adding back RcppArmadillo #78

merged 7 commits into from
Sep 3, 2024

Conversation

kbenoit
Copy link
Contributor

@kbenoit kbenoit commented Sep 2, 2024

@koheiw this branch needs to address how to get this package working with the quanteda v4.1.0 that broke it.

With quanteda 4.1.0 installed, the package fails to build:

══ Documenting ════════════════════════════════════════════════════════════════════════════════════════════════════════════
ℹ Updating quanteda.textstats documentation
ℹ Loading quanteda.textstats
Exports from /Users/kbenoit/Dropbox (Personal)/GitHub/quanteda/quanteda.textstats/src/collocations.cpp:
   DataFrame cpp_collocations(const List& texts_, const CharacterVector& types_, const IntegerVector& words_ignore_, const unsigned int count_min, const IntegerVector sizes_, const String& method, const double smoothing, const int thread = -1)

Exports from /Users/kbenoit/Dropbox (Personal)/GitHub/quanteda/quanteda.textstats/src/keyness.cpp:
   Rcpp::NumericVector cpp_keyness(arma::sp_mat& mt, const std::string measure, const std::string correct, const int thread = -1)

/Users/kbenoit/Dropbox (Personal)/GitHub/quanteda/quanteda.textstats/src/RcppExports.cpp updated.
/Users/kbenoit/Dropbox (Personal)/GitHub/quanteda/quanteda.textstats/R/RcppExports.R updated.
ℹ Re-compiling quanteda.textstats (debug build)
── R CMD INSTALL ──────────────────────────────────────────────────────────────────────────────────────────────────────────
─  installing *source* package ‘quanteda.textstats’ ...
   ** using staged installation
   ** libs
   using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
   using SDK: ‘MacOSX14.4.sdk’
   clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/quanteda/include' -I/opt/R/arm64/include   -DARMA_64BIT_WORD=1 `/Library/Frameworks/R.framework/Resources/bin/Rscript ../inst/deftbb.R` -fPIC  -falign-functions=64 -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always  -c RcppExports.cpp -o RcppExports.o
   clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/quanteda/include' -I/opt/R/arm64/include   -DARMA_64BIT_WORD=1 `/Library/Frameworks/R.framework/Resources/bin/Rscript ../inst/deftbb.R` -fPIC  -falign-functions=64 -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always  -c collocations.cpp -o collocations.o
   In file included from collocations.cpp:1:
   In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/quanteda/include/lib.h:17:
   In file included from /usr/local/include/tbb/tbb.h:17:
   /usr/local/include/tbb/../oneapi/tbb.h:28:10: fatal error: 'oneapi/tbb/blocked_range.h' file not found
   #include "oneapi/tbb/blocked_range.h"
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   1 error generated.
   make: *** [collocations.o] Error 1
   ERROR: compilation failed for package ‘quanteda.textstats’
─  removing ‘/private/var/folders/rc/y2gv0_dn0z19ygq271w7f9dr0000gq/T/Rtmp4XI4tY/devtools_install_b2a400c25b9/quanteda.textstats’
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'R' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Backtrace:
 1. devtools::check(args = c("--as-cran"), check_dir = dirname(getwd()))
 2. devtools::document(pkg, quiet = quiet)
 3. roxygen2::roxygenise(pkg$path, roclets)
 4. local load_code(base_path)
 5. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
 6. pkgbuild::compile_dll(path, quiet = quiet)
 7. pkgbuild:::withr_with_makevars(compiler_flags(debug), { …
 8. pkgbuild:::withr_with_envvar(c(R_MAKEVARS_USER = makevars_file), { …
 9. base::force(code)
10. base::force(code)
11. pkgbuild:::withr_with_envvar(c(DEBUG = "true"), build())
12. base::force(code)
13. pkgbuild::build()
14. pkgbuild:::install_min(path, dest = install_dir, components = "libs", args = if (needs_clean(path)) "--preclean", …
15. pkgbuild::rcmd_build_tools("INSTALL", c(path, paste("--library=", dest, …
16. pkgbuild::with_build_tools({ …
17. base::withCallingHandlers(callr::rcmd_safe(..., env = env, spinner = FALSE, …
18. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, …
19. callr:::run_r(options)
20. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, …
21. base::with.default(options, with_envvar(env, do.call(processx::run, …
22. base::eval(substitute(expr), data, enclos = parent.frame())
23. base::eval(substitute(expr), data, enclos = parent.frame())
24. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs, …
25. base::force(code)
26. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), …
27. (function (command = NULL, args = character(), error_on_status = TRUE, …
28. base::throw(new_process_error(res, call = sys.call(), echo = echo, …
29. | base::signalCondition(cond)
30. (function (e) …
31. asNamespace("callr")$err$throw(e)
Execution halted

Exited with status 1.

@koheiw
Copy link
Collaborator

koheiw commented Sep 3, 2024

I fixed linking to RcppArmadillo and Github actions. It passes all the checks. The TBB issue is probably unrelated to changes in this PR.

@kbenoit
Copy link
Contributor Author

kbenoit commented Sep 3, 2024

It passes the checks but that's against the CRAN version of 4.0.2. With 4.1.0 installed locally, I still get:

── R CMD INSTALL ──────────────────────────────────────────────────────────────────────────────────────────────────────────
─  installing *source* package ‘quanteda.textstats’ ...
   ** using staged installation
   ** libs
   using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
   using SDK: ‘MacOSX14.4.sdk’
   clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Users/kbenoit/Library/R/arm64/4.4/library/Rcpp/include' -I'/Users/kbenoit/Library/R/arm64/4.4/library/RcppArmadillo/include' -I'/Users/kbenoit/Library/R/arm64/4.4/library/quanteda/include' -I/opt/R/arm64/include   -DARMA_64BIT_WORD=1 `/Library/Frameworks/R.framework/Resources/bin/Rscript ../inst/deftbb.R` -fPIC  -falign-functions=64 -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always  -c RcppExports.cpp -o RcppExports.o
   clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Users/kbenoit/Library/R/arm64/4.4/library/Rcpp/include' -I'/Users/kbenoit/Library/R/arm64/4.4/library/RcppArmadillo/include' -I'/Users/kbenoit/Library/R/arm64/4.4/library/quanteda/include' -I/opt/R/arm64/include   -DARMA_64BIT_WORD=1 `/Library/Frameworks/R.framework/Resources/bin/Rscript ../inst/deftbb.R` -fPIC  -falign-functions=64 -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always  -c collocations.cpp -o collocations.o
   In file included from collocations.cpp:1:
   In file included from /Users/kbenoit/Library/R/arm64/4.4/library/quanteda/include/lib.h:17:
   In file included from /usr/local/include/tbb/tbb.h:17:
   /usr/local/include/tbb/../oneapi/tbb.h:28:10: fatal error: 'oneapi/tbb/blocked_range.h' file not found
   #include "oneapi/tbb/blocked_range.h"
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   1 error generated.
   make: *** [collocations.o] Error 1
   ERROR: compilation failed for package ‘quanteda.textstats’
─  removing ‘/private/var/folders/rc/y2gv0_dn0z19ygq271w7f9dr0000gq/T/RtmpMW9ml6/devtools_install_16aeb49a720f6/quanteda.textstats’
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'R' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Backtrace:
 1. base::suppressPackageStartupMessages({ …
 2. base::withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
 3. devtools::document(roclets = c("rd", "collate", "namespace", …
 4. roxygen2::roxygenise(pkg$path, roclets)
 5. local load_code(base_path)
 6. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
 7. pkgbuild::compile_dll(path, quiet = quiet)
 8. pkgbuild:::withr_with_makevars(compiler_flags(debug), { …
 9. pkgbuild:::withr_with_envvar(c(R_MAKEVARS_USER = makevars_file), { …
10. base::force(code)
11. base::force(code)
12. pkgbuild:::withr_with_envvar(c(DEBUG = "true"), build())
13. base::force(code)
14. pkgbuild::build()
15. pkgbuild:::install_min(path, dest = install_dir, components = "libs", args = if (needs_clean(path)) "--preclean", …
16. pkgbuild::rcmd_build_tools("INSTALL", c(path, paste("--library=", dest, …
17. pkgbuild::with_build_tools({ …
18. base::withCallingHandlers(callr::rcmd_safe(..., env = env, spinner = FALSE, …
19. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, …
20. callr:::run_r(options)
21. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, …
22. base::with.default(options, with_envvar(env, do.call(processx::run, …
23. base::eval(substitute(expr), data, enclos = parent.frame())
24. base::eval(substitute(expr), data, enclos = parent.frame())
25. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs, …
26. base::force(code)
27. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), …
28. (function (command = NULL, args = character(), error_on_status = TRUE, …
29. base::throw(new_process_error(res, call = sys.call(), echo = echo, …
30. | base::signalCondition(cond)
31. (function (e) …
32. asNamespace("callr")$err$throw(e)
Execution halted

Exited with status 1.

@koheiw
Copy link
Collaborator

koheiw commented Sep 3, 2024

It compiles with quanteda v4.1.0 on my Windows and Linux. I think the linker cannot find the library on your Mac because we are not using autoconf in this package. TBB flag is inserted based on quanteda's installation.

https://github.com/quanteda/quanteda.textstats/blob/master/inst/libtbb.R

In quanteda, the result pkg-config --libs tbb is assined to @TBB_LIBS@ in https://github.com/quanteda/quanteda/blob/master/src/Makevars.in by by autoconfig. What do you see if you run pkg-config --libs tbb on your Mac?

@kbenoit
Copy link
Contributor Author

kbenoit commented Sep 3, 2024

(base) 192:quanteda.textstats kbenoit$ pkg-config --libs tbb
-L/opt/homebrew/Cellar/tbb/2021.13.0/lib -ltbb

@kbenoit kbenoit merged commit 11727bf into master Sep 3, 2024
6 checks passed
@kbenoit kbenoit deleted the fix-quanteda-4_1_0 branch September 3, 2024 09:23
@koheiw
Copy link
Collaborator

koheiw commented Sep 3, 2024

Does it build if you add -L/opt/homebrew/Cellar/tbb/2021.13.0/lib to Makevars.in?

If so, we could change https://github.com/quanteda/quanteda.textstats/blob/master/inst/libtbb.R to

#' Print TBB flag in makevars
if (Sys.info()[["sysname"]] == "Windows") {
    if (getRversion() >= "4.3.0") {
        cat("-ltbb12")
    } else {
        cat("-ltbb_static")
    }
} else {
    if (quanteda:::cpp_tbb_enabled()) {
        cat("pkg-config --libs tbb")
    }
}

pkg-config --libs tbb returns -ltbb so does no harm on my Ubuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants