diff --git a/.Rbuildignore b/.Rbuildignore index d13f13f..90aeec6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,4 @@ ^\.Rproj\.user$ ^LICENSE\.md$ ^src/\.cargo$ +^src/rust/vendor$ diff --git a/.gitignore b/.gitignore index 671b0d8..75c3f22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .Rproj.user .DS_Store +src/rust/vendor diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..1b93ebd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,4 @@ # Generated by roxygen2: do not edit by hand +export(hello_world) +useDynLib(osinfo, .registration = TRUE) diff --git a/configure b/configure new file mode 100755 index 0000000..d656e00 --- /dev/null +++ b/configure @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +# https://github.com/eitsupi/prqlr/blob/main/configure +export PATH="$PATH:$HOME/.cargo/bin" + +if [ ! "$(command -v cargo)" ]; then + echo "----------------------- [RUST NOT FOUND]---------------------------" + echo "The 'cargo' command was not found on the PATH. Please install rustc" + echo "from: https://www.rust-lang.org/tools/install" + echo "" + echo "Alternatively, you may install cargo from your OS package manager:" + echo " - Debian/Ubuntu: apt-get install cargo" + echo " - Fedora/CentOS: dnf install cargo" + echo " - macOS: brew install rustc" + echo "-------------------------------------------------------------------" + echo "" + exit 1 +fi + +exit 0 diff --git a/configure.win b/configure.win new file mode 100644 index 0000000..d9b66ed --- /dev/null +++ b/configure.win @@ -0,0 +1,15 @@ +#!/bin/sh + +# https://github.com/eitsupi/prqlr/blob/main/configure.win +export PATH="$PATH:$HOME/.cargo/bin" + +if [ ! "$(command -v cargo)" ]; then + echo "----------------------- [RUST NOT FOUND]---------------------------" + echo "The 'cargo' command was not found on the PATH. Please install rustc" + echo "from: https://www.rust-lang.org/tools/install" + echo "-------------------------------------------------------------------" + echo "" + exit 1 +fi + +exit 0 diff --git a/man/hello_world.Rd b/man/hello_world.Rd new file mode 100644 index 0000000..8291afd --- /dev/null +++ b/man/hello_world.Rd @@ -0,0 +1,11 @@ +% 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/src/Makevars b/src/Makevars index d76aa99..fbc4182 100644 --- a/src/Makevars +++ b/src/Makevars @@ -7,9 +7,17 @@ all: C_clean $(SHLIB): $(STATLIB) +CRAN_FLAGS=-j 2 --offline CARGOTMP = $(CURDIR)/.cargo +VENDOR_DIR = $(CURDIR)/vendor $(STATLIB): + if [ -f ./rust/vendor.tar.xz ]; then \ + tar xf rust/vendor.tar.xz && \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + fi + # In some environments, ~/.cargo/bin might not be included in PATH, so we need # to set it here to ensure cargo can be invoked. It is appended to PATH and # therefore is only used if cargo is absent from the user's PATH. @@ -17,14 +25,12 @@ $(STATLIB): export CARGO_HOME=$(CARGOTMP); \ fi && \ export PATH="$(PATH):$(HOME)/.cargo/bin" && \ - cargo build --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) - if [ "$(NOT_CRAN)" != "true" ]; then \ - rm -Rf $(CARGOTMP) && \ - rm -Rf $(LIBDIR)/build; \ - fi + cargo build $(CRAN_FLAGS) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) && \ + echo `cargo --version` && echo `rustc --version`; + rm -Rf $(CARGOTMP) $(VENDOR_DIR) $(LIBDIR)/build; \ C_clean: - rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) + rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) clean: - rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target + rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) $(TARGET_DIR) diff --git a/src/Makevars.win b/src/Makevars.win index 49456d9..f25f2d8 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -9,14 +9,29 @@ all: C_clean $(SHLIB): $(STATLIB) +CRAN_FLAGS=-j 2 --offline +CARGOTMP = $(CURDIR)/.cargo +VENDOR_DIR = $(CURDIR)/vendor + +all: C_clean + +$(SHLIB): $(STATLIB) + +CRAN_FLAGS=-j 2 --offline CARGOTMP = $(CURDIR)/.cargo $(STATLIB): + # uncompress vendored deps + if [ -f ./rust/vendor.tar.xz ]; then \ + tar xf rust/vendor.tar.xz && \ + mkdir -p $(CARGOTMP) && \ + cp rust/vendor-config.toml $(CARGOTMP)/config.toml; \ + fi + mkdir -p $(TARGET_DIR)/libgcc_mock # `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have # `libgcc_eh` due to the compilation settings. So, in order to please the # compiler, we need to add empty `libgcc_eh` to the library search paths. - # # For more details, please refer to # https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316 touch $(TARGET_DIR)/libgcc_mock/libgcc_eh.a @@ -26,15 +41,15 @@ $(STATLIB): export CARGO_HOME=$(CARGOTMP); \ fi && \ export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="$(CARGO_LINKER)" && \ - export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock" && \ - cargo build --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) + export LIBRARY_PATH="$${LIBRARY_PATH};$(CURDIR)/$(TARGET_DIR)/libgcc_mock"; \ + cargo build $(CRAN_FLAGS) --target=$(TARGET) --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR) && \ + echo `cargo --version` && echo `rustc --version`; if [ "$(NOT_CRAN)" != "true" ]; then \ - rm -Rf $(CARGOTMP) && \ - rm -Rf $(LIBDIR)/build; \ + rm -Rf $(CARGOTMP) $(VENDOR_DIR) $(LIBDIR)/build; \ fi C_clean: - rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) + rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) clean: - rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR) + rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(CARGOTMP) $(VENDOR_DIR) $(TARGET_DIR) diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock new file mode 100644 index 0000000..a946b28 --- /dev/null +++ b/src/rust/Cargo.lock @@ -0,0 +1,86 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "extendr-api" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d55a0174c4df17c467fb59b3f836bec31d1af6d56c4182cfdf34a62d1553a4" +dependencies = [ + "extendr-macros", + "libR-sys", + "once_cell", + "paste", +] + +[[package]] +name = "extendr-macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33833971650cade4bfa3097b979506bf2b4934b60392e110f95b94c2406cbb84" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "libR-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34aaa68a201f71eab5df5a67d1326add8aaf029434e939353bcab0534919ff1" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "osinfo" +version = "0.1.0" +dependencies = [ + "extendr-api", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"