diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..92b2793 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +.direnv diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d343d84..10bec8e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,6 @@ Requires [Nix](https://nixos.org/) with flakes enabled. ```bash -# enter dev shell direnv allow # or: nix develop ``` @@ -15,29 +14,42 @@ 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//` 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/.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 @@ -45,12 +57,15 @@ cd bindings/wasm && wasm-pack build --target web 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 ``` diff --git a/README.md b/README.md index eda2eba..2c9a453 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/flake.nix b/flake.nix index 0afdc33..095f11d 100644 --- a/flake.nix +++ b/flake.nix @@ -96,7 +96,7 @@ category = "bazel"; } { - name = "test"; + name = "check"; command = "bazel test //..."; help = "Run all tests"; category = "bazel";