diff --git a/NAMESPACE b/NAMESPACE index 1b93ebd..067fa51 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,4 @@ # Generated by roxygen2: do not edit by hand -export(hello_world) +export(os_info) useDynLib(osinfo, .registration = TRUE) diff --git a/R/extendr-wrappers.R b/R/extendr-wrappers.R index 1b22a83..1b04509 100644 --- a/R/extendr-wrappers.R +++ b/R/extendr-wrappers.R @@ -1,12 +1,18 @@ +# Generated by extendr: Do not edit by hand + # nolint start +# +# This file was created with the following call: +# .Call("wrap__make_osinfo_wrappers", use_symbols = TRUE, package_name = "osinfo") + #' @docType package #' @usage NULL #' @useDynLib osinfo, .registration = TRUE NULL -#' Return string `"Hello world!"` to R. -#' @export -hello_world <- function() .Call(wrap__hello_world) +#' get os information +os_info_impl <- function() .Call(wrap__os_info_impl) + # nolint end diff --git a/R/os-info.R b/R/os-info.R new file mode 100644 index 0000000..505a40f --- /dev/null +++ b/R/os-info.R @@ -0,0 +1,5 @@ +#' get os info +#' @export +os_info <- function() { + os_info_impl() +} \ No newline at end of file diff --git a/man/hello_world.Rd b/man/hello_world.Rd deleted file mode 100644 index 8291afd..0000000 --- a/man/hello_world.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/extendr-wrappers.R -\name{hello_world} -\alias{hello_world} -\title{Return string \code{"Hello world!"} to R.} -\usage{ -hello_world() -} -\description{ -Return string \code{"Hello world!"} to R. -} diff --git a/man/os_info.Rd b/man/os_info.Rd new file mode 100644 index 0000000..ca53ef1 --- /dev/null +++ b/man/os_info.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/os-info.R +\name{os_info} +\alias{os_info} +\title{get os info} +\usage{ +os_info() +} +\description{ +get os info +} diff --git a/man/os_info_impl.Rd b/man/os_info_impl.Rd new file mode 100644 index 0000000..05ff07d --- /dev/null +++ b/man/os_info_impl.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/extendr-wrappers.R +\name{os_info_impl} +\alias{os_info_impl} +\title{get os information} +\usage{ +os_info_impl() +} +\description{ +get os information +} diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index a946b28..4e92e67 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -31,17 +31,34 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a34aaa68a201f71eab5df5a67d1326add8aaf029434e939353bcab0534919ff1" +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "os_info" +version = "3.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" +dependencies = [ + "log", + "windows-sys", +] + [[package]] name = "osinfo" version = "0.1.0" dependencies = [ "extendr-api", + "os_info", ] [[package]] @@ -84,3 +101,76 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index d5e143c..bc7aa9c 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -10,3 +10,4 @@ name = 'osinfo' [dependencies] extendr-api = '*' +os_info = { version = "3", default-features = false } diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index 100346e..1149a5b 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -1,10 +1,21 @@ use extendr_api::prelude::*; -/// Return string `"Hello world!"` to R. -/// @export +#[derive(Debug, PartialEq, IntoDataFrameRow)] +struct OsInfo { + version: String, + os_type: String, + architecture: Option, +} +/// get os information #[extendr] -fn hello_world() -> &'static str { - "Hello world!" +fn os_info_impl() -> List { + let info = os_info::get(); + list!( + version = info.version().to_string(), + os_type = info.os_type().to_string(), + architecture = info.architecture(), + codename = info.codename() + ) } // Macro to generate exports. @@ -12,5 +23,5 @@ fn hello_world() -> &'static str { // See corresponding C code in `entrypoint.c`. extendr_module! { mod osinfo; - fn hello_world; + fn os_info_impl; }