Skip to content

Commit

Permalink
Adds necesarry build steps to ensure CRAN compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Nov 20, 2023
1 parent 09fe33e commit d70d88c
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 14 deletions.
23 changes: 21 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
^src/\.cargo$
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.Rmd$
^README\.md$
^man/figures/.*$
^\.github$
^fonts$

^src/.cargo$
^src/rust/.cargo$
^src/rust/.vscode$
^src/rust/vendor$

^_pkgdown\.yml$
^docs$
^pkgdown$
^LICENSE\.md$

^cran-comments\.md$
^CRAN-SUBMISSION$
^CRAN-RELEASE$

^check$

^update_authors\.R$
50 changes: 50 additions & 0 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: "${{ matrix.config.os }} (R: ${{ matrix.config.r }}, Rust: ${{ matrix.config.rust }})"

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release', rust: 'stable-msvc'}
- {os: windows-latest, r: 'devel', rust: 'stable-msvc'}
- {os: macOS-latest, r: 'release', rust: 'stable' }
- {os: ubuntu-latest, r: 'release', rust: 'stable' }
- {os: ubuntu-latest, r: 'devel', rust: 'stable' }
- {os: ubuntu-latest, r: 'release', rust: 'nightly' }

steps:
- uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.config.rust }}

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools-version }}
use-public-rspm: true

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2

- name: debug
run: cat ./check/*.Rcheck/00install.out
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ po/*~
# RStudio Connect folder
rsconnect/
docs

# Rust Cargo files
src/.cargo
src/rust/.cargo
src/rust/vendor/

docs
8 changes: 7 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ Package: orbweaver
Title: Fast and Efficient Graph Data Structures
Version: 0.1.0.9000
Authors@R:
person("Andres", "Quintero", , "[email protected]", role = c("aut", "cre"))
c(person("Andres", "Quintero", , "[email protected]", role = c("aut", "cre")),
person(given = "The authors of the dependency Rust crates",
role = c("ctb"),
comment = "see inst/AUTHORS file for details"))
Description: Orbweaver is an R packages that optimizes the processing of graph data structures.
URL: https://github.com/ixpantia/orbweaver
BugReports: https://github.com/ixpantia/orbweaver/issues
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/rextendr/version: 0.3.1
SystemRequirements: Cargo (Rust's package manager), rustc
91 changes: 91 additions & 0 deletions LICENSE.note
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
This package contains the Rust source code of the dependencies in src/rust/vendor.tar.xz
The authorships and the licenses are listed below. In summary, all libraries are
distributed either under the MIT license or under MIT/Apache-2.0 dual license [1].

Note that, when Cargo (Rust’s build system and package manager) is not installed
on the machine, the pre-compiled binary will be downloaded on building this
package. The binary is compiled using the same Rust code, so the authorships and
the licenses are the same as listed here.

[1]: The unicode-indent library shows 'Unicode-DFS-2016' license because it
contains some test data generated by using the Unicode Character Database.
So, this license is not applied to the actual sources that get compiled.
Please refer to the License section of the library's README
(https://crates.io/crates/unicode-ident) for the details.

===============================

Name: either
Files: vendor/either/*
Authors: bluss
License: MIT OR Apache-2.0

------------------------------

Name: extendr-api
Files: vendor/extendr-api/*
Authors: andy-thomason, Thomas Down, Mossa Merhi Reimert, Claus O. Wilke, Hiroaki Yutani, Ilia A. Kosenkov, Michael Milton
License: MIT

------------------------------

Name: extendr-macros
Files: vendor/extendr-macros/*
Authors: andy-thomason, Thomas Down, Mossa Merhi Reimert, Claus O. Wilke, Hiroaki Yutani, Ilia A. Kosenkov
License: MIT

------------------------------

Name: itertools
Files: vendor/itertools/*
Authors: bluss
License: MIT OR Apache-2.0

------------------------------

Name: libR-sys
Files: vendor/libR-sys/*
Authors: andy-thomason, Thomas Down, Mossa Merhi Reimert, Claus O. Wilke, Ilia A. Kosenkov, Hiroaki Yutani
License: MIT

------------------------------

Name: once_cell
Files: vendor/once_cell/*
Authors: Aleksey Kladov
License: MIT OR Apache-2.0

------------------------------

Name: paste
Files: vendor/paste/*
Authors: David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: proc-macro2
Files: vendor/proc-macro2/*
Authors: David Tolnay, Alex Crichton
License: MIT OR Apache-2.0

------------------------------

Name: quote
Files: vendor/quote/*
Authors: David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: syn
Files: vendor/syn/*
Authors: David Tolnay
License: MIT OR Apache-2.0

------------------------------

Name: unicode-ident
Files: vendor/unicode-ident/*
Authors: David Tolnay
License: (MIT OR Apache-2.0) AND Unicode-DFS-2016
51 changes: 51 additions & 0 deletions inst/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
The authors of the dependency Rust crates:

either (version 1.9.0):
bluss

extendr-api (version 0.6.0):
andy-thomason
Thomas Down
Mossa Merhi Reimert
Claus O. Wilke
Hiroaki Yutani
Ilia A. Kosenkov
Michael Milton

extendr-macros (version 0.6.0):
andy-thomason
Thomas Down
Mossa Merhi Reimert
Claus O. Wilke
Hiroaki Yutani
Ilia A. Kosenkov

itertools (version 0.11.0):
bluss

libR-sys (version 0.6.0):
andy-thomason
Thomas Down
Mossa Merhi Reimert
Claus O. Wilke
Ilia A. Kosenkov
Hiroaki Yutani

once_cell (version 1.18.0):
Aleksey Kladov

paste (version 1.0.14):
David Tolnay

proc-macro2 (version 1.0.69):
David Tolnay
Alex Crichton

quote (version 1.0.33):
David Tolnay

syn (version 2.0.39):
David Tolnay

unicode-ident (version 1.0.12):
David Tolnay
25 changes: 20 additions & 5 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO
VENDORING = yes
OFFLINE_OPTION = --offline

TARGET_DIR = ./rust/target
LIBDIR = $(TARGET_DIR)/release
STATLIB = $(LIBDIR)/liborbweaver.a
Expand All @@ -7,24 +11,35 @@ all: C_clean

$(SHLIB): $(STATLIB)

CARGOTMP = $(CURDIR)/.cargo

$(STATLIB):
# vendoring (Note: to avoid NOTE of "Found the following hidden files and
# directories", .cargo needs to be created here)
if [ "$(VENDORING)" = "yes" ]; then \
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
mkdir -p ./rust/.cargo && \
cp ./config/cargo_vendor_config.toml ./rust/.cargo/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.
if [ "$(NOT_CRAN)" != "true" ]; then \
export CARGO_HOME=$(CARGOTMP); \
fi && \
export PATH="$(PATH):$(HOME)/.cargo/bin" && \
cargo build --lib --release --manifest-path=./rust/Cargo.toml --target-dir $(TARGET_DIR)
cd ./rust && \
cargo build --lib --release \
$(OFFLINE_OPTION) \
--jobs 1
if [ "$(NOT_CRAN)" != "true" ]; then \
rm -Rf $(CARGOTMP) && \
rm -Rf $(LIBDIR)/build; \
fi

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
rm -Rf $(SHLIB) $(OBJECTS) ./rust/.cargo $(STATLIB)

clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) rust/target
rm -Rf $(SHLIB) $(OBJECTS) $(STATLIB) ./rust/.cargo ./rust/vendor ./rust/target

.PHONY: all C_clean clean
33 changes: 27 additions & 6 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
TARGET = $(subst 64,x86_64,$(subst 32,i686,$(WIN)))-pc-windows-gnu
TARGET = x86_64-pc-windows-gnu

# Rtools42 doesn't have the linker in the location that cargo expects, so we
# need to overwrite it via configuration.
CARGO_LINKER = x86_64-w64-mingw32.static.posix-gcc.exe

# TODO
VENDORING = yes
OFFLINE_OPTION = --offline

TARGET_DIR = ./rust/target
LIBDIR = $(TARGET_DIR)/$(TARGET)/release
Expand All @@ -9,9 +17,17 @@ all: C_clean

$(SHLIB): $(STATLIB)

CARGOTMP = $(CURDIR)/.cargo

$(STATLIB):
mkdir -p $(LIBDIR)/libgcc_mock && touch $(LIBDIR)/libgcc_mock/libgcc_eh.a

# vendoring (Note: to avoid NOTE of "Found the following hidden files and
# directories", .cargo needs to be created here)
if [ "$(VENDORING)" = "yes" ]; then \
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
mkdir -p ./rust/.cargo && \
cp ./cargo_vendor_config.toml ./rust/.cargo/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
Expand All @@ -27,14 +43,19 @@ $(STATLIB):
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)
cd ./rust && \
cargo build --target=$(TARGET) --lib --release \
$(OFFLINE_OPTION) \
--jobs 1
if [ "$(NOT_CRAN)" != "true" ]; then \
rm -Rf $(CARGOTMP) && \
rm -Rf $(LIBDIR)/build; \
fi

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS)
rm -Rf $(SHLIB) $(OBJECTS) ./rust/.cargo $(STATLIB)

clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) $(TARGET_DIR)
rm -Rf $(SHLIB) $(OBJECTS) $(STATLIB) ./rust/.cargo ./rust/vendor ./rust/target

.PHONY: all C_clean clean
5 changes: 5 additions & 0 deletions src/config/cargo_vendor_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
23 changes: 23 additions & 0 deletions src/rust/vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh -e

cargo vendor

# c.f. https://reproducible-builds.org/docs/archives/
tar \
--sort=name \
--mtime='1970-01-01 00:00:00Z' \
--owner=0 \
--group=0 \
--numeric-owner \
--xz \
--create \
--file=vendor.tar.xz \
vendor

echo
echo
echo "####################################################"
echo "# #"
echo "# UPDATE src/config/cargo_vendor_config.toml !!! #"
echo "# #"
echo "####################################################"
Binary file added src/rust/vendor.tar.xz
Binary file not shown.
Loading

0 comments on commit d70d88c

Please sign in to comment.