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

Full R API bindings #242

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
9664239
wp: added features for all r headers..
CGMossa Jun 8, 2024
2d32d8d
wp: added files seen on mac...
CGMossa Jun 8, 2024
1edbb6e
wp: running the bindings for each separate file
CGMossa Jun 9, 2024
c385521
wp: complex should only be replaced in one place.. I think.
CGMossa Jun 9, 2024
1e6276f
wp: deleted the old cached bindings, in favour of these atomic ones.
CGMossa Jun 9, 2024
ada483e
wp: removed items from other headers (nice!)
CGMossa Jun 9, 2024
4268564
wp: keep fortran items _now_ that they don't cross pollute
CGMossa Jun 9, 2024
b3f459d
wp: test is its own module
CGMossa Jun 9, 2024
eac6830
wp: moved generated bindings..
CGMossa Jun 9, 2024
0dbfb7e
wp: this _compiles_ atleast
CGMossa Jun 9, 2024
42e021d
wp: still works!
CGMossa Jun 9, 2024
2238131
wp: this also works, maybe we are done?
CGMossa Jun 9, 2024
96d9d80
wp:re-arranged custom bindings
CGMossa Jun 9, 2024
88f9cba
wp: imports...
CGMossa Jun 9, 2024
8523fbb
wp: added feature dependencies. But these are not used in `lib.rs` yet.
CGMossa Jun 9, 2024
09ba4fc
wp: missing? what is libintl?
CGMossa Jun 9, 2024
0fbfceb
wp: merge up
CGMossa Jun 9, 2024
a646a11
wp: added r version to the header..
CGMossa Jun 9, 2024
9c61dbb
minor
CGMossa Jun 9, 2024
9042797
README: updated the instructions
CGMossa Jun 9, 2024
75f95f1
wp: updated the bindings generating ci script [generate bindings]
CGMossa Jun 9, 2024
2651af8
REVERT LATER [generate bindings]
CGMossa Jun 9, 2024
bac704f
REVERT THIS: disabled everything...
CGMossa Jun 9, 2024
0999c65
[generate bindings]
CGMossa Jun 9, 2024
90eb78b
Update bindings [skip ci]
CGMossa Jun 9, 2024
c1cdf08
windows is not blocking correctly...
CGMossa Jun 9, 2024
d2cdb8e
[generate bindings]
CGMossa Jun 9, 2024
81ade9d
ci: try again [generate bindings]
CGMossa Jun 9, 2024
353f7fc
ci: try again [generate bindings]
CGMossa Jun 9, 2024
ad0c803
Update bindings [skip ci]
CGMossa Jun 9, 2024
770789a
another hail mary [generate bindings]
CGMossa Jun 9, 2024
41a30a3
Update bindings [skip ci]
CGMossa Jun 9, 2024
6c1caab
this is correct, right? [generate bindings]
CGMossa Jun 9, 2024
9904371
[generate bindings]
CGMossa Jul 19, 2024
3a19c44
locally generated bindings
CGMossa Jul 19, 2024
4a33e28
[generate bindings]
CGMossa Jul 20, 2024
76ba112
Update bindings [skip ci]
CGMossa Jul 20, 2024
0959e11
comment a debug statement
CGMossa Jul 20, 2024
78aea60
`cargo fmt`
CGMossa Jul 20, 2024
eca7d3c
export bindings
CGMossa Jul 20, 2024
c9f5907
update nonAPI
CGMossa Jul 20, 2024
a29acaa
moved generated bindings to root
CGMossa Jul 20, 2024
0ffe664
move the bindings
CGMossa Jul 20, 2024
024007c
[generate bindings]
CGMossa Jul 20, 2024
88c7a0d
Update bindings [skip ci]
CGMossa Jul 20, 2024
351a189
[generate bindings]
CGMossa Jul 20, 2024
60e1cfc
updated bindings manually [generate bindings]
CGMossa Jul 20, 2024
5498112
[generate bindings]
CGMossa Jul 20, 2024
1919380
Update bindings [skip ci]
CGMossa Jul 20, 2024
2dc642a
these should be removed? [generate bindings]
CGMossa Jul 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
110 changes: 27 additions & 83 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- main
- master
- full_bindings
pull_request:
branches:
- main
- master
- full_bindings
issue_comment:
types:
- created
Expand All @@ -18,8 +20,10 @@ on:
# This can also manually run
workflow_dispatch: {}

jobs:
env:
LIBRSYS_BINDINGS_OUTPUT_PATH: generated_bindings

jobs:
test_with_bindgen:
# When the event is not issue_comment, always run the tests. When it is,
# check if (1) the comment is on pull request, (2) the comment author is the
Expand Down Expand Up @@ -56,19 +60,21 @@ jobs:
# only one stable Rust toolchain per combination of a platform and
# an R version (e.g. Windows and R-release) to emit bindings.
- {os: windows-latest, r: 'release', rust-version: 'stable-msvc', target: 'x86_64-pc-windows-gnu', emit-bindings: 'true'}
- {os: windows-latest, r: 'release', rust-version: 'nightly-msvc', target: 'x86_64-pc-windows-gnu'}
# - {os: windows-latest, r: 'release', rust-version: 'nightly-msvc', target: 'x86_64-pc-windows-gnu'}
- {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', target: 'x86_64-pc-windows-gnu', emit-bindings: 'true'}
- {os: windows-latest, r: 'release', rust-version: 'stable-gnu', target: 'x86_64-pc-windows-gnu'}
# - {os: windows-latest, r: 'release', rust-version: 'stable-gnu', target: 'x86_64-pc-windows-gnu'}
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', target: 'x86_64-pc-windows-gnu', emit-bindings: 'true'}
- {os: windows-latest, r: '4.2', rust-version: 'stable-msvc', target: 'x86_64-pc-windows-gnu', emit-bindings: 'true' }

- {os: macOS-latest, r: 'release', rust-version: 'nightly'}
# - {os: macOS-latest, r: 'release', rust-version: 'nightly'}
- {os: macOS-latest, r: 'devel', rust-version: 'stable', emit-bindings: 'true'}
- {os: macOS-latest, r: 'oldrel', rust-version: 'stable', emit-bindings: 'true'}
- {os: macOS-latest, r: 'release', rust-version: 'stable', emit-bindings: 'true'}
- {os: macOS-latest, r: 'release', rust-version: 'stable', target: 'x86_64-apple-darwin', skip-tests: 'true', emit-bindings: 'true'}
- {os: macOS-latest, r: '4.2', rust-version: 'stable', emit-bindings: 'true' }
- {os: macOS-latest, r: '4.2', rust-version: 'stable', target: 'x86_64-apple-darwin', skip-tests: 'true', emit-bindings: 'true'}


- {os: ubuntu-latest, r: 'release', rust-version: 'nightly'}
# - {os: ubuntu-latest, r: 'release', rust-version: 'nightly'}
- {os: ubuntu-latest, r: 'release', rust-version: 'stable', emit-bindings: 'true'}
- {os: ubuntu-latest, r: 'release', rust-version: 'stable', target: 'aarch64-unknown-linux-gnu', skip-tests: 'true', emit-bindings: 'true'}

Expand All @@ -78,6 +84,9 @@ jobs:
- {os: ubuntu-latest, r: 'oldrel', rust-version: 'stable', emit-bindings: 'true'}
- {os: ubuntu-latest, r: 'oldrel', rust-version: 'stable', target: 'aarch64-unknown-linux-gnu', skip-tests: 'true', emit-bindings: 'true'}

- {os: ubuntu-latest, r: '4.2', rust-version: 'stable', emit-bindings: 'true' }
- {os: ubuntu-latest, r: '4.2', rust-version: 'stable', target: 'aarch64-unknown-linux-gnu', skip-tests: 'true', emit-bindings: 'true'}

env:
RSPM: ${{ matrix.config.rspm }}

Expand Down Expand Up @@ -123,7 +132,7 @@ jobs:
if: runner.os == 'Windows'
run: |
# Configure linker
echo "RUSTFLAGS=-C linker=x86_64-w64-mingw32.static.posix-gcc.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "RUSTFLAGS=-Clinker=x86_64-w64-mingw32.static.posix-gcc.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

# Create libgcc_eh mock
New-Item -Path libgcc_mock -Type Directory
Expand Down Expand Up @@ -175,6 +184,8 @@ jobs:
# https://github.com/r-lib/ps/commit/a24f2c4d1bdba63be14e7729b9ab81d0ed9f719e
# Environment variables are required fir Mac-OS-11.0, see
# https://github.com/extendr/libR-sys/issues/35

# TODO: remove everything except `LIBCLANG_PATH`
- name: Configure macOS
if: runner.os == 'macOS'
run: |
Expand Down Expand Up @@ -231,7 +242,6 @@ jobs:
. ./ci-cargo.ps1
ci-cargo build -vv --features use-bindgen $(if ($env:RUST_TARGET -ne '') {"--target=$env:RUST_TARGET"} ) -ActionName "Building for target: $env:RUST_TARGET"
env:
LIBRSYS_BINDINGS_OUTPUT_PATH: generated_bindings
RUST_TARGET: ${{ matrix.config.target }}

- name: Upload generated bindings
Expand All @@ -241,14 +251,13 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: generated_binding-${{ matrix.config.os }}-R-${{ matrix.config.r }}-rust-${{ matrix.config.rust-version }}-${{ matrix.config.target || 'default'}}
path: generated_bindings
path: ${{ env.LIBRSYS_BINDINGS_OUTPUT_PATH }}

check_generate_bindings_flag:
name: Check if [generate bindings] is in latest commit message
runs-on: ubuntu-latest
outputs:
head_commit_message: ${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE }}
# generate_bindings: ${{ contains(steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE, '[generate bindings]') }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -261,8 +270,8 @@ jobs:
echo "${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE }}"
echo "${{ contains(steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE, '[generate bindings]') }}"

pr_generated_bindings:
name: Make PR with generated bindings
commit_generated_bindings:
name: Commit generated bindings
needs: [test_with_bindgen, check_generate_bindings_flag]
if: ${{ contains(needs.check_generate_bindings_flag.outputs.head_commit_message, '[generate bindings]') }}
runs-on: ubuntu-latest
Expand All @@ -279,10 +288,11 @@ jobs:

# Replace the default bindings
cd bindings
for x in linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64; do
# Choose the newest version except for devel
ln --force -s "$(ls -1 ./bindings-${x}-*.rs | grep -v devel | sort | tail -1)" ./bindings-${x}.rs
done
# TODO: this needs adjustment for the new output files...
# for x in linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64; do
# # Choose the newest version except for devel
# ln --force -s "$(ls -1 ./bindings-*-${x}-*.rs | grep -v devel | sort | tail -1)" ./bindings-*-${x}.rs
# done
cd ..
- name: Add generated bindings
run: |
Expand All @@ -291,70 +301,4 @@ jobs:
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Update bindings [skip ci]"
- name: Push to PR branch
run: git push

# Gather the generated bindings and push them to generated_bindings branch.
# If we need to update the bindings, create a pull request from that branch.
commit_generated_bindings:
needs: test_with_bindgen
runs-on: ubuntu-latest
# In the case of /bindings command, we don't need to check anything else
# because it should have checked in test_with_bindings job. In the other
# cases, we only want to invoke this on the master branch.
if: github.event_name == 'issue_comment' || github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4

- name: Switch branch
if: github.event_name != 'issue_comment'
run: |
# 1) If there's already generated_bindings branch, checkout it.
# 2) If generated_binding branch is not created, create it from the default branch.
if git ls-remote --exit-code --heads origin generated_bindings 2>&1 >/dev/null; then
git fetch origin --no-tags --prune --depth=1 generated_bindings
git checkout generated_bindings
else
git switch -c generated_bindings
fi

- name: Switch branch (/bindings command)
if: github.event_name == 'issue_comment'
uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Commit the generated bindings
run: |
# Update or add the bindings
cp generated_binding-*/*.rs bindings/

# Replace the default bindings
cd bindings
for x in linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64; do
# Choose the newest version except for devel
ln --force -s "$(ls -1 ./bindings-${x}-*.rs | grep -v devel | sort | tail -1)" ./bindings-${x}.rs
done
cd ..

# detect changes (the code is derived from https://stackoverflow.com/a/3879077)
git add bindings/
git update-index --refresh
if ! git diff-index --quiet HEAD -- bindings/; then
git config --local user.name "${GITHUB_ACTOR}"
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -m "Update bindings [skip ci]"
else
echo "No changes"
fi

- name: Push
if: github.event_name != 'issue_comment'
run: git push origin generated_bindings

- name: Push (/bindings command)
if: github.event_name == 'issue_comment'
uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
run: git push
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bindings/*.rs
115 changes: 115 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ repository = "https://github.com/extendr/libR-sys"
[build-dependencies]
bindgen = { version = "0.69.4", optional = true, features = ["experimental"] }
regex = { version = "*", optional = true, default-features = false }
fs_extra = "1.3"

[features]
default = ["runtime"]
Expand All @@ -36,6 +37,120 @@ runtime = ["bindgen/runtime"]
# Enables generation of layout-tests in bindgen
layout_tests = ["use-bindgen"]

disabled = []
# TODO: include default headers...

# TODO:?!
# stamp-h.in
# Makefile = []
# config.in = []
# Makefile.in = []
# Makefile.win = []

# internal headers, not installed
# Rgraphics = []
# Internal.h
# Print = []
# Parse = []
# Errormsg = []
# Startup = []
# Rconnections = []
# rlocale = []
# Fileio = []
# Graphics = []
# Rmodules/RX11
# Rmodules/Rlapack
# Rmodules/Rinternet // doesn't state that is internal...but it is...
# Rmath0.in = []
# Rinlinedfuns = []
# Defn = []
# IOStuff = []

# R_ext/*
Print = []
Parse = ["Rinternals"]
Error = []
Itermacros = []
Utils = ["Boolean", "Complex"]
stats_stubs = []
GetX11Image = ["Boolean"]
# TODO: combine them?
GraphicsEngine = ["GraphicsDevice", "Rinternals", "Boolean"]
GraphicsDevice = ["GraphicsEngine", "Rinternals", "Boolean"]
Callbacks = ["Rinternals", "Boolean"]
Rdynload = ["Boolean"]
RS = []
BLAS = ["Complex"]
Arith = []
Boolean = []
Applic = ["Boolean"]
Linpack = []
Constants = []
Riconv = []
RStartup = ["Boolean"]
QuartzDevice = []
libextern = []
MathThreads = []
Memory = []
Connections = ["Boolean"]
PrtUtil = ["Rinternals", "Complex"]
Altrep = ["Rinternals", "Boolean", "Complex", "Rdynload"]
Rallocators = []
Visibility = []
stats_package = []
Complex = []
Lapack = ["Complex"]
Random = []
eventloop = []
R_ext = [
"GraphicsEngine",
"Error",
"Itermacros",
"Utils",
"stats_stubs",
"GetX11Image",
"GraphicsDevice",
"Callbacks",
"Rdynload",
"Parse",
"RS",
"BLAS",
"Arith",
"Boolean",
"Applic",
"Linpack",
"Constants",
"Riconv",
"RStartup",
"Print",
"QuartzDevice",
"libextern",
"MathThreads",
"Memory",
"Connections",
"PrtUtil",
"Altrep",
"Rallocators",
"Visibility",
"stats_package",
# "Makefile",
"Complex",
"Lapack",
"Random",
"eventloop",
]
# R_INCLUDES/* (in root)
libintl = []
R = []
Rconfig = []
Rdefines = []
Rembedded = ["Boolean"]
Rinterface = []
Rinternals = ["Boolean", "Complex", "Rdynload"]
Rmath = []
# GraphicsBase = [] # private
# Rdynpriv = [] # ?? maybe private?

[lib]
# Some code comments on R's source code might be accidentally treated as Rust's
# doc test. See https://github.com/extendr/libR-sys/issues/194 for the details.
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The bindings can be generated using [`bindgen`](https://github.com/rust-lang/rus
`bindgen` requires [`libclang`](https://clang.llvm.org/docs/Tooling.html), which should be installed first.
This library relies on `LIBCLANG_PATH` environment variable to determine path to the appropriate version of `libclang`.

The output folder for bindings can be configured using `LIBRSYS_BINDINGS_OUTPUT_PATH` environment variable, thus make sure it is set to e.g `bindings`.
The output folder for bindings can be configured using `LIBRSYS_BINDINGS_OUTPUT_PATH` environment variable, thus make sure it is set to e.g `src/bindings`.

- **Linux**

Expand Down Expand Up @@ -90,6 +90,12 @@ The output folder for bindings can be configured using `LIBRSYS_BINDINGS_OUTPUT_
PATH=/usr/local/opt/llvm/bin:$PATH
```

Alternatively, one may merely set

```shell
export LIBCLANG_PATH=$(brew --prefix llvm)/lib
```

Build & test using

```shell
Expand Down
Loading
Loading