diff options
| author | Fuwn <[email protected]> | 2022-01-25 23:04:22 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-25 23:04:22 -0800 |
| commit | 6699cbaa1c16b464bcfc1963143ebc945154b671 (patch) | |
| tree | b6f83ca4f13a14e3539754d8428c76cab86beb5d | |
| download | rawaccel-sys-main.tar.xz rawaccel-sys-main.zip | |
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | Cargo.toml | 16 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | Makefile.toml | 37 | ||||
| -rw-r--r-- | build.rs | 9 | ||||
| m--------- | rawaccel | 0 | ||||
| -rw-r--r-- | rust-toolchain.toml | 2 | ||||
| -rw-r--r-- | rustfmt.toml | 29 | ||||
| -rw-r--r-- | src/lib.rs | 26 |
10 files changed, 150 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..49edac4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Rust +/target/ +/Cargo.lock +/**/*.rs.bk + +# IDE +/.idea/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3f37248 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rawaccel"] + path = rawaccel + url = [email protected]:LibreAccel/rawaccel.git diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..bc3caf6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rawaccel-sys" +version = "0.1.0" +authors = ["Fuwn <[email protected]>", "a1xd <[email protected]>"] +edition = "2021" +description = "⚙ Experimental bindings to the Raw Accel common library" +homepage = "https://github.com/LibreAccel/rawaccel-sys" +repository = "https://github.com/LibreAccel/rawaccel-sys" +license = "MIT" +publish = false + +[build-dependencies] +cxx-build = "1.0.63" + +[dependencies] +cxx = "1.0.63" @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-2022 a1xd, Fuwn + +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. diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..d004dbc --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,37 @@ +# ------------ +# | Wrappers | +# ------------ +[tasks.fmt] +command = "cargo" +args = ["fmt"] + +[tasks.check] +command = "cargo" +args = ["check"] + +[tasks.clippy] +command = "cargo" +args = ["clippy"] + +[tasks.test] +command = "cargo" +args = ["test"] + +[tasks.bench] +command = "cargo" +args = ["bench"] + +# ------------- +# | Executors | +# ------------- +[tasks.checkf] +workspace = false +dependencies = ["fmt", "check"] + +[tasks.checkfc] +workspace = false +dependencies = ["fmt", "check", "clippy"] + +[tasks.checkall] +workspace = false +dependencies = ["fmt", "check", "clippy", "test", "bench"] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ed08b3e --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +fn main() { + cxx_build::bridge("src/lib.rs") + .include("/rawaccel") + .flag("/std:c++17") + .compile("rawaccel"); + + println!("cargo:rerun-if-changed=src/lib.rs"); + println!("cargo:rerun-if-changed=rawaccel"); +} diff --git a/rawaccel b/rawaccel new file mode 160000 +Subproject 2896b8a09ce42e965705c58593b8738adc454f7 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..09396e5 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2021-12-04" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..cdca26c --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,29 @@ +condense_wildcard_suffixes = true +edition = "2021" +enum_discrim_align_threshold = 20 +# error_on_line_overflow = true +# error_on_unformatted = true +fn_single_line = true +force_multiline_blocks = true +format_code_in_doc_comments = true +format_macro_matchers = true +format_strings = true +imports_layout = "HorizontalVertical" +# license_template_path = ".license_template" +match_arm_blocks = false +imports_granularity = "Crate" +newline_style = "Unix" +normalize_comments = true +normalize_doc_attributes = true +reorder_impl_items = true +group_imports = "StdExternalCrate" +reorder_modules = true +report_fixme = "Always" +# report_todo = "Always" +struct_field_align_threshold = 20 +struct_lit_single_line = false +tab_spaces = 2 +use_field_init_shorthand = true +use_try_shorthand = true +where_single_line = true +wrap_comments = true diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..5252d2c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,26 @@ +#![feature(extern_types)] + +#[cxx::bridge(namespace = "rawaccel")] +pub mod utility { + unsafe extern "C++" { + include!("rawaccel-sys/rawaccel/common/utility.hpp"); + + pub fn minsd(a: f64, b: f64) -> f64; + pub fn maxsd(a: f64, b: f64) -> f64; + pub fn clampsd(v: f64, lo: f64, hi: f64) -> f64; + pub fn ilogb(x: f64) -> i32; + pub fn scalbn(x: f64, n: i32) -> f64; + pub fn infnan(x: f64) -> bool; + } +} + +#[cfg(test)] +mod test { + use crate::utility; + + #[test] + fn test_utility_minsd() { assert_eq!(utility::minsd(2.0, 3.0), 2.0) } + + #[test] + fn test_utility_maxsd() { assert_eq!(utility::maxsd(2.0, 3.0), 3.0) } +} |