Skip to content

Commit 23af2bf

Browse files
authored
Split code into features (#137)
* upgrade async-std to 1.6 beta * add ip feature * add glob feature * add cacehd feature * fix runtime-tokio clippy warnings * add watcher feature * don't clone if watcher feature has been disabled * use async-rs/async-std#768 for fixing tests * activate all features for bench test over previous version * benchmark pull_request and decrease the threshold * switch to github actions * fix typo * Fix: cargo test features doesn't like space * better management of feature:logging and feature:watcher * use async-std/master for testing * add basic wasm32 support * use runtime-async-std for wasm32 test * fix clippy warnings * fix typo * make other tests avalaible only on no-wasm32 target * finish split code into features && bump version
1 parent 1824313 commit 23af2bf

23 files changed

+892
-280
lines changed

.github/workflows/benchmark.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Benchmark
22
on:
3+
pull_request:
34
push:
45
branches:
56
- master
@@ -23,7 +24,8 @@ jobs:
2324
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
2425
auto-push: true
2526
# Show alert with commit comment on detecting possible performance regression
26-
alert-threshold: '200%'
27+
alert-threshold: '150%'
2728
comment-on-alert: true
29+
comment-always: true
2830
fail-on-alert: true
2931
alert-comment-cc-users: '@GopherJ'

.github/workflows/ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
name: Auto Build CI
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@master
17+
18+
- name: Install Rust toolchain
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
profile: minimal
22+
toolchain: stable
23+
components: rustfmt, clippy
24+
override: true
25+
26+
- name: Install Dependencies
27+
run: sudo apt-get install libssl-dev
28+
29+
- name: Cargo Clean
30+
uses: actions-rs/cargo@v1
31+
with:
32+
command: clean
33+
34+
- name: Cargo Build
35+
uses: actions-rs/cargo@v1
36+
with:
37+
command: build
38+
39+
# Todo: https://github.com/rust-lang/cargo/issues/2980
40+
- name: Cargo Test For All Features Using async-std
41+
uses: actions-rs/cargo@v1
42+
with:
43+
command: test
44+
args: --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging
45+
46+
- name: Cargo Test For All Features Using tokio
47+
uses: actions-rs/cargo@v1
48+
with:
49+
command: test
50+
args: --no-default-features --features runtime-tokio,cached,glob,ip,watcher,logging
51+
52+
- name: Cargo Check Wasm
53+
uses: actions-rs/cargo@v1
54+
with:
55+
command: check
56+
target: wasm32-unknown-unknown
57+
override: true
58+
args: --no-default-features --features runtime-async-std,cached,glob,ip,watcher,logging
59+
60+
- name: Cargo Clippy
61+
uses: actions-rs/cargo@v1
62+
with:
63+
command: clippy
64+
args: -- -D warnings
65+
66+
- name: Cargo Fmt Check
67+
uses: actions-rs/cargo@v1
68+
with:
69+
command: fmt
70+
args: --all -- --check

.github/workflows/coverage.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Coverage
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
cover:
11+
name: Auto Codecov Coverage
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@master
17+
18+
- name: Install Rust toolchain
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
profile: minimal
22+
toolchain: stable
23+
override: true
24+
25+
- name: Run cargo-tarpaulin
26+
uses: actions-rs/[email protected]
27+
with:
28+
args: --out Xml
29+
30+
- name: Upload to codecov.io
31+
uses: codecov/codecov-action@v1
32+
with:
33+
token: ${{secrets.CODECOV_TOKEN}}

.travis.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

Cargo.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "casbin"
3-
version = "0.7.1"
3+
version = "0.7.2"
44
authors = ["Joey <[email protected]>", "Cheng JIANG <[email protected]>"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -15,27 +15,34 @@ keywords = ["auth", "authorization", "rbac", "acl", "abac"]
1515
[dependencies]
1616
regex = "1.3.1"
1717
rhai = { version = "0.13.0", default-features = false, features = ["sync", "only_i32", "no_function", "no_float"] }
18-
ip_network = "0.3.4"
19-
ttl_cache = "0.5.1"
18+
ip_network = { version = "0.3.4", optional = true }
19+
ttl_cache = { version = "0.5.1", optional = true }
2020
lazy_static = "1.4.0"
2121
indexmap = "1.3.1"
2222
async-std = { version = "1.5.0", optional = true }
2323
async-trait = "0.1.24"
2424
log = { version = "0.4.8", optional = true }
2525
tokio = { version = "0.2.11", optional = true, default-features = false }
26-
globset = "0.4.5"
26+
globset = { version = "0.4.5", optional = true }
2727
thiserror = "1.0.14"
2828

2929
[features]
3030
default = ["runtime-async-std"]
3131

32-
runtime-tokio = ["tokio/fs", "tokio/io-util", "tokio/stream", "tokio/rt-threaded", "tokio/blocking"]
32+
runtime-tokio = ["tokio/fs", "tokio/io-util"]
3333
runtime-async-std = ["async-std"]
3434
logging = ["log"]
35+
ip = ["ip_network"]
36+
glob = ["globset"]
37+
cached = ["ttl_cache"]
38+
watcher = []
3539

3640
[profile.release.build-override]
3741
opt-level = 0
3842

39-
[dev-dependencies]
43+
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
4044
async-std = { version = "1.5.0", features = [ "attributes" ] }
45+
46+
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
4147
tokio = { version = "0.2.11", features = [ "full" ] }
48+
async-std = { version = "1.5.0", features = [ "attributes" ] }

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
[![Crates.io](https://img.shields.io/crates/v/casbin.svg)](https://crates.io/crates/casbin)
55
[![crates.io](https://img.shields.io/crates/d/casbin)](https://crates.io/crates/casbin)
66
[![Docs](https://docs.rs/casbin/badge.svg)](https://docs.rs/casbin)
7-
[![Build Status](https://travis-ci.org/casbin/casbin-rs.svg?branch=master)](https://travis-ci.org/casbin/casbin-rs)
8-
[![codecov](https://codecov.io/gh/casbin/casbin-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin/casbin-rs)
7+
[![CI](https://github.com/casbin/casbin-rs/workflows/CI/badge.svg)](https://github.com/casbin/casbin-rs/actions)
8+
[![Codecov](https://codecov.io/gh/casbin/casbin-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/casbin/casbin-rs)
99

1010
**Casbin-RS** is a powerful and efficient open-source access control library for Rust projects. It provides support for enforcing authorization based on various [access control models](https://en.wikipedia.org/wiki/Computer_security_model).
1111

@@ -27,7 +27,7 @@ Add this package to `Cargo.toml` of your project. (Check https://crates.io/crate
2727

2828
```toml
2929
[dependencies]
30-
casbin = { version = "0.7.1", default-features = false, features = ["runtime-async-std", "logging"] }
30+
casbin = { version = "0.7.2", default-features = false, features = ["runtime-async-std", "logging"] }
3131
async-std = { version = "1.5.0", features = ["attributes"] }
3232
env_logger = "0.7.1"
3333
```

benches/benchmark.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn b_benchmark_basic_model(b: &mut Bencher) {
6363
});
6464
}
6565

66+
#[cfg(feature = "cached")]
6667
#[bench]
6768
fn b_benmark_cached_basic_model(b: &mut Bencher) {
6869
let mut e = await_future(CachedEnforcer::new(
@@ -89,6 +90,7 @@ fn b_benchmark_rbac_model(b: &mut Bencher) {
8990
});
9091
}
9192

93+
#[cfg(feature = "cached")]
9294
#[bench]
9395
fn b_benchmark_cached_rbac_model(b: &mut Bencher) {
9496
let mut e = await_future(CachedEnforcer::new(
@@ -139,6 +141,7 @@ fn b_benchmark_rbac_model_small(b: &mut Bencher) {
139141
b.iter(|| await_future(e.enforce(&["user501", "data9", "read"])).unwrap());
140142
}
141143

144+
#[cfg(feature = "cached")]
142145
#[bench]
143146
fn b_benchmark_cached_rbac_model_small(b: &mut Bencher) {
144147
let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap();
@@ -213,6 +216,7 @@ fn b_benchmark_rbac_model_medium(b: &mut Bencher) {
213216
b.iter(|| await_future(e.enforce(&["user5001", "data15", "read"])).unwrap());
214217
}
215218

219+
#[cfg(feature = "cached")]
216220
#[bench]
217221
fn b_benchmark_cached_rbac_model_medium(b: &mut Bencher) {
218222
let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap();
@@ -287,6 +291,7 @@ fn b_benchmark_rbac_model_large(b: &mut Bencher) {
287291
b.iter(|| await_future(e.enforce(&["user50001", "data1500", "read"])).unwrap());
288292
}
289293

294+
#[cfg(feature = "cached")]
290295
#[bench]
291296
fn b_benchmark_cached_rbac_model_large(b: &mut Bencher) {
292297
let mut e = await_future(CachedEnforcer::new("examples/rbac_model.conf", ())).unwrap();
@@ -335,6 +340,7 @@ fn b_benchmark_rbac_with_resource_roles(b: &mut Bencher) {
335340
b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap());
336341
}
337342

343+
#[cfg(feature = "cached")]
338344
#[bench]
339345
fn b_benchmark_cached_rbac_with_resource_roles(b: &mut Bencher) {
340346
let mut e = await_future(CachedEnforcer::new(
@@ -357,6 +363,7 @@ fn b_benchmark_rbac_model_with_domains(b: &mut Bencher) {
357363
b.iter(|| await_future(e.enforce(&["alice", "domain1", "data1", "read"])).unwrap());
358364
}
359365

366+
#[cfg(feature = "cached")]
360367
#[bench]
361368
fn b_benchmark_cached_rbac_model_with_domains(b: &mut Bencher) {
362369
let mut e = await_future(CachedEnforcer::new(
@@ -375,6 +382,7 @@ fn b_benchmark_abac_model(b: &mut Bencher) {
375382
b.iter(|| await_future(e.enforce(&["alice", r#"{"Owner": "alice"}"#, "read"])).unwrap());
376383
}
377384

385+
#[cfg(feature = "cached")]
378386
#[bench]
379387
fn b_benchmark_cached_abac_model(b: &mut Bencher) {
380388
let mut e = await_future(CachedEnforcer::new("examples/abac_model.conf", ())).unwrap();
@@ -393,6 +401,7 @@ fn b_benchmark_key_match(b: &mut Bencher) {
393401
b.iter(|| await_future(e.enforce(&["alice", "/alice_data/resource1", "GET"])).unwrap());
394402
}
395403

404+
#[cfg(feature = "cached")]
396405
#[bench]
397406
fn b_benchmark_cached_key_match(b: &mut Bencher) {
398407
let mut e = await_future(CachedEnforcer::new(
@@ -415,6 +424,7 @@ fn b_benchmark_rbac_with_deny(b: &mut Bencher) {
415424
b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap());
416425
}
417426

427+
#[cfg(feature = "cached")]
418428
#[bench]
419429
fn b_benchmark_cached_rbac_with_deny(b: &mut Bencher) {
420430
let mut e = await_future(CachedEnforcer::new(
@@ -437,6 +447,7 @@ fn b_benchmark_priority_model(b: &mut Bencher) {
437447
b.iter(|| await_future(e.enforce(&["alice", "data1", "read"])).unwrap());
438448
}
439449

450+
#[cfg(feature = "cached")]
440451
#[bench]
441452
fn b_benchmark_cached_priority_model(b: &mut Bencher) {
442453
let mut e = await_future(CachedEnforcer::new(

src/adapter/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use async_trait::async_trait;
22

3+
#[cfg(not(target_arch = "wasm32"))]
34
pub mod file_adapter;
45
pub mod memory_adapter;
56
pub mod null_adapter;
67

8+
#[cfg(not(target_arch = "wasm32"))]
79
pub use file_adapter::FileAdapter;
810
pub use memory_adapter::MemoryAdapter;
911
pub use null_adapter::NullAdapter;

0 commit comments

Comments
 (0)