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
19 changes: 10 additions & 9 deletions .github/workflows/_c_cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ on:
workflow_call:
inputs:
os:
description: 'Operating system to run on'
description: "Operating system to run on"
required: false
type: string
default: 'ubuntu-latest'
default: "ubuntu-latest"

jobs:
jobs:
# ----------------------------------------------------------------------------
# Build C and C++ Package
# ----------------------------------------------------------------------------


# ----------------------------------------------------------------------------
# Test C
# ----------------------------------------------------------------------------
Expand All @@ -37,7 +36,7 @@ jobs:
path: ~/.cache/bazel
key: bazel-${{ runner.os }}
restore-keys: bazel-${{ runner.os }}

- name: Run C Example (Bazel)
run: |
bazel run //examples/c:c_example
Expand Down Expand Up @@ -84,10 +83,12 @@ jobs:
path: ~/.cache/bazel
key: bazel-${{ runner.os }}
restore-keys: bazel-${{ runner.os }}

- name: Run C++ Example (Bazel)
run: |
bazel run //examples/cpp:cpp_example
run: bazel run //examples/cpp:cpp_example

- name: Run C++ Regression Tests
run: bazel test //tests:regression_cpp_tests --test_output=errors --keep_going
Comment thread
alextac98 marked this conversation as resolved.

test-cpp-cmake:
name: Test C++ Bindings with CMake
Expand All @@ -113,4 +114,4 @@ jobs:
# Publish C/C++ Package
# ----------------------------------------------------------------------------

# No publish step for C/C++ packages
# No publish step for C/C++ packages
35 changes: 26 additions & 9 deletions .github/workflows/_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ jobs:
matrix:
platform:
# Linux
- { os: linux, runner: ubuntu-latest, target: x86_64-unknown-linux-gnu } # x86 64-bit
- { os: linux, runner: ubuntu-latest, target: aarch64-unknown-linux-gnu } # Arm 64-bit
- { os: linux, runner: ubuntu-latest, target: armv7-unknown-linux-gnueabihf } # Arm 32-bit
- {
os: linux,
runner: ubuntu-latest,
target: x86_64-unknown-linux-gnu,
} # x86 64-bit
- {
os: linux,
runner: ubuntu-latest,
target: aarch64-unknown-linux-gnu,
} # Arm 64-bit
- {
os: linux,
runner: ubuntu-latest,
target: armv7-unknown-linux-gnueabihf,
} # Arm 32-bit
# macOS
- { os: macos, runner: macos-latest, target: universal2-apple-darwin } # MacOS Universal
- { os: macos, runner: macos-latest, target: universal2-apple-darwin } # MacOS Universal
# Windows
- { os: windows, runner: windows-latest, target: x86_64-pc-windows-msvc } # x86 64-bit
- {
os: windows,
runner: windows-latest,
target: x86_64-pc-windows-msvc,
} # x86 64-bit
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -35,7 +51,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
python-version: "3.12"

- name: Build wheels
uses: PyO3/maturin-action@v1
Expand All @@ -50,7 +66,6 @@ jobs:
name: wheels-${{ matrix.platform.os }}-${{ matrix.platform.target }}
path: python/dist/*.whl


# ----------------------------------------------------------------------------
# Test Python Bindings
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -81,9 +96,11 @@ jobs:
- name: Run Python Example
run: bazel run //examples/python:python_example

- name: Run Python Regression Tests
run: bazel test //tests:regression_python_tests --test_output=errors --keep_going

# ----------------------------------------------------------------------------
# Publsih Python Wheels
# Publish Python Wheels
# ----------------------------------------------------------------------------

python-publish-pypi:
Expand All @@ -103,4 +120,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: dist/
packages-dir: dist/
12 changes: 7 additions & 5 deletions .github/workflows/_rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
workflow_call:
inputs:
os:
description: 'Operating system to run on'
description: "Operating system to run on"
required: false
type: string
default: 'ubuntu-latest'
default: "ubuntu-latest"
secrets:
CARGO_REGISTRY_TOKEN:
required: true
Expand All @@ -18,7 +18,7 @@ jobs:
# ----------------------------------------------------------------------------

# No build step is needed for Rust in Bazel, already happened in main workflow

# ----------------------------------------------------------------------------
# Test Rust
# ----------------------------------------------------------------------------
Expand All @@ -43,8 +43,10 @@ jobs:
restore-keys: bazel-${{ runner.os }}

- name: Test Core
run: |
bazel test //core/... --test_output=errors --keep_going
run: bazel test //core/... --test_output=errors --keep_going

- name: Run Regression Tests
run: bazel test //tests:regression_rust_tests --test_output=errors --keep_going

# ----------------------------------------------------------------------------
# Publish Rust Crate
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ permissions:
actions: read

jobs:

# ============================================================================
# General Jobs
# ============================================================================
Expand Down Expand Up @@ -69,6 +68,29 @@ jobs:
- name: Build everything
run: bazel build //... --keep_going

test:
name: Test All
runs-on: ubuntu-latest
needs: build
env:
CI: true
BAZELISK_ALLOW_ENVS: Y
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel
key: bazel-${{ runner.os }}
restore-keys: bazel-${{ runner.os }}

- name: Test everything
run: bazel test //... --test_output=errors --keep_going

# =============================================================================
# Language-Specific Test Jobs
# =============================================================================
Expand Down
103 changes: 103 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# AGENTS.md - Guidance for agentic coding tools working in this repo.

## Project Summary

This project is a library in multiple languages for handling units and checking consistency in mathematical operations and conversions. The core functionality is implemented in Rust, with each language binding having their own folder. The entire project is managed by Bazel as a build system.

### Common Targets (Bazel)

- Rust core library: `//core:dv_rs`
- Rust tests: `//core:unit_tests`, `//core:units_tests`, `//core:operator_tests`
- Python test: `//python:test_dv`
- C example: `//examples/c:c_example`
- C++ example: `//examples/cpp:cpp_example`

### Folder Structure

- `core`: Contains the core library implemented in Rust.
- `docs`: Documentation for the project for both users and developers.
- `python`: Python bindings for the core library.
- `cpp`: C++ bindings for the core library.

## Notes for Agents

- If you need CI parity, mirror workflow commands in `.github/workflows/*.yaml`.

### Code Review Guidelines

- Focus on overall structure, design patterns, and correctness.
- Avoid nitpicking formatting or comments unless they are egregiously bad.
- Ensure adherence to coding standards and best practices.

## Build, Test, and Lint Commands

### Bazel (preferred for all languages)

- Build everything: `bazel build //... --keep_going`
- Test everything: `bazel test //... --test_output=errors --keep_going`

### Rust (core)
- Build core: `bazel build //core:dv_rs`
- Run all core tests: `bazel test //core/... --test_output=errors --keep_going`
- Run a single Rust test target: `bazel test //core:units_tests`
- Run a single Rust test function:
`bazel test //core:units_tests --test_arg=angle_conversions`
(Use Rust test name; Bazel passes args to the test binary.)
- Generate docs: `bazel build //core:docs`
- Serve docs: `bazel run //core:serve_docs`

### Python (bindings)
- Run Python tests: `bazel test //python/... --test_output=errors --keep_going`
- Run the Python example: `bazel run //examples/python:python_example`
- Single Python test target: `bazel test //python:test_dv`
- Single Python test function (pytest -k):
`bazel test //python:test_dv --test_arg=-k --test_arg=TestMathFunctions`

### C/C++ (bindings/examples)
- Run C example (Bazel): `bazel run //examples/c:c_example`
- Run C++ example (Bazel): `bazel run //examples/cpp:cpp_example`
- CMake demos (optional):
`cmake -S . -B build && cmake --build build --target dv_example_c dv_example_cpp`

### Docs (Docusaurus)
- Docs live under `docs/` and are managed via Bazel + pnpm.
- Update pnpm lockfile (from `docs/`):
`bazel run -- @pnpm --dir $PWD install --lockfile-only`

### Linting / Formatting
- No explicit lint or formatter config is enforced in this repo (yet)
- For Rust, follow `rustfmt`-style formatting if you need to reformat.
- For Python, follow PEP 8 style and keep imports sorted.

## Code Style Guidelines
### Cross-cutting
- Prefer Bazel targets over ad-hoc build scripts.
- Keep changes minimal; avoid introducing new tools unless required.
- Favor clear, explicit error messages that help users of the bindings.

### Rust (core)
- Edition: 2021 (see `core/BUILD.bazel`).
- Naming: `snake_case` for functions/modules, `CamelCase` for types.
- Error handling: return `Result<_, String>` with clear messages.
- Use `expect` with a shared `FAIL_MSG` in tests (see `core/tests`).
- Prefer explicit conversions and unit compatibility checks.
- Keep unit parsing rules documented in doc comments.
- Use `&DimensionalVariable` for operator implementations to avoid copies.
- Avoid unnecessary `return` but keep consistent with existing style.

### Python (bindings/tests)
- Testing framework: `pytest`.
- Test classes named `TestSomething`, methods named `test_*`.
- Keep docstrings on test classes/methods for clarity.
- Import order: stdlib, third-party, local (`dv_py`), then specific symbols.
- Raise and assert `DVError` for invalid operations.

### C/C++ (bindings)
- Headers live in `cpp/include`:
- `dv_c.h` for C API
- `dv.hpp` for C++ RAII wrapper
- CMake support is minimal; prefer Bazel for consistency.

### Docs (Docusaurus)
- Source in `docs/src` and `docs/docs`.
- Follow existing structure and avoid large refactors for small changes.
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bazel_dep(name = "rules_cc", version = "0.2.8")
bazel_dep(name = "rules_python", version = "1.6.3")
bazel_dep(name = "rules_uv", version = "0.88.0")
bazel_dep(name = "aspect_rules_js", version = "2.6.0")
bazel_dep(name = "nlohmann_json", version = "3.11.3")

# =============================================================================
# Rust Setup
Expand All @@ -25,6 +26,15 @@ rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2024")
use_repo(rust, "rust_toolchains")

# Shared Rust crates for workspace tests/utilities
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.spec(
package = "serde_json",
version = "1.0",
)
crate.from_specs()
use_repo(crate, "crates")

# ==============================================================================
# PyO3 Setup
# ==============================================================================
Expand Down
259 changes: 259 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

major = 0
minor = 3
patch = 2
patch = 3
2 changes: 1 addition & 1 deletion core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ filegroup(
name = "rust_sources",
srcs = glob(["**/*.rs", "**/*.toml", "**/*.md"]),
visibility = ["//python:__pkg__"],
)
)
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dv"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
authors = [ "Alex Tacescu <alextac98@gmail.com>",]
description = "Core Rust library for DimensionalVariable, a multi-language library for handling physical quantities with units."
Expand Down
Loading