-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
a3beb9a
commit 321caad
Showing
13 changed files
with
218 additions
and
25 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/target | ||
/Cargo.lock | ||
/cargo/*/Cargo.toml | ||
/cargo/*/Cargo.lock | ||
/*.profraw | ||
.idea | ||
.idea |
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,36 @@ | ||
DEV_DEPENDENCIES_LINE = $(shell cat Cargo.toml | grep -n "\[dev-dependencies\]" | cut -d : -f 1) | ||
DELIMITING_LINE = $(shell echo $$(( $(DEV_DEPENDENCIES_LINE) - 2 ))) | ||
TOTAL_LINES = $(shell cat Cargo.toml | wc -l) | ||
TAIL_LINES = $(shell echo $$(( $(TOTAL_LINES) - $(DELIMITING_LINE) ))) | ||
|
||
python: | ||
@head -n $(DELIMITING_LINE) Cargo.toml > cargo/$@/Cargo.toml | ||
@echo "pyo3 = { version = \"0.18.0\", features = [\"abi3\", \"extension-module\"] }" >> cargo/$@/Cargo.toml | ||
@tail -n $(TAIL_LINES) Cargo.toml >> cargo/$@/Cargo.toml | ||
@echo >> cargo/$@/Cargo.toml | ||
@cat cargo/$@/Cargo.toml.tail >> cargo/$@/Cargo.toml | ||
@cd cargo/$@ && cargo build --release --target-dir ../../target/$@ | ||
@mv target/$@/release/libcesride.dylib target/$@/release/cesride.so | ||
|
||
python-shell: | ||
@cd target/python/release/ && python3 | ||
|
||
rust: | ||
@cargo build --release | ||
|
||
libs: rust python | ||
|
||
clean: | ||
cargo clean | ||
|
||
fix: | ||
cargo fix | ||
cargo fmt | ||
|
||
preflight: | ||
cargo fmt --check | ||
cargo clippy -- -D warnings | ||
cargo build --release | ||
cargo test --release | ||
cargo audit | ||
cargo tarpaulin |
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
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,11 @@ | ||
[target.x86_64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] | ||
|
||
[target.aarch64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] |
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,11 @@ | ||
[lib] | ||
path = "../../src/lib_python.rs" | ||
test = false | ||
doctest = false | ||
bench = true | ||
doc = true | ||
crate-type = ["cdylib"] | ||
|
||
[features] | ||
default = ["python"] | ||
python = [] |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub(crate) mod tables; | ||
pub mod tables; | ||
|
||
use crate::core::util; | ||
use crate::error::{err, Error, Result}; | ||
|
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod cigar; | ||
mod counter; | ||
mod diger; | ||
mod matter; | ||
mod util; | ||
mod verfer; | ||
pub mod cigar; | ||
pub mod counter; | ||
pub mod diger; | ||
pub mod matter; | ||
pub mod util; | ||
pub mod verfer; |
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
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,16 @@ | ||
// TODO: remove before 1.0.0 | ||
#![allow(dead_code)] | ||
|
||
use pyo3::prelude::*; | ||
|
||
mod core; | ||
mod error; | ||
mod python; | ||
|
||
use crate::core::matter::Matter; | ||
|
||
#[pymodule] | ||
fn cesride(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_class::<Matter>()?; | ||
Ok(()) | ||
} |
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,76 @@ | ||
use pyo3::{ | ||
prelude::*, | ||
exceptions::{PyException, PyValueError}, | ||
}; | ||
|
||
use crate::core::matter::Matter; | ||
|
||
#[pymethods] | ||
impl Matter { | ||
#[new] | ||
fn py_new( | ||
code: Option<&str>, | ||
raw: Option<&[u8]>, | ||
raw_size: Option<usize>, | ||
qb64: Option<&str>, | ||
qb64b: Option<&[u8]>, | ||
qb2: Option<&[u8]>, | ||
) -> PyResult<Self> { | ||
let result = if let Some(code) = code { | ||
let (raw, raw_size) = if raw.is_none() || raw_size.is_none() { | ||
return Err(PyValueError::new_err("code present, raw and raw_size missing")); | ||
} else { | ||
(raw.unwrap(), raw_size.unwrap()) | ||
}; | ||
|
||
Self::new_with_code_and_raw(code, raw, raw_size) | ||
} else if let Some(qb64) = qb64 { | ||
Self::new_with_qb64(qb64) | ||
} else if let Some(qb64b) = qb64b { | ||
Self::new_with_qb64b(qb64b) | ||
} else if let Some(qb2) = qb2 { | ||
Self::new_with_qb2(qb2) | ||
} else { | ||
return Err(PyValueError::new_err("must specify some parameters")); | ||
}; | ||
|
||
match result { | ||
Ok(matter) => Ok(matter), | ||
Err(e) => Err(PyException::new_err(e.to_string())), | ||
} | ||
} | ||
|
||
#[pyo3(name = "code")] | ||
fn py_code(&self) -> String { | ||
self.code() | ||
} | ||
|
||
#[pyo3(name = "raw")] | ||
fn py_raw(&self) -> Vec<u8> { | ||
self.raw() | ||
} | ||
|
||
#[pyo3(name = "qb64")] | ||
fn py_qb64(&self) -> PyResult<String> { | ||
match self.qb64() { | ||
Ok(s) => Ok(s), | ||
Err(e) => Err(PyException::new_err(e.to_string())), | ||
} | ||
} | ||
|
||
#[pyo3(name = "qb64b")] | ||
fn py_qb64b(&self) -> PyResult<Vec<u8>> { | ||
match self.qb64b() { | ||
Ok(b) => Ok(b), | ||
Err(e) => Err(PyException::new_err(e.to_string())), | ||
} | ||
} | ||
|
||
#[pyo3(name = "qb2")] | ||
fn py_qb2(&self) -> PyResult<Vec<u8>> { | ||
match self.qb2() { | ||
Ok(b) => Ok(b), | ||
Err(e) => Err(PyException::new_err(e.to_string())), | ||
} | ||
} | ||
} |
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 @@ | ||
mod matter; |