Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
43 changes: 29 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Requires [Nix](https://nixos.org/) with flakes enabled.

```bash
# enter dev shell
direnv allow # or: nix develop
```

Expand All @@ -15,42 +14,58 @@ direnv allow # or: nix develop
cargo build --workspace
cargo test --workspace
cargo clippy --workspace -- -D warnings
cargo fmt --check
```

## Bazel

```bash
build # alias: bazel build //...
test # alias: bazel test //...
check # alias: bazel test //...
```

## Format
## Parity tests

Every module must produce identical results across all bindings. The `tests/parity/` suite generates a `golden.json` from `stdbr-core` and validates Rust, Node.js, Python, FFI-C, and WASM against it.

```bash
fmt # alias: nix fmt
bazel test //tests/parity/...
```

## Building specific bindings
When adding a new function to core, add the corresponding test cases to `tools/parity_gen/src/main.rs` and update every `test_parity.*` file.

```bash
cargo build -p stdbr-python
cargo build -p stdbr-wasm --target wasm32-unknown-unknown
cd bindings/python && maturin develop
cd bindings/wasm && wasm-pack build --target web
```
## Adding a new binding target

1. Create `bindings/<target>/` with `Cargo.toml` and source
2. Expose the same API surface as existing bindings (parse, validate, format, generate)
3. Add `test_parity.*` that reads `golden.json` and validates all cases
4. Add build + test rules in `tests/parity/BUILD.bazel`
5. Register the Cargo manifest in `MODULE.bazel`

## Adding a new BR module

1. Implement in `core/src/<module>.rs` (`no_std` + `alloc`)
2. Export from `core/src/lib.rs`
3. Add bindings in all targets: `ffi-c`, `nodejs`, `python`, `wasm`
4. Add golden test cases in `tools/parity_gen/src/main.rs`
5. Update all `test_parity.*` files to cover the new module
6. If the module needs external data (like municipio uses IBGE), add a sync workflow in `.github/workflows/`

## Project structure

```
stdbr/
core/ # stdbr-core (no_std Rust library)
bindings/
ffi-c/ # C/C++ FFI (cdylib + staticlib + cbindgen)
ffi-c/ # C/C++ FFI (staticlib + cbindgen)
nodejs/ # Node.js via napi-rs
python/ # Python via PyO3 + maturin
wasm/ # WebAssembly via wasm-bindgen
tools/ # Bazel custom rules
.github/workflows/ # CI (Nix-based)
tools/
parity_gen/ # Golden test data generator
rules_rust_extras/ # Bazel custom rules (cbindgen)
tests/parity/ # Cross-binding parity tests
.github/workflows/ # CI + IBGE sync
flake.nix # Nix dev environment
MODULE.bazel # Bazel module config
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fullzer4/stdbr/actions/workflows/ci.yml/badge.svg)](https://github.com/fullzer4/stdbr/actions/workflows/ci.yml)
[![IBGE Sync](https://github.com/fullzer4/stdbr/actions/workflows/ibge-sync.yml/badge.svg)](https://github.com/fullzer4/stdbr/actions/workflows/ibge-sync.yml)
[![License: Apache-2.0](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](LICENSE)
[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)

Standard library for Brazil.

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
category = "bazel";
}
{
name = "test";
name = "check";
command = "bazel test //...";
help = "Run all tests";
category = "bazel";
Expand Down
Loading