DenoとdaxでCpp_CMakeプロジェクトの開発を支援する話_CppMIX17

708 Views

March 13, 26

スライド概要

Docswellを使いましょう

(ダウンロード不可)

関連スライド

各ページのテキスト
1.

Deno と dax で C++/CMake プロジェクトの 開発を支援する話 COx2 (Tatsuya Shiozawa) C++ MIX #17

2.

発表者の紹介 氏名: 塩澤 達矢 • 株式会社COCOTONE 代表取締役 • JUCE enthusiast • JUCEとC++で生活するCEO • JUCEのコミュニティ活動から発展して オーディオプログラミングを事業として行っている

3.

発表者の紹介 所属: 株式会社COCOTONE • Web: https://www.cocotone.jp/ • 読みは「ココトーン」 • 提供サービス • • オーディオプラグイン開発受託 • オーディオアプリ開発受託 • 音楽・映像分野に関するソフトウェア開発のコンサルティング • JUCE導入サポート cpprefjpゴールドスポンサー3年目

4.

本資料について ■ ベースとなる記事 本資料は Qiita 記事「DenoとdaxでC++/CMakeプロジェクトの開発を支援する話」をベースとしてプレゼン テーション資料化したものです。 URL: https://qiita.com/COx2/items/6fdf6ddaa81c54bbcdf9 ■ C++ 解説について 本 LT では C++ 開発の補助ツールについて取り上げることから、C++ 自体の解説は少ない点をご了承くだ さい。

5.

Quick Start 3ステップで C++/CMake プロジェクトを始める Step 1: Deno をインストール curl -fsSL https://deno.land/install.sh | sh macOS / Linux irm https://deno.land/install.ps1 | iex Windows (PowerShell) Step 2: プロジェクトを生成 $ deno run --allow-read --allow-write --allow-run https://raw.githubusercontent.com/COx2/deno-advent-calender-2025/main/generator/generate.ts --name "MyProject" --author "Your Name" --with-git Step 3: ビルド & 実行 $ cd myproject $ deno task build $ deno task test cox2.github.io/deno-advent-calender-2025/ja/index.html cox2.github.io/deno-advent-calender-2025/ja/index.html

6.

モチベーション:C++ クロスプラットフォーム開発の課題 CMake でビルド設定を抽象化しても、前後の処理に課題が残る 1. シェルスクリプトはシェル依存 macOS は zsh、Windows は PowerShell — シェルスクリプトを書き分ける必要がある 2. 補助ツールをシステム環境にインストール Python / Node.js / Ruby など、追加のインストールが必要 3. コンテキストスイッチ スクリプト言語とアプリ開発言語の特性差による認知負荷 → Deno + dax で解決する

7.

技術スタック:Deno + dax + CMake File API Deno • シングルバイナリで完結 • TypeScript ネイティブ実行 • 権限ベースのセキュリティ dax → • TS で書くシェルスクリプト • rm, cp 等をクロス実行 • OS コマンドも呼び出し可能 CMake File API → • ビルド情報を JSON で提供 • 成果物パスの動的解決 • ハードコーディング不要

8.

Deno とは Node.js 作者 Ryan Dahl が設計した次世代 TypeScript ランタイム ユーザーランドで完結 URL から直接 TypeScript 実行 システム管理者権限不要。シングルバイナリ (~100 MB) を ホームディレクトリにインストールするだけで即利用可能 deno run https://... で GitHub 上のスクリプトを インストールなしに即座に実行 TypeScript ネイティブ セキュリティファースト 組み込みツールチェイン 設定不要で .ts を直接実行 明示的な権限フラグで安全に実行 lint / fmt / test / bundle 内蔵 Web 標準 API npm 互換 (Deno 2) クロスコンパイル fetch, WebSocket 等ブラウザ互換 npm パッケージをそのまま利用 deno compile でバイナリ生成 deno.com deno.com

9.

Deno の使い方(1)URL インポート ライブラリの URL を書くだけで依存を解決 ライブラリの URL インポート // npm: プレフィックスで npm パッケージをインポート import { Hono } from "npm:hono" // jsr: プレフィックスで JSR レジストリからインポート import $ from "jsr:@david/dax" // https: URL から直接インポート import { z } from "https://deno.land/x/zod/mod.ts" 権限ベースのセキュリティ # ネットワーク + ファイル読み取りを許可して実行 $ deno run --allow-net --allow-read server.ts # 全権限を許可(開発時) $ deno run --allow-all app.ts docs.deno.com docs.deno.com

10.
[beta]
Deno の使い方(2)URL 実行 & タスク
配布側も利用側もゼロインストール

スクリプトの URL 実行
# GitHub 上の TypeScript を直接実行 — ローカルのインストール一切不要
$ deno run --allow-all
https://raw.githubusercontent.com/COx2/deno-advent-calender-2025/main/generator/generate.ts
--name "MyProject" --author "Your Name" --with-git

deno.json でタスク定義
// deno.json — npm scripts のように使える
{
"tasks": {
"build": "deno run -A build.ts",
"test": "deno run -A test.ts",
"clean": "deno run -A clean.ts"
}
}

docs.deno.com

docs.deno.com

11.
[beta]
dax とは
TypeScript で書けるクロスプラットフォームシェルツール — zx にインスパイア

クロスプラットフォームシェル
Windows でも macOS / Linux でも同じコマンドが動作

組み込みコマンド

使用例
import $ from "@david/dax"
// コマンド実行
await $`echo hello`

cp, mv, rm, mkdir, sleep 等を
OS 問わず実行

// stdout をテキストで取得
const out = await $`echo hi`.text()
console.log(out);

テンプレートリテラル構文

// クロスプラットフォーム
await $`rm -rf build`
await $`cp –r src dest`

await $`echo ${variable}` で
変数展開も型安全

豊富なユーティリティ
$.confirm, $.prompt, Path API,
HTTP リクエストなど

github.com/dsherret/dax

github.com/dsherret/dax

12.

dax:TypeScript で書くシェルスクリプト クリーン処理 async function clean() { await $`rm -rf build dist`; } CMake コマンド呼び出し await $`cmake -B build - DCMAKE_BUILD_TYPE=${config} プラットフォーム分岐 if (Deno.build.os === "windows") { await $`cmake --build build --config ${config}`; } else { await $`cmake --build build --config ${config} --parallel`; } TypeScript の変数を展開してコマンドに渡せる + OS 判定で分岐 -G ${generator}`;

13.

CMake File API の活用 CMake 3.14+ のビルド情報を TypeScript で型安全にパース 1 2 3 4 クエリ作成 CMake 実行 パース 成果物取得 .cmake/api/v1/ query/ に配置 cmake -B build JSON を生成 TypeScript で 型安全に読み込み ファイルパスを 動的に解決 従来(ハードコーディング) // Windows と macOS で分岐... const execPath = "build/bin/Release/myapp.exe"; const libPath = "build/lib/Release/myapp.dll"; cmake.org/cmake/help/latest/manual/cmake-file-api.7.html cmake.org/cmake/help/latest/manual/cmake-file-api.7.html File API(動的解決) const artifacts = await parseFileAPI("build"); const exec = artifacts.find( a => a.type === "EXECUTABLE");

14.

応用例:Deno C++ Project Generator URL 一行で C++/CMake プロジェクトを生成 インストール不要 — Deno さえあれば URL から直接実行 すぐ使えるテンプレート — CMake + ビルドスクリプト + ソースを一括生成 型安全なビルドシステム — TypeScript による自動化 クロスプラットフォーム — Windows / macOS / Linux 対応 $ deno run --allow-read --allow-write --allow-run https://raw.githubusercontent.com/COx2/deno-advent-calender-2025/main/generator/generate.ts --name "MyProject" --author "Your Name" --with-git cox2.github.io/deno-advent-calender-2025/ja/index.html cox2.github.io/deno-advent-calender-2025/ja/index.html

15.

応用例:実行フローとコマンド $ deno task build # リリースビルド $ deno task build:debug # デバッグビルド $ deno task test # ビルド + 実行テスト $ deno task clean # クリーン deno task test 実行時の内部フロー CMake 設定 Building MyApp v1.0.0 → ビルド 実行 Configuring → File API パース Building → 成果物 検出 Artifacts → Done! テスト 実行

16.

応用例:Deno JUCE Project Generator URL 一行で JUCE オーディオプラグインプロジェクトを生成 対応プラグインフォーマット VST3 Win / macOS / Linux AU macOS のみ Standalone プロジェクト生成 $ deno run --allow-all https://raw.githubusercontent.com/cocotone/deno-juce-project-generator/main/generator/generate.ts --name "MyAudioPlugin" --author "Your Name" --with-git ビルドタスク deno task build Release ビルド deno task run Standalone 実行 deno task run:debug Debug で実行 cocotone.github.io/deno-juce-project-generator/ja/index.html cocotone.github.io/deno-juce-project-generator/ja/index.html 全プラットフォーム

17.

まとめ:Deno + dax + CMake のメリット クロスプラットフォーム CMake 統合 Windows / macOS / Linux で同じスクリプトが動作 File API によるビルド情報の自動取得 型安全性 開発者体験の向上 TypeScript による設定管理とエラー検出 Deno Task によるコマンド簡略化と自己文書化 環境構築の簡略化 コラボレーション改善 Deno シングルバイナリで依存関係を最小化 JS/TS の高い普及率

18.

ありがとうございました qiita.com/COx2/items/6fdf6ddaa81c54bbcdf9 Qiita 記事 qiita.com/COx2/items/6fdf6ddaa81c54bbcdf9 cox2.github.io/deno-advent-calender-2025/ja/index.html Deno C++ Project Generator cox2.github.io/deno-advent-calender-2025/ja/index.html cocotone.github.io/deno-juce-project-generator/ja/index.html Deno JUCE Project Generator cocotone.github.io/deno-juce-project-generator/ja/index.html 参考リンク deno.com COx2 (Tatsuya Shiozawa) | C++ MIX #17 / github.com/dsherret/dax / cmake.org