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
28 changes: 11 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup mise
uses: jdx/mise-action@v2
with:
toolchain: stable
cache: true

- uses: jetli/wasm-pack-action@v0.4.0

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install toolchains
run: mise install

- name: Install dependencies
run: pnpm install --frozen-lockfile
run: mise exec -- pnpm install --frozen-lockfile

- name: Type Check
run: mise run check

- name: Build
run: pnpm run build
- name: Build Layout Engine (FFI)
run: mise run build:ffi
48 changes: 13 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,28 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup mise
uses: jdx/mise-action@v2
with:
toolchain: stable
cache: true

- uses: jetli/wasm-pack-action@v0.4.0

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install toolchains
run: mise install

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build Layout Engine (WASM)
run: pnpm run build
run: mise exec -- pnpm install --frozen-lockfile

- name: Check Formatting
run: pnpm run format --check
run: mise run format -- --check .

- name: Lint
run: pnpm run lint
run: mise run lint -- .

- name: Type Check
run: pnpm run check
run: mise run check

- name: Build Layout Engine (FFI)
run: mise run build:ffi

- name: Run Tests
run: pnpm run test
run: mise run test
40 changes: 9 additions & 31 deletions .github/workflows/profiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,23 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup mise
uses: jdx/mise-action@v2
with:
toolchain: stable
cache: true

- uses: jetli/wasm-pack-action@v0.4.0

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install toolchains
run: mise install

- name: Install dependencies
run: pnpm install --frozen-lockfile
run: mise exec -- pnpm install --frozen-lockfile

- name: Build Layout Engine (WASM)
run: pnpm run build
- name: Build Layout Engine (FFI)
run: mise run build:ffi

- name: Run Limit Test
run: |
pnpm run profiler:limit | tee benchmark_result.txt
mise run profiler:limit | tee benchmark_result.txt

- name: Extract Report
id: extract_report
Expand Down
67 changes: 28 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,78 +32,67 @@ Bunのパフォーマンスを最大限に活かし、快適な開発体験を

## クイックスタート

> **前提**: Bun(`bun` コマンド)がインストール済みであること
> **前提**: `mise` がインストール済みであること(このリポジトリは `mise.toml` でツールを管理します)

### セットアップ

```bash
pnpm install
```

### テスト
mise install
mise exec -- pnpm install --frozen-lockfile

```bash
pnpm test
# Layout Engine (FFI) をビルド(初回/更新時)
mise run build:ffi
```

### すぐ動くサンプル(showcase)
### テスト

```bash
# 矢印キーでカウント / q で終了
bun packages/showcase/counter.ts

# ダッシュボード(↑/↓でページ移動 / space で一時停止 / q で終了)
bun packages/showcase/dashboard.ts
mise run test
```

### Profiling / Perf Regression

```bash
# 大量要素のストレス(JSON出力、--io=off で stdout を捨てて純粋な計算寄りに)
bun run profile:stress --n=10000 --frames=120 --io=off --out=profiles/stress.json

# パフォーマンス予算テスト(将来的にCIで回帰検知に使う想定)
# 例: まずは計測してから budget を詰めるのがおすすめ
bun run perf:budget --task=frame --n=10000 --iterations=30 --out=profiles/budget.json
bun run perf:budget --task=diff --rows=200 --cols=400 --iterations=20 --out=profiles/budget-diff.json
# 大量要素のストレス
mise run profiler:stress -- --n=10000 --frames=120 --io=off --out=profiles/stress.json

# bun test に載せる場合(CI or BTUIN_PERF=1 のときのみ実行)
CI=1 bun run test:perf
# 予算/サイズは env で上書き可能(例: BTUIN_BUDGET_FRAME_P95=120 など)
# パフォーマンス上限テスト
mise run profiler:limit
```

## 使い方(最小例)
## 使い方

```ts
import { createApp, VStack, Text, ref, onKey } from "btuin";
import { createApp, VStack, Text, ref } from "btuin";

const app = createApp({
setup() {
init({ onKey, runtime }) {
const count = ref(0);
onKey((k) => {
if (k.name === "up") count.value++;
if (k.name === "down") count.value--;
if (k.name === "q") process.exit(0);
if (k.name === "q") runtime.exit(0);
});

return () =>
VStack([Text("Counter"), Text(String(count.value))])
.width("100%")
.height("100%")
.justify("center")
.align("center");
return { count };
},
render({ count }) {
return VStack([Text("Counter"), Text(String(count.value))])
.width("100%")
.height("100%")
.justify("center")
.align("center");
},
});

await app.mount();
```

## 設計メモ(ざっくり)
## 責務

- `@btuin/reactivity`: `ref/computed/effect/watch` による状態管理
- `@btuin/layout-engine`: Flexbox ライクなレイアウト(WASM
- `@btuin/renderer`: バッファ描画 + 差分レンダリング(`renderDiff` は文字列を返す純粋関数)
- `@btuin/terminal`: raw mode / 入力 / stdout 書き込み
- `reactivity`: `ref/computed/effect/watch` による状態管理
- `layout-engine`: Flexbox ライクなレイアウト(Rust FFI
- `renderer`: バッファ描画 + 差分レンダリング(`renderDiff` は文字列を返す純粋関数)
- `terminal`: raw mode / 入力 / stdout 書き込み
- `btuin`: それらを束ねる “アプリ実行” と View API

## アダプタ(テスト/差し替え用)
Expand Down
64 changes: 64 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
root = "tests"
18 changes: 18 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tools]
bun="1.3.5"
pnpm="10.26.0"
rust="stable"

[tasks]
"start"="bun run"
"build:ffi" = "cd src/layout-engine && cargo build --release"
"lint"="pnpm exec oxlint"
"lint:fix"="pnpm exec oxlint --fix"
"format"="pnpm exec oxfmt"
"check"="bunx tsc --noEmit"
"test"="bun test"
"test:watch"="bun test --watch"
"profiler"="bun test ./scripts/profiler*.spec.ts"
"profiler:stress"="bun test ./scripts/profiler-stress.spec.ts"
"profiler:layout"="bun test ./scripts/profiler-layout.spec.ts"
"profiler:limit"="bun test ./scripts/profiler-limit.spec.ts"
18 changes: 2 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
{
"name": "btuin-monorepo",
"version": "0.1.0",
"private": true,
"type": "module",
"workspaces": [
"packages/*"
],
"scripts": {
"start": "bun run",
"build": "pnpm --filter @btuin/layout-engine build",
"lint": "oxlint packages/*",
"lint:fix": "oxlint packages/* --fix",
"format": "oxfmt packages/*",
"test": "bun test packages/btuin packages/layout-engine packages/reactivity packages/renderer packages/terminal packages/showcase",
"test:watch": "pnpm test --watch",
"test:all": "bun test packages",
"profiler": "bun test scripts/profiler*.spec.ts",
"profiler:stress": "bun test scripts/profiler-stress.test.ts",
"profiler:layout": "bun test scripts/profiler-layout.test.ts",
"profiler:limit": "bun test scripts/profiler-limit.spec.ts",
"check": "bunx tsc --noEmit"
},
"devDependencies": {
"@types/bun": "latest",
"oxfmt": "^0.17.0",
Expand All @@ -29,7 +15,7 @@
"typescript": "^5"
},
"engines": {
"bun": "latest"
"bun": "^1.3.4"
},
"packageManager": "pnpm@10.25.0"
}
Loading