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
2 changes: 1 addition & 1 deletion .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
# CodeRabbit review settings for SwiftGraphviz. CLAUDE.md is picked up as review
# CodeRabbit review settings for SwiftGraphviz. AGENTS.md is picked up as review
# guidelines automatically; the instructions below add what matters per path.
language: en-US

Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/CGraphviz.artifactbundle/ @Vithanco
/CGraphvizWasm.artifactbundle/ @Vithanco
/artifacts.sha256 @Vithanco
/AGENTS.md @Vithanco
/CLAUDE.md @Vithanco
/.coderabbit.yaml @Vithanco
/.github/ @Vithanco
57 changes: 57 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# AGENTS.md

This file provides guidance to coding agents (Claude Code, Codex, Cursor, and others) when working with code in this repository.

## Build & Test

```bash
swift build # Build the library
swift test # Run tests (test target: SwiftGraphvizTests)
```

On macOS/iOS, the bundled `Graphviz.xcframework` is used automatically. On Linux, a pre-built static library is bundled as `CGraphviz.artifactbundle` (SE-0482, requires Swift 6.2+).

To rebuild the Linux artifact bundle (run inside a Linux container):
```bash
./build_linux_static.sh # clones graphviz source
GRAPHVIZ_SRC=/path/to/graphviz ./build_linux_static.sh # use local copy
```

To rebuild the macOS/iOS xcframework:
```bash
./build_xcframework.sh
```

WebAssembly (`wasm32-unknown-wasip1`) is supported — see [WASM.md](WASM.md).
The Swift layer is Foundation-free and compiles under Embedded Swift. The Graphviz C
library **compiles to wasm** via `./build_wasm_static.sh` (verified: ~2.4 MB
`CGraphvizWasm.artifactbundle`), using `wasm-toolchain.cmake` + `wasm_compat.h`
against the WASI sysroot bundled in an installed Swift wasm SDK — no separate
wasi-sdk needed. VGraph links it in-process. Select the wasm binary target with
`GRAPHVIZ_WASM=1 swift build --swift-sdk <...wasm-embedded>`.

Swift tools version: 6.0. Minimum platforms: macOS 15, iOS 18. Linux requires Swift 6.2+ (for artifact bundle support).

## Architecture

SwiftGraphviz is a Swift wrapper around the C Graphviz library for computing graph layouts. It has three layers:

**CGraphviz** — Platform-specific pre-built Graphviz static library. On Apple it's `Graphviz.xcframework` (macOS, iOS, simulator slices). On Linux it's `CGraphviz.artifactbundle` (SE-0482). Both are `.binaryTarget` in Package.swift.

**GraphvizBridge** (C) — Thin C bridge that wraps Graphviz macros as callable C functions, since Swift cannot invoke C macros directly. Two files:
- `builtins.c/h` — Plugin registration (`loadGraphvizLibraries()`) and accessor functions for node coords (`nd_coord`), edge splines (`ed_label`, `ed_lp`, etc.), and graph bounding boxes (`gd_bb`).
- `unflatten.c/h` — The `agUnflatten` algorithm exposed as a C function.

**SwiftGraphviz** (Swift) — Public API layer. Key types:
- `GVGraph`, `GVNode`, `GVEdge`, `GVCluster` — typealiases for `UnsafeMutablePointer<Ag*_t>` with Swift extensions for setting attributes and reading layout results.
- `GVGeometry` — Cross-platform geometry types (`GVPoint`, `GVSize`, `GVRect`, `GVVector`) replacing CoreGraphics. `GVGeometry+Apple.swift` adds `cgPoint`/`cgSize`/`cgRect`/`cgVector` bridging via `#if canImport(CoreGraphics)`.
- `NodeLayout`, `EdgeLayout`, `ClusterLayout` — Value types that snapshot layout results from the Graphviz pointers.
- `GVParameters` — Enums for Graphviz attributes (`GVNodeParameters`, `GVEdgeParameters`, `GVGraphParameters`), unit types (`GVPoints`, `GVInches`), and style/direction enums.
- `GraphvizWrapper` — Global context (`gblGVContext`), `GVLayoutEngine` enum, `GVGlobalContextPointer` typealias.

## Key Patterns

- **Static plugin registration**: Graphviz plugins (dot, neato, core) are registered statically via `gvNEWcontext` + `gvAddLibrary` on all platforms. No dynamic plugin discovery.
- **Graphviz attributes**: Set defaults on the graph first (`g.setDefault(.node(.label))`), then set values on individual elements (`node.set(.width, "1.5")`). All attributes are string-based.
- **Units**: Graphviz uses 72 points per inch. Node dimensions come back in inches from the C layer; `GVInches`/`GVPoints` types handle conversion.
- **`staging/` directory**: Contains files moved out of the main source but kept for reference. Prefer moving unused files here rather than deleting them.
58 changes: 1 addition & 57 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,57 +1 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Build & Test

```bash
swift build # Build the library
swift test # Run tests (test target: SwiftGraphvizTests)
```

On macOS/iOS, the bundled `Graphviz.xcframework` is used automatically. On Linux, a pre-built static library is bundled as `CGraphviz.artifactbundle` (SE-0482, requires Swift 6.2+).

To rebuild the Linux artifact bundle (run inside a Linux container):
```bash
./build_linux_static.sh # clones graphviz source
GRAPHVIZ_SRC=/path/to/graphviz ./build_linux_static.sh # use local copy
```

To rebuild the macOS/iOS xcframework:
```bash
./build_xcframework.sh
```

WebAssembly (`wasm32-unknown-wasip1`) is supported — see [WASM.md](WASM.md).
The Swift layer is Foundation-free and compiles under Embedded Swift. The Graphviz C
library **compiles to wasm** via `./build_wasm_static.sh` (verified: ~2.4 MB
`CGraphvizWasm.artifactbundle`), using `wasm-toolchain.cmake` + `wasm_compat.h`
against the WASI sysroot bundled in an installed Swift wasm SDK — no separate
wasi-sdk needed. VGraph links it in-process. Select the wasm binary target with
`GRAPHVIZ_WASM=1 swift build --swift-sdk <...wasm-embedded>`.

Swift tools version: 6.0. Minimum platforms: macOS 15, iOS 18. Linux requires Swift 6.2+ (for artifact bundle support).

## Architecture

SwiftGraphviz is a Swift wrapper around the C Graphviz library for computing graph layouts. It has three layers:

**CGraphviz** — Platform-specific pre-built Graphviz static library. On Apple it's `Graphviz.xcframework` (macOS, iOS, simulator slices). On Linux it's `CGraphviz.artifactbundle` (SE-0482). Both are `.binaryTarget` in Package.swift.

**GraphvizBridge** (C) — Thin C bridge that wraps Graphviz macros as callable C functions, since Swift cannot invoke C macros directly. Two files:
- `builtins.c/h` — Plugin registration (`loadGraphvizLibraries()`) and accessor functions for node coords (`nd_coord`), edge splines (`ed_label`, `ed_lp`, etc.), and graph bounding boxes (`gd_bb`).
- `unflatten.c/h` — The `agUnflatten` algorithm exposed as a C function.

**SwiftGraphviz** (Swift) — Public API layer. Key types:
- `GVGraph`, `GVNode`, `GVEdge`, `GVCluster` — typealiases for `UnsafeMutablePointer<Ag*_t>` with Swift extensions for setting attributes and reading layout results.
- `GVGeometry` — Cross-platform geometry types (`GVPoint`, `GVSize`, `GVRect`, `GVVector`) replacing CoreGraphics. `GVGeometry+Apple.swift` adds `cgPoint`/`cgSize`/`cgRect`/`cgVector` bridging via `#if canImport(CoreGraphics)`.
- `NodeLayout`, `EdgeLayout`, `ClusterLayout` — Value types that snapshot layout results from the Graphviz pointers.
- `GVParameters` — Enums for Graphviz attributes (`GVNodeParameters`, `GVEdgeParameters`, `GVGraphParameters`), unit types (`GVPoints`, `GVInches`), and style/direction enums.
- `GraphvizWrapper` — Global context (`gblGVContext`), `GVLayoutEngine` enum, `GVGlobalContextPointer` typealias.

## Key Patterns

- **Static plugin registration**: Graphviz plugins (dot, neato, core) are registered statically via `gvNEWcontext` + `gvAddLibrary` on all platforms. No dynamic plugin discovery.
- **Graphviz attributes**: Set defaults on the graph first (`g.setDefault(.node(.label))`), then set values on individual elements (`node.set(.width, "1.5")`). All attributes are string-based.
- **Units**: Graphviz uses 72 points per inch. Node dimensions come back in inches from the C layer; `GVInches`/`GVPoints` types handle conversion.
- **`staging/` directory**: Contains files moved out of the main source but kept for reference. Prefer moving unused files here rather than deleting them.
@AGENTS.md
2 changes: 1 addition & 1 deletion scripts/hygiene.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ done <<< "$patterns"
# 14
printf '%s\n' "$patterns" > "$TMP/.git/info/exclude"; bad=0
for path in Package.swift build_xcframework.sh build_linux_static.sh build_wasm_static.sh Containerfile.build \
Graphviz.xcframework/x CGraphviz.artifactbundle/x CGraphvizWasm.artifactbundle/x CLAUDE.md .coderabbit.yaml .github/CODEOWNERS scripts/x.sh; do
Graphviz.xcframework/x CGraphviz.artifactbundle/x CGraphvizWasm.artifactbundle/x AGENTS.md CLAUDE.md .coderabbit.yaml .github/CODEOWNERS scripts/x.sh; do
echo "$path" | git -C "$TMP" check-ignore --no-index -q --stdin || { fail "not covered by CODEOWNERS: $path"; bad=1; }
done
[ $bad -eq 0 ] && pass 'Given CODEOWNERS, when its patterns are read, then it covers the manifest, scripts, binaries, agent config and .github/'
Expand Down
Loading