{"id":14069298,"url":"https://github.com/extendr/libR-sys","last_synced_at":"2025-07-30T05:32:00.064Z","repository":{"id":40240141,"uuid":"254059689","full_name":"extendr/libR-sys","owner":"extendr","description":"Low level R bindgen interface","archived":false,"fork":false,"pushed_at":"2024-09-09T06:05:48.000Z","size":5284,"stargazers_count":55,"open_issues_count":16,"forks_count":24,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-25T03:46:59.646Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://extendr.github.io/libR-sys/libR_sys/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/extendr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-08T10:44:30.000Z","updated_at":"2025-06-12T15:22:05.000Z","dependencies_parsed_at":"2025-01-10T14:10:48.111Z","dependency_job_id":"ba324dd5-ea88-4b71-8e9f-955ab177a56e","html_url":"https://github.com/extendr/libR-sys","commit_stats":{"total_commits":267,"total_committers":11,"mean_commits":"24.272727272727273","dds":0.6816479400749064,"last_synced_commit":"8574fac8e79e04d7ddcbeb9116958d3ff3402664"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/extendr/libR-sys","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2FlibR-sys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2FlibR-sys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2FlibR-sys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2FlibR-sys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extendr","download_url":"https://codeload.github.com/extendr/libR-sys/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extendr%2FlibR-sys/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267815187,"owners_count":24148356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:06:49.615Z","updated_at":"2025-07-30T05:31:59.696Z","avatar_url":"https://github.com/extendr.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# libR-sys\n\nLow-level R library bindings\n\n[![Github Actions Build Status](https://github.com/extendr/libR-sys/workflows/Tests/badge.svg)](https://github.com/extendr/libR-sys/actions)\n[![crates.io](https://img.shields.io/crates/v/libR-sys.svg)](https://crates.io/crates/libR-sys)\n[![Documentation](https://docs.rs/libR-sys/badge.svg)](https://docs.rs/libR-sys)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Installation\n\nThe recommended way to build this library is to use precompiled bindings, which are available for `Linux`, `macOS`, and `Windows`.\n\nAlternatively, the library can be built from source, in which case it invokes `bindgen` crate, which has extra platform-specific dependencies (including `msys2` for `Windows`).\n\n## Configuration\n\n`libR-sys` recognizes the following environment variables:\n\n- `LIBRSYS_R_VERSION` If set, it is used to determine the version of R, for which bindings should be generated. `LIBRSYS_R_VERSION` should be set to one of the supported values, e.g. `4.2.0` or `4.3.0-devel` (the pattern is `major.minor.patch[-devel]`). Malformed `LIBRSYS_R_VERSION` results in compilation error. If `LIBRSYS_R_VERSION` is unset, `R` is invoked and its `R.version` is used.\n\n## Using precompiled bindings (recommended)\n\nTwo components are required to build the library:\n\n1. [`R`](https://cran.r-project.org/): It needs to be installed and available in the search path.\n2. [`Rust`](https://www.rust-lang.org/learn/get-started): It is recommended to install `Rust` using `rustup`; search path should include `Rust` binaries.\n\n**Note: On Windows, only R \u003e= 4.2 is supported**\n\nOnce `R` and `Rust` are configured, the library can be easily built:\n\n```bash\n# macOS \u0026 Linux\ncargo build\n\n# Windows\ncargo build --target x86_64-pc-windows-gnu\n```\n\nTo test the build, run `cargo test`.\n\n```bash\n# macOS \u0026 Linux\ncargo test\n\n# Windows\ncargo test --target x86_64-pc-windows-gnu\n```\n\n## Building bindings from source (advanced)\n\n**Note: On Windows, only R \u003e= 4.2 is supported**\n\nThe bindings can be generated using [`bindgen`](https://github.com/rust-lang/rust-bindgen), special `Rust` crate.\n`bindgen` usage is enabled via `use-bindgen` feature flag.\n\n`bindgen` requires [`libclang`](https://clang.llvm.org/docs/Tooling.html), which should be installed first.\nThis library relies on `LIBCLANG_PATH` environment variable to determine path to the appropriate version of `libclang`.\n\nThe output folder for bindings can be configured using `LIBRSYS_BINDINGS_OUTPUT_PATH` environment variable, thus make sure it is set to e.g `bindings`.\n\n- **Linux**\n\n  Set `LIBCLANG_PATH` to the `lib` directory of your `llvm` installation, e.g.,\n  `LIBCLANG_PATH=/usr/lib/llvm-3.9/lib`. Build \u0026 test using\n\n  ```shell\n  cargo build --features use-bindgen\n  cargo test  --features use-bindgen \n  ```\n\n- **macOS**\n\n  Install `llvm-config` via [homebrew](https://brew.sh/) with:\n\n  ```bash\n  brew install llvm\n  ```\n\n  Add it to your search path via:\n\n  ```bash\n  echo 'export PATH=\"/usr/local/opt/llvm/bin:$PATH\"' \u003e\u003e ~/.bash_profile\n  ```\n\n  If you want to compile `libR-sys` from within RStudio, you may also have to add the following line to your `.Renviron` file:\n\n  ```bash\n  PATH=/usr/local/opt/llvm/bin:$PATH\n  ```\n\n  Build \u0026 test using\n  \n  ```shell\n  cargo build --features use-bindgen\n  cargo test  --features use-bindgen \n  ```\n\n- **Windows**\n  On Windows, bindings can be generated using native `LLVM` installation and `Rtools` distribution.\n\n  Install LLVM:\n\n  ```powershell\n  choco install llvm -y\n  ```\n\n  `LLVM` can be also installed using `winget`, `scoop`, or manually.\n\n  To ensure LLVM is successfully installed and configured, run `clang --version`. If `clang` is not on the `PATH`, manually add path to `clang` installation to the `PATH` environement variable.\n\n  Install `Rtools` if it is misisng:\n\n  ```powershell\n  choco install rtools -y\n  ```\n\n  Installing `Rtools` this way automatically sets `RTOOLS42_HOME` (or `RTOOLS43_HOME`) environment variable.\n\n  Ensure that `R_HOME` environment variable is set to the `R` installation directory.\n\n  Finally, point `libR-sys` to the include directory of `Rtools`:\n\n  ```powershell\n  $env:LIBRSYS_LIBCLANG_INCLUDE_PATH=\"$env:RTOOLS42_HOME\\x86_64-w64-mingw32.static.posix\\include\"\n  ```\n\n  Now, the bindings can be build using the following command:\n\n  ```powershell\n  cargo build --target x86_64-pc-windows-gnu --features use-bindgen\n  ```\n\n## Running bindgen tests on Windows\n\nRunning bindgen tests on Windows requires a bit more setup.\n\nFirst, add `Rtools` `bin` directory to the `PATH` (replace `RTOOLS42_HOME` with `RTOOLS43_HOME` if you are using `Rtools` 4.3):\n\n```powershell\n$env:PATH += \";$env:RTOOLS42_HOME\\x86_64-w64-mingw32.static.posix\\bin\"\n```\n\nSecond, patch `Rtools` version `4.2` and higher since there is a `gcc` static linking issue. `rustc` adds `-lgcc_eh` flag\nto the compiler, but Rtools' GCC doesn't have `libgcc_eh` due to\nthe compilation settings. So, in order to please the compiler, `libgcc_eh` should be mocked and added to the library search paths. For more details, please refer to [r-windows/rtools-packages].\n\n[r-windows/rtools-packages]: https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316\n\nCreate a directory for missing library file and an empty file there:\n\n``` powershell\n# create a directory in an arbitrary location (e.g. libgcc_mock)\nNew-Item -Path libgcc_mock -Type Directory\n\n# create empty libgcc_eh.a and libgcc_s.a\nNew-Item -Path libgcc_mock\\libgcc_eh.a -Type File\n```\n\nFinally, configure `Rust` compiler and select appropriate linker (see [The Cargo Book]):\n\n[The Cargo Book]: https://doc.rust-lang.org/cargo/reference/config.html#environment-variables\n\n```powershell\n$env:CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=\"x86_64-w64-mingw32.static.posix-gcc.exe\"\n$env:LIBRARY_PATH=\"libgcc_mock\" # Replace it with the path to the directory created above\n```\n\nAlternatively, linker can be configured in `.cargo/config.toml`:\n\n``` toml\n[target.x86_64-pc-windows-gnu]\nlinker = \"x86_64-w64-mingw32.static.posix-gcc.exe\"\n```\n\nNow, the tests can be run:\n\n```powershell\ncargo test --target x86_64-pc-windows-gnu --features use-bindgen\n```\n\n### Editor settings\n\n\u003cdetails\u003e\n\nRust-analyzer might need some settings. For example, if you are using VS Code, you probably need to add the following options to `.vscode/settings.json`.\n\n``` json\n{\n    // The target needs to be GNU\n    \"rust-analyzer.cargo.target\": \"x86_64-pc-windows-gnu\",\n    // Specify \"use-bindgen\" for developing R-devel.\n    \"rust-analyzer.cargo.features\": [],\n    \"terminal.integrated.env.windows\": {\n        \"R_HOME\": \"C:/Program Files/R/R-4.2.2\",\n        \"PATH\": \"${env:R_HOME}/bin/x64;C:/rtools42/x86_64-w64-mingw32.static.posix/bin;C:/rtools42/usr/bin;${env:PATH}\"\n    }\n}\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2FlibR-sys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextendr%2FlibR-sys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextendr%2FlibR-sys/lists"}