From a8d7434dc8f91343531cf436393a0547b50abee7 Mon Sep 17 00:00:00 2001 From: Josiah Parry Date: Mon, 28 Oct 2024 01:48:35 -0400 Subject: [PATCH] Add `--print=native-static-libs` when compiling (#393) * add linker info to Makevars * add link to PR * update snaps * update snaps * use tools/msrv.R and configure to address R-devel warnings * remove tools/msrv.R from use_cran_defaults() --- .github/workflows/test_pkg_gen.yaml | 11 ------- NEWS.md | 1 + R/cran-compliance.R | 36 --------------------- R/use_extendr.R | 37 ++++++++++++++++++++++ inst/templates/Makevars | 3 ++ inst/templates/Makevars.win | 3 ++ inst/templates/cran/Makevars | 3 ++ inst/templates/cran/Makevars.win | 3 ++ tests/testthat/_snaps/use_cran_defaults.md | 12 +++++-- tests/testthat/_snaps/use_extendr.md | 18 +++++++++++ 10 files changed, 77 insertions(+), 50 deletions(-) diff --git a/.github/workflows/test_pkg_gen.yaml b/.github/workflows/test_pkg_gen.yaml index 31826280..91e9a5c2 100644 --- a/.github/workflows/test_pkg_gen.yaml +++ b/.github/workflows/test_pkg_gen.yaml @@ -85,17 +85,6 @@ jobs: file.path("tests", "testthat", "test-hello.R") ) - # test NOT_CRAN envvar - brio::write_lines( - c( - "if [ \"$NOT_CRAN\" != \"true\" ]; then", - " exit 1", - "fi" - ), - file.path("configure") - ) - Sys.chmod("configure", "0755") - # TODO: allow warnings on oldrel (cf., https://stat.ethz.ch/pipermail/r-package-devel/2023q2/009229.html) if (.Platform$OS.type == "windows" && getRversion() < "4.3.0") { error_on <- "error" diff --git a/NEWS.md b/NEWS.md index 61d690cc..246de4ea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # rextendr (development version) +* `Makevars` now prints linked static libraries at compile time * `use_extendr()` sets the `DESCRIPTION`'s `SystemRequirements` field according to CRAN policy to `Cargo (Rust's package manager), rustc` (#329) * Introduces new functions `use_cran_defaults()` and `vendor_pkgs()` to ease the publication of extendr-powered packages on CRAN. See the new article _CRAN compliant extendr packages_ on how to use these (#320). * `rust_sitrep()` now better communicates the status of the Rust toolchain and available targets. It also guides the user through necessary installation steps to fix Rust setup (#318). diff --git a/R/cran-compliance.R b/R/cran-compliance.R index 3e1d1a69..4ca7505f 100644 --- a/R/cran-compliance.R +++ b/R/cran-compliance.R @@ -52,42 +52,6 @@ use_cran_defaults <- function(path = ".", quiet = FALSE, overwrite = NULL, lib_n ) } - # create tools directory if it does not exist - if (!dir.exists("tools")) { - dir.create("tools") - } - - # add msrv.R template - use_rextendr_template( - "cran/msrv.R", - save_as = file.path("tools", "msrv.R"), - quiet = quiet, - overwrite = overwrite - ) - - # add configure and configure.win templates - use_rextendr_template( - "cran/configure", - save_as = "configure", - quiet = quiet, - overwrite = overwrite, - data = list(lib_name = lib_name) - ) - - # configure needs to be made executable - # ignore for Windows - if (.Platform[["OS.type"]] == "unix") { - Sys.chmod("configure", "0755") - } - - use_rextendr_template( - "cran/configure.win", - save_as = "configure.win", - quiet = quiet, - overwrite = overwrite, - data = list(lib_name = lib_name) - ) - # use CRAN specific Makevars templates use_rextendr_template( "cran/Makevars", diff --git a/R/use_extendr.R b/R/use_extendr.R index e0694db3..7c62d9c7 100644 --- a/R/use_extendr.R +++ b/R/use_extendr.R @@ -172,6 +172,43 @@ use_extendr <- function(path = ".", data = list(pkg_name = pkg_name) ) + # create tools directory if it does not exist + if (!dir.exists("tools")) { + dir.create("tools") + } + + # add msrv.R template + use_rextendr_template( + "cran/msrv.R", + save_as = file.path("tools", "msrv.R"), + quiet = quiet, + overwrite = overwrite + ) + + # add configure and configure.win templates + use_rextendr_template( + "cran/configure", + save_as = "configure", + quiet = quiet, + overwrite = overwrite, + data = list(lib_name = lib_name) + ) + + # configure needs to be made executable + # ignore for Windows + if (.Platform[["OS.type"]] == "unix") { + Sys.chmod("configure", "0755") + } + + use_rextendr_template( + "cran/configure.win", + save_as = "configure.win", + quiet = quiet, + overwrite = overwrite, + data = list(lib_name = lib_name) + ) + + if (!isTRUE(quiet)) { cli::cli_alert_success("Finished configuring {.pkg extendr} for package {.pkg {pkg_name}}.") cli::cli_ul( diff --git a/inst/templates/Makevars b/inst/templates/Makevars index 07ed90f4..6ec006bf 100644 --- a/inst/templates/Makevars +++ b/inst/templates/Makevars @@ -3,6 +3,9 @@ LIBDIR = $(TARGET_DIR)/release STATLIB = $(LIBDIR)/lib{{{lib_name}}}.a PKG_LIBS = -L$(LIBDIR) -l{{{lib_name}}} +# Print linked static libraries at compile time +export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) diff --git a/inst/templates/Makevars.win b/inst/templates/Makevars.win index e47a9ab2..4e2a4387 100644 --- a/inst/templates/Makevars.win +++ b/inst/templates/Makevars.win @@ -5,6 +5,9 @@ LIBDIR = $(TARGET_DIR)/$(TARGET)/release STATLIB = $(LIBDIR)/lib{{{lib_name}}}.a PKG_LIBS = -L$(LIBDIR) -l{{{lib_name}}} -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll +# Print linked static libraries at compile time +export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) diff --git a/inst/templates/cran/Makevars b/inst/templates/cran/Makevars index e2dc513e..0f0e40aa 100644 --- a/inst/templates/cran/Makevars +++ b/inst/templates/cran/Makevars @@ -3,6 +3,9 @@ LIBDIR = $(TARGET_DIR)/release STATLIB = $(LIBDIR)/lib{{{lib_name}}}.a PKG_LIBS = -L$(LIBDIR) -l{{{lib_name}}} +# Print linked static libraries at compile time +export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) diff --git a/inst/templates/cran/Makevars.win b/inst/templates/cran/Makevars.win index f19bb836..72f7479d 100644 --- a/inst/templates/cran/Makevars.win +++ b/inst/templates/cran/Makevars.win @@ -5,6 +5,9 @@ LIBDIR = $(TARGET_DIR)/$(TARGET)/release STATLIB = $(LIBDIR)/lib{{{lib_name}}}.a PKG_LIBS = -L$(LIBDIR) -l{{{lib_name}}} -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll +# Print linked static libraries at compile time +export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) diff --git a/tests/testthat/_snaps/use_cran_defaults.md b/tests/testthat/_snaps/use_cran_defaults.md index aa89ea55..4c637a16 100644 --- a/tests/testthat/_snaps/use_cran_defaults.md +++ b/tests/testthat/_snaps/use_cran_defaults.md @@ -17,6 +17,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' v Writing 'R/extendr-wrappers.R' + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect. @@ -25,9 +28,6 @@ Code use_cran_defaults() Message - v Writing 'tools/msrv.R' - v Writing 'configure' - v Writing 'configure.win' > File 'src/Makevars' already exists. Skip writing the file. > File 'src/Makevars.win' already exists. Skip writing the file. v Adding "^src/rust/vendor$" to '.Rbuildignore'. @@ -43,6 +43,9 @@ STATLIB = $(LIBDIR)/libtestpkg.a PKG_LIBS = -L$(LIBDIR) -ltestpkg + # Print linked static libraries at compile time + export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) @@ -81,6 +84,9 @@ STATLIB = $(LIBDIR)/libtestpkg.a PKG_LIBS = -L$(LIBDIR) -ltestpkg -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll + # Print linked static libraries at compile time + export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) diff --git a/tests/testthat/_snaps/use_extendr.md b/tests/testthat/_snaps/use_extendr.md index 7cf6ce67..bb281aff 100644 --- a/tests/testthat/_snaps/use_extendr.md +++ b/tests/testthat/_snaps/use_extendr.md @@ -17,6 +17,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' v Writing 'R/extendr-wrappers.R' + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect. @@ -48,6 +51,9 @@ STATLIB = $(LIBDIR)/libtestpkg.a PKG_LIBS = -L$(LIBDIR) -ltestpkg + # Print linked static libraries at compile time + export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) @@ -86,6 +92,9 @@ STATLIB = $(LIBDIR)/libtestpkg.a PKG_LIBS = -L$(LIBDIR) -ltestpkg -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll + # Print linked static libraries at compile time + export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB) @@ -212,6 +221,9 @@ > File 'src/rust/src/lib.rs' already exists. Skip writing the file. > File 'src/testpkg.wrap-win.def' already exists. Skip writing the file. > File 'R/extendr-wrappers.R' already exists. Skip writing the file. + > File 'tools/msrv.R' already exists. Skip writing the file. + > File 'configure' already exists. Skip writing the file. + > File 'configure.win' already exists. Skip writing the file. v Finished configuring extendr for package testpkg.wrap. * Please run `rextendr::document()` for changes to take effect. @@ -229,6 +241,9 @@ v Writing 'src/rust/src/lib.rs' v Writing 'src/testpkg-win.def' > File 'R/extendr-wrappers.R' already exists. Skip writing the file. + v Writing 'tools/msrv.R' + v Writing 'configure' + v Writing 'configure.win' v Finished configuring extendr for package testpkg. * Please run `rextendr::document()` for changes to take effect. @@ -260,6 +275,9 @@ STATLIB = $(LIBDIR)/libbar.a PKG_LIBS = -L$(LIBDIR) -lbar + # Print linked static libraries at compile time + export RUSTFLAGS=--print=native-static-libs + all: C_clean $(SHLIB): $(STATLIB)