ビルド手順書 / Build Instructions
このドキュメントは、ym2151-log-player-rust のビルド方法を説明します。
This document explains how to build ym2151-log-player-rust.
目次 / Table of Contents
- 必要な環境 / Requirements
- Linux でのビルド / Building on Linux
- Linux から Windows へのクロスコンパイル / Cross-compiling to Windows from Linux
- Windows でのネイティブビルド / Native Build on Windows
- リリースビルドの最適化 / Release Build Optimization
- トラブルシューティング / Troubleshooting
必要な環境 / Requirements
共通要件 / Common Requirements
- Rust: 1.70 以降 / 1.70 or later
- インストール / Installation: https://rustup.rs/
- Cコンパイラ: zig cc(推奨) / C Compiler: zig cc (recommended)
- mingw, msys2, MSVC は使用しないでください / Do NOT use mingw, msys2, or MSVC
プラットフォーム別要件 / Platform-specific Requirements
Linux
- gcc または zig cc
- ALSA開発ライブラリ(リアルタイム音声再生を有効にする場合)
# Ubuntu/Debian
sudo apt-get install libasound2-dev
# Fedora
sudo dnf install alsa-lib-devel
Windows
- zig cc(必須) / zig cc (required)
- Rustツールチェーン / Rust toolchain
Linux でのビルド / Building on Linux
1. 基本ビルド / Basic Build
# リポジトリをクローン / Clone the repository
git clone https://github.com/cat2151/ym2151-log-player-rust.git
cd ym2151-log-player-rust
# デバッグビルド / Debug build
cargo build
# リリースビルド / Release build
cargo build --release
# 実行 / Run
./target/release/ym2151-log-player-rust sample_events.json
2. リアルタイム音声再生を有効化 / Enable Real-time Audio
# リアルタイム音声機能付きビルド / Build with real-time audio
cargo build --release --features realtime-audio
# 実行 / Run
./target/release/ym2151-log-player-rust sample_events.json
注意 / Note: Linux環境では、ALSA開発ライブラリが必要です。 In Linux environment, ALSA development libraries are required.
3. テストの実行 / Running Tests
# 基本テスト / Basic tests
cargo test
# リアルタイム音声機能を含むテスト / Tests with real-time audio
cargo test --features realtime-audio
# 詳細出力付きテスト / Tests with verbose output
cargo test -- --nocapture
Linux から Windows へのクロスコンパイル / Cross-compiling to Windows from Linux
前提条件 / Prerequisites
- zig のインストール / Install zig
# zig をダウンロード / Download zig
# https://ziglang.org/download/ から適切なバージョンを選択
# Choose appropriate version from https://ziglang.org/download/
# 推奨: 0.13.0 以降、最小要件: 0.11.0 以降
# Recommended: 0.13.0 or later, Minimum: 0.11.0 or later
# 例(Linux x86_64の場合) / Example (for Linux x86_64)
wget https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz
tar -xf zig-linux-x86_64-0.13.0.tar.xz
# PATHに追加 / Add to PATH
export PATH=$PATH:$PWD/zig-linux-x86_64-0.13.0
- Windows ターゲットの追加 / Add Windows target
rustup target add x86_64-pc-windows-gnu
ビルド手順 / Build Steps
# 環境変数を設定 / Set environment variables
export CC="zig cc -target x86_64-windows"
export AR="zig ar"
# ビルド実行 / Execute build
cargo build --release --target x86_64-pc-windows-gnu
# 生成された実行ファイル / Generated executable
# target/x86_64-pc-windows-gnu/release/ym2151-log-player-rust.exe
リアルタイム音声機能付きクロスコンパイル / Cross-compile with Real-time Audio
export CC="zig cc -target x86_64-windows"
export AR="zig ar"
cargo build --release --target x86_64-pc-windows-gnu --features realtime-audio
ワンライナースクリプト / One-liner Script
CC="zig cc -target x86_64-windows" AR="zig ar" cargo build --release --target x86_64-pc-windows-gnu
Windows でのネイティブビルド / Native Build on Windows
前提条件 / Prerequisites
- Rust のインストール / Install Rust
- https://rustup.rs/ からインストーラーをダウンロード
- Download installer from https://rustup.rs/
- zig のインストール / Install zig
- https://ziglang.org/download/ から Windows版をダウンロード
- Download Windows version from https://ziglang.org/download/
- 展開したディレクトリをPATHに追加 / Add extracted directory to PATH
ビルド手順(PowerShell) / Build Steps (PowerShell)
# リポジトリをクローン / Clone repository
git clone https://github.com/cat2151/ym2151-log-player-rust.git
cd ym2151-log-player-rust
# 環境変数を設定 / Set environment variables
$env:CC = "zig cc"
$env:AR = "zig ar"
# リリースビルド / Release build
cargo build --release
# 実行 / Run
.\target\release\ym2151-log-player-rust.exe sample_events.json
ビルド手順(コマンドプロンプト) / Build Steps (Command Prompt)
REM リポジトリをクローン / Clone repository
git clone https://github.com/cat2151/ym2151-log-player-rust.git
cd ym2151-log-player-rust
REM 環境変数を設定 / Set environment variables
set CC=zig cc
set AR=zig ar
REM リリースビルド / Release build
cargo build --release
REM 実行 / Run
.\target\release\ym2151-log-player-rust.exe sample_events.json
リアルタイム音声機能付きビルド / Build with Real-time Audio
# PowerShell
$env:CC = "zig cc"
$env:AR = "zig ar"
cargo build --release --features realtime-audio
REM Command Prompt
set CC=zig cc
set AR=zig ar
cargo build --release --features realtime-audio
リリースビルドの最適化 / Release Build Optimization
バイナリサイズの削減 / Reducing Binary Size
オプション設定 / Optional Configuration
デフォルトのビルド設定で十分ですが、さらにバイナリサイズを削減したい場合は、Cargo.toml に以下の設定を追加できます:
The default build configuration is sufficient, but if you want to further reduce binary size, you can add the following configuration to Cargo.toml:
[profile.release]
opt-level = "z" # サイズ最適化 / Optimize for size
lto = true # Link Time Optimization
codegen-units = 1 # 並列化を無効化(より良い最適化) / Disable parallelization (better optimization)
strip = true # シンボル情報を削除 / Remove debug symbols
panic = "abort" # パニック時にアンワインドしない / Don't unwind on panic
注意 / Note: これらの設定はコンパイル時間を増加させますが、実行ファイルサイズを大幅に削減します。 These settings increase compilation time but significantly reduce executable size.
参考 / Reference: デフォルト設定でのバイナリサイズは約 767KB です。strip を有効化すると約 598KB に削減されます。 With default settings, binary size is approximately 767KB. Enabling strip reduces it to approximately 598KB.
追加の最適化オプション / Additional Optimization Options
より積極的なサイズ削減を行いたい場合: For more aggressive size reduction:
# upx を使用した圧縮(オプション) / Compression using upx (optional)
# https://upx.github.io/
cargo build --release
upx --best --lzma target/release/ym2151-log-player-rust
トラブルシューティング / Troubleshooting
問題: ALSA エラー(Linux) / Issue: ALSA errors (Linux)
エラーメッセージ / Error message:
error: failed to run custom build command for `alsa-sys v0.x.x`
解決方法 / Solution:
# Ubuntu/Debian
sudo apt-get install libasound2-dev pkg-config
# Fedora
sudo dnf install alsa-lib-devel
問題: zig cc が見つからない / Issue: zig cc not found
エラーメッセージ / Error message:
error: linker `zig cc` not found
解決方法 / Solution:
- zig が正しくインストールされているか確認
Verify zig is properly installed:
zig version - PATH が正しく設定されているか確認
Verify PATH is correctly set:
echo $PATH # Linux/macOS echo %PATH% # Windows CMD $env:Path # Windows PowerShell - 環境変数を再設定
Reset environment variables:
export CC="zig cc" export AR="zig ar"
問題: Windows クロスコンパイルの失敗 / Issue: Windows cross-compilation failure
エラーメッセージ / Error message:
error: linking with `zig cc` failed
確認事項 / Check:
-
zig のバージョンが 0.11.0 以降であること(0.13.0 以降を推奨) zig version is 0.11.0 or later (0.13.0 or later recommended)
- Windows ターゲットが追加されているか確認
Verify Windows target is added:
rustup target list --installed | grep windows - 環境変数が正しく設定されているか確認
Verify environment variables are set correctly:
echo $CC echo $AR
問題: opm.c のコンパイル警告 / Issue: opm.c compilation warnings
警告メッセージ / Warning message:
warning: unused variable 'channel'
説明 / Explanation: これらは Nuked-OPM ライブラリ由来の警告で、プログラムの動作には影響しません。無視して構いません。
These warnings come from the Nuked-OPM library and do not affect program behavior. They can be safely ignored.
問題: リアルタイム音声が動作しない / Issue: Real-time audio not working
確認事項 / Check:
- realtime-audio 機能が有効になっているか
Verify realtime-audio feature is enabled:
cargo build --features realtime-audio -
音声出力デバイスが利用可能か確認 Verify audio output device is available
- Linux の場合、ALSA ライブラリがインストールされているか確認 On Linux, verify ALSA libraries are installed
ビルド成果物 / Build Artifacts
通常のビルド / Standard Build
- デバッグビルド / Debug build:
target/debug/ym2151-log-player-rust[.exe] - リリースビルド / Release build:
target/release/ym2151-log-player-rust[.exe]
クロスコンパイル / Cross-compilation
- Windows向け / For Windows:
target/x86_64-pc-windows-gnu/release/ym2151-log-player-rust.exe
参考情報 / References
- IMPLEMENTATION_PLAN.md - 実装計画書 / Implementation plan
- README.md - プロジェクト概要 / Project overview
- Rust公式サイト
- zig公式サイト
- Nuked-OPM
- 元のC実装 / Original C implementation
ライセンス / License
このプロジェクトは MIT ライセンスの下で公開されています。 This project is released under the MIT License.