Skip to content

Commit 50dddca

Browse files
committed
feat(ffi): add python and wasm bindings
1 parent c0ea708 commit 50dddca

9 files changed

Lines changed: 565 additions & 8 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build Python wheels
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
build-wheels:
11+
name: Build wheels (${{ matrix.platform }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
include:
17+
- os: ubuntu-22.04
18+
platform: manylinux_x86_64
19+
- os: ubuntu-22.04
20+
platform: manylinux_aarch64
21+
- os: macos-13
22+
platform: macos_x86_64
23+
- os: macos-14
24+
platform: macos_aarch64
25+
- os: windows-2022
26+
platform: windows_x86_64
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.11"
35+
36+
- name: Build wheels
37+
uses: PyO3/maturin-action@v1
38+
with:
39+
command: build
40+
args: --release --out dist
41+
maturin-version: "1.5.1"
42+
manylinux: auto
43+
target: ${{ matrix.platform }}
44+
features: python-ffi
45+
46+
- name: Upload wheels
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: wheels-${{ matrix.platform }}
50+
path: dist/*.whl
51+
52+
sdist:
53+
name: Build sdist
54+
runs-on: ubuntu-22.04
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Set up Python
59+
uses: actions/setup-python@v5
60+
with:
61+
python-version: "3.11"
62+
63+
- name: Build sdist
64+
uses: PyO3/maturin-action@v1
65+
with:
66+
command: sdist
67+
args: --out dist
68+
maturin-version: "1.5.1"
69+
features: python-ffi
70+
71+
- name: Upload sdist
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: sdist
75+
path: dist/*.tar.gz

Cargo.toml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,39 @@ crate-type = ["cdylib", "rlib"]
99
[dependencies]
1010
memmap2 = "0.9"
1111
memchr = "2.7"
12-
ratatui = "0.26"
13-
crossterm = "0.27"
12+
ratatui = { version = "0.26", optional = true }
13+
crossterm = { version = "0.27", optional = true }
1414
clap = { version = "4.4", features = ["derive"] }
1515
owo-colors = { version = "4.0", features = ["supports-colors"] }
16-
ureq = "2.9"
17-
tempfile = "3.10"
16+
ureq = { version = "2.9", optional = true }
17+
tempfile = { version = "3.10", optional = true }
1818
aho-corasick = "1.1"
1919
base64 = "0.21"
2020
ignore = "0.4.25"
2121
rayon = "1.11.0"
2222
log = "0.4"
23-
env_logger = "0.10"
23+
env_logger = { version = "0.10", optional = true }
2424
serde = { version = "1.0", features = ["derive"] }
2525
serde_json = "1.0"
2626
tree-sitter = { version = "0.25", optional = true }
2727
tree-sitter-javascript = { version = "0.25", optional = true }
2828
syntect = { version = "5.2", optional = true }
2929
pyo3 = { version = "0.21", features = ["extension-module", "abi3-py311"], optional = true }
30+
wasm-bindgen = { version = "0.2.92", optional = true }
31+
serde-wasm-bindgen = { version = "0.6", optional = true }
3032

3133
[features]
32-
default = []
34+
default = ["native"]
35+
native = ["ureq", "tempfile", "env_logger", "ratatui", "crossterm"]
3336
js-ast = ["tree-sitter", "tree-sitter-javascript"]
3437
highlighting = ["syntect"]
3538
python-ffi = ["pyo3"]
39+
wasm-ffi = ["wasm-bindgen", "serde-wasm-bindgen"]
40+
41+
[[bin]]
42+
name = "argus"
43+
path = "src/main.rs"
44+
required-features = ["native"]
3645

3746
[profile.release]
3847
opt-level = 3

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ print(scan_json(opts))
177177

178178
---
179179

180+
## WASM Support
181+
182+
Build a WASM module with in-memory scanning (no filesystem access) using the `wasm-ffi` feature.
183+
184+
```bash
185+
cargo build --target wasm32-unknown-unknown --release --no-default-features --features wasm-ffi
186+
```
187+
188+
The module exports `scan_bytes_json(bytes, options)` and `scan_bytes_count(bytes, options)`.
189+
190+
---
191+
180192
## Deep Analysis and Security Heuristics
181193

182194
argus moves beyond simple pattern matching by applying a suite of heuristics to every potential match. When using `--deep-scan`, the following specific analysis modules are activated:

python/argus_ffi/py.typed

Whitespace-only changes.

python/tests/test_import.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def test_import_and_scan_json():
2+
import argus_ffi
3+
4+
opts = argus_ffi.ScanOptions(
5+
targets=["."],
6+
keywords=["token"],
7+
entropy=False,
8+
deep_scan=False,
9+
flow_scan=False,
10+
request_trace=False,
11+
mode="scan",
12+
)
13+
14+
out = argus_ffi.scan_json(opts)
15+
assert isinstance(out, str)

0 commit comments

Comments
 (0)