-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c2ad76f
Showing
11 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Run tests | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
test_macos: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Install libeditorconfig | ||
run: brew install editorconfig | ||
- name: Run tests | ||
run: cargo test | ||
test_ubuntu: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Install libeditorconfig | ||
run: sudo apt-get update && sudo apt-get install libeditorconfig-dev | ||
- name: Run tests | ||
run: cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "editorconfig-sys" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Thorsten Blum <[email protected]>"] | ||
homepage = "https://github.com/toblux/editorconfig-sys" | ||
repository = "https://github.com/toblux/editorconfig-sys" | ||
documentation = "https://docs.rs/editorconfig-sys" | ||
description = "Native Rust bindings to libeditorconfig" | ||
readme = "README.md" | ||
license = "MIT" | ||
keywords = ["editorconfig", "libeditorconfig", "bindings", "ffi", "sys"] | ||
categories = ["external-ffi-bindings"] | ||
links = "editorconfig" | ||
build = "build.rs" | ||
|
||
[dev-dependencies] | ||
rand = "0.8.5" | ||
|
||
[build-dependencies] | ||
bindgen = "0.69.2" | ||
pkg-config = "0.3.29" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Thorsten Blum | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Native Rust Bindings to libeditorconfig | ||
|
||
This crate uses [bindgen](https://crates.io/crates/bindgen) and [pkg-config](https://crates.io/crates/pkg-config) to automatically generate Rust FFI bindings to the [EditorConfig Core C](https://github.com/editorconfig/editorconfig-core-c) library. | ||
|
||
Following the `*-sys` package convention, `editorconfig-sys` is just a thin wrapper around the native `libeditorconfig` library. | ||
|
||
<!-- The "safe" Rust bindings to `libeditorconfig`, built on top of this `editorconfig-sys` crate, can be found [here](https://github.com/toblux/rust-editorconfig). --> | ||
|
||
![Workflow status](https://github.com/toblux/editorconfig-sys/actions/workflows/test.yml/badge.svg) | ||
|
||
## Dependencies | ||
|
||
To use this crate, `libeditorconfig >= 0.12.5` must be installed and `pkg-config` must be able to find it. You can check if `pkg-config` can find the library and which version is installed with: | ||
|
||
```sh | ||
pkg-config --modversion editorconfig | ||
``` | ||
|
||
## Installation | ||
|
||
Add this to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
editorconfig-sys = "0.1.0" | ||
``` | ||
|
||
## Usage | ||
|
||
Some `unsafe` Rust code examples can be found in the [tests](tests/editorconfig_sys.rs). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use pkg_config::Library; | ||
|
||
const LIBRARY_NAME: &str = "editorconfig"; | ||
|
||
// Technically libeditorconfig v0.12.2 already supports pkg-config: | ||
// https://github.com/editorconfig/editorconfig-core-c/releases/tag/v0.12.2 | ||
const MIN_VERSION: &str = "0.12.5"; | ||
const MAX_VERSION: &str = "1.0.0"; | ||
|
||
fn main() { | ||
let err_msg = format!("Unable to find library {} >= {}", LIBRARY_NAME, MIN_VERSION); | ||
let lib = pkg_config::Config::new() | ||
.range_version(MIN_VERSION..MAX_VERSION) | ||
.probe(LIBRARY_NAME) | ||
.expect(&err_msg); | ||
gen_bindings(lib); | ||
} | ||
|
||
fn gen_bindings(lib: Library) { | ||
let include_paths = lib | ||
.include_paths | ||
.iter() | ||
.map(|path| format!("-I{}", path.to_string_lossy())); | ||
|
||
let bindings = bindgen::Builder::default() | ||
.header("wrapper.h") | ||
.clang_args(include_paths) | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
.generate() | ||
.expect("Failed to generate bindings"); | ||
|
||
// Write bindings to `$OUT_DIR/bindings.rs` | ||
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("bindings.rs")) | ||
.expect("Failed to write bindings"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
|
||
[*.rs] | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
root = true | ||
# Comments are fine | ||
LINE 3 IS INVALID AND SHOULD CAUSE AN ERROR |
Oops, something went wrong.