diff --git a/CalcPi.jl/README.md b/CalcPi.jl/README.md index c842641..9484c39 100644 --- a/CalcPi.jl/README.md +++ b/CalcPi.jl/README.md @@ -1,80 +1,80 @@ # CalcPi.jl -JuliaからRustで実装されたMonte Carlo法によるπ計算ライブラリ(`calcpi-rs`)を呼び出すためのJuliaパッケージです。 +A Julia package for calling a Rust-implemented Monte Carlo π calculation library (`calcpi-rs`) from Julia. -## 概要 +## Overview -`CalcPi.jl`は、`calcpi-rs`ライブラリへのJuliaバインディングを提供します。Monte Carlo法を使用してπの値を計算できます。 +`CalcPi.jl` provides Julia bindings to the `calcpi-rs` library. You can calculate the value of π using the Monte Carlo method. -## インストール +## Installation ```julia using Pkg Pkg.add(url="path/to/CalcPi.jl") ``` -または、開発モードでインストール: +Or install in development mode: ```julia using Pkg Pkg.develop(path="path/to/CalcPi.jl") ``` -## ビルド +## Building -パッケージをビルドすると、Rustライブラリが自動的にコンパイルされ、C APIバインディングが生成されます: +Building the package will automatically compile the Rust library and generate C API bindings: ```julia using Pkg Pkg.build("CalcPi") ``` -## 使い方 +## Usage ```julia using CalcPi -# MonteCarloPiインスタンスを作成 +# Create a MonteCarloPi instance calc = CalcPi.MonteCarloPi() -# 100万サンプルでπを計算 +# Calculate π with 1 million samples result = CalcPi.calculate(calc, UInt64(1_000_000)) println("π ≈ $result") -# リソースを解放 +# Release resources CalcPi.release(calc) ``` -## プロジェクト構造 +## Project Structure ``` CalcPi.jl/ ├── deps/ -│ ├── build.jl # ビルドスクリプト -│ └── libcalcpi_rs.* # ビルドされたライブラリ(自動生成) +│ ├── build.jl # Build script +│ └── libcalcpi_rs.* # Built library (auto-generated) ├── src/ -│ ├── CalcPi.jl # 高レベルAPI -│ └── C_API.jl # C APIバインディング(自動生成) -├── test/ # テストファイル -└── utils/ # C API生成ユーティリティ +│ ├── CalcPi.jl # High-level API +│ └── C_API.jl # C API bindings (auto-generated) +├── test/ # Test files +└── utils/ # C API generation utilities ``` -## 開発 +## Development -開発ガイドについては`DEVELOPMENT.md`を参照してください。 +For development guide, see `DEVELOPMENT.md`. -## テスト +## Testing ```julia using Pkg Pkg.test("CalcPi") ``` -## 依存関係 +## Dependencies -- `CEnum.jl` - C enumのサポート -- `RustToolChain.jl` - Rust toolchainの管理(ビルド時のみ) +- `CEnum.jl` - C enum support +- `RustToolChain.jl` - Rust toolchain management (build-time only) -## ライセンス +## License -このプロジェクトのライセンス情報については、ルートディレクトリのREADMEを参照してください。 +For license information about this project, please refer to the README in the root directory. diff --git a/CalcPi.jl/src/CalcPi.jl b/CalcPi.jl/src/CalcPi.jl index bced0ea..84b074f 100644 --- a/CalcPi.jl/src/CalcPi.jl +++ b/CalcPi.jl/src/CalcPi.jl @@ -16,7 +16,7 @@ export calcpi_monte_carlo_pi_reset """ MonteCarloPi -モンテカルロ法でπを計算する計算機の高レベルAPIラッパーです。 +High-level API wrapper for a calculator that computes π using the Monte Carlo method. """ mutable struct MonteCarloPi ptr::Ptr{calcpi_monte_carlo_pi} @@ -38,7 +38,7 @@ end """ release(calc::MonteCarloPi) -計算機のリソースを解放します。通常は自動的に呼ばれますが、明示的に呼ぶこともできます。 +Releases the calculator's resources. Usually called automatically, but can be called explicitly. """ function release(calc::MonteCarloPi) if calc.ptr != C_NULL @@ -50,7 +50,7 @@ end """ calculate(calc::MonteCarloPi, samples::UInt64) -> Float64 -指定された数のサンプルを生成してπを推定します。 +Generates the specified number of samples and estimates π. """ function calculate(calc::MonteCarloPi, samples::UInt64) if calc.ptr == C_NULL @@ -72,7 +72,7 @@ end """ estimate(calc::MonteCarloPi) -> Float64 -現在のサンプルからπの推定値を取得します。 +Gets the π estimate from the current samples. """ function estimate(calc::MonteCarloPi) if calc.ptr == C_NULL @@ -94,7 +94,7 @@ end """ total_samples(calc::MonteCarloPi) -> UInt64 -総サンプル数を取得します。 +Gets the total number of samples. """ function total_samples(calc::MonteCarloPi) if calc.ptr == C_NULL @@ -116,7 +116,7 @@ end """ inside_circle(calc::MonteCarloPi) -> UInt64 -円内の点数を取得します。 +Gets the number of points inside the circle. """ function inside_circle(calc::MonteCarloPi) if calc.ptr == C_NULL @@ -138,7 +138,7 @@ end """ reset(calc::MonteCarloPi) -統計情報をリセットします。 +Resets the statistics. """ function reset(calc::MonteCarloPi) if calc.ptr == C_NULL @@ -157,7 +157,7 @@ end """ calc_pi(samples::UInt64) -> Float64 -簡易的なπ計算関数。内部でMonteCarloPiを作成・使用・解放します。 +Simple π calculation function. Internally creates, uses, and releases a MonteCarloPi instance. """ function calc_pi(samples::UInt64) calc = MonteCarloPi() diff --git a/CalcPi.jl/utils/README.md b/CalcPi.jl/utils/README.md index cb36d33..18d5358 100644 --- a/CalcPi.jl/utils/README.md +++ b/CalcPi.jl/utils/README.md @@ -1,65 +1,63 @@ -# CalcPi.jl C-API 自動生成ツール +# CalcPi.jl C-API Auto-generation Tool -このディレクトリには、CヘッダーファイルからJuliaバインディングを自動生成するツールが含まれています。 +This directory contains tools for automatically generating Julia bindings from C header files. -## 概要 +## Overview -`SparseIR.jl/utils`の仕組みを参考に、`calcpi.h`からJuliaの`C_API.jl`を自動生成します。 +Based on the mechanism from `SparseIR.jl/utils`, this tool automatically generates Julia's `C_API.jl` from `calcpi.h`. -## ファイル構成 +## File Structure -- `generate_C_API.jl` - メインの生成スクリプト -- `generator.toml` - Clang.jlの設定ファイル -- `prologue.jl` - 生成コードのプロローグ(ライブラリロード処理) -- `Project.toml` - 依存関係(Clang.jl) +- `generate_C_API.jl` - Main generation script +- `generator.toml` - Clang.jl configuration file +- `prologue.jl` - Prologue for generated code (library loading process) +- `Project.toml` - Dependencies (Clang.jl) -## 使用方法 +## Usage -### 1. Rustライブラリのビルド +### 1. Building the Rust Library -まず、Rustライブラリをビルドしてヘッダーファイルを生成します: +First, build the Rust library to generate the header file: ```bash cd ../../calcpi-rs cargo build --release ``` -これにより、`calcpi-rs/include/calcpi.h`が生成されます。 +This generates `calcpi-rs/include/calcpi.h`. -### 2. Juliaバインディングの生成 +### 2. Generating Julia Bindings -生成スクリプトを実行します: +Run the generation script: ```bash cd CalcPi.jl/utils julia generate_C_API.jl ``` -デフォルトでは、`../../calcpi-rs`を探します。別のパスを指定する場合: +By default, it looks for `../../calcpi-rs`. To specify a different path: ```bash julia generate_C_API.jl --calcpi-rs-dir /path/to/calcpi-rs ``` -### 3. 生成されるファイル +### 3. Generated Files -`CalcPi.jl/src/C_API.jl`が生成されます。このファイルには: +`CalcPi.jl/src/C_API.jl` is generated. This file contains: -- 型定義(`calcpi_monte_carlo_pi`など) -- 定数定義(`CALCPI_SUCCESS`など) -- C関数のラッパー(`calcpi_monte_carlo_pi_new`など) +- Type definitions (e.g., `calcpi_monte_carlo_pi`) +- Constant definitions (e.g., `CALCPI_SUCCESS`) +- C function wrappers (e.g., `calcpi_monte_carlo_pi_new`) -が含まれます。 +## Generation Script Behavior -## 生成スクリプトの動作 +1. **Command-line argument parsing**: Path can be specified with `--calcpi-rs-dir` +2. **Directory validation**: Checks for the existence of `calcpi-rs/include/calcpi.h` +3. **Parsing with Clang.jl**: Parses the C header +4. **Julia code generation**: Generates `C_API.jl` +5. **Prologue insertion**: Adds the contents of `prologue.jl` at the beginning -1. **コマンドライン引数の解析**: `--calcpi-rs-dir`でパスを指定可能 -2. **ディレクトリの検証**: `calcpi-rs/include/calcpi.h`の存在確認 -3. **Clang.jlによるパース**: Cヘッダーを解析 -4. **Juliaコードの生成**: `C_API.jl`を生成 -5. **プロローグの挿入**: `prologue.jl`の内容を先頭に追加 - -## 設定のカスタマイズ +## Configuration Customization ### generator.toml @@ -75,33 +73,31 @@ extract_c_comment_style = "doxygen" ### prologue.jl -ライブラリのロード処理を定義します。ローカルビルドを優先し、なければシステムライブラリを探します。 +Defines the library loading process. It prioritizes local builds and falls back to system libraries if not found. -## トラブルシューティング +## Troubleshooting -### エラー: calcpi.h not found +### Error: calcpi.h not found -Rustライブラリをビルドしてください: +Build the Rust library: ```bash cd calcpi-rs && cargo build --release ``` -### エラー: CEnum not found - -生成された`C_API.jl`で`CEnum`が使われていない場合は、`using CEnum`の行を削除してください。 +### Error: CEnum not found -### 生成コードの修正 +If `CEnum` is not used in the generated `C_API.jl`, remove the `using CEnum` line. -生成されたコードは自動生成なので、直接編集せずに: +### Modifying Generated Code -1. Cヘッダーを修正して再生成 -2. `prologue.jl`を修正して再生成 -3. `generator.toml`の設定を変更して再生成 +Since the generated code is auto-generated, do not edit it directly. Instead: -してください。 +1. Modify the C header and regenerate +2. Modify `prologue.jl` and regenerate +3. Change the settings in `generator.toml` and regenerate -## 参考 +## References -- `SparseIR.jl/utils/generate_C_API.jl` - 参考実装 +- `SparseIR.jl/utils/generate_C_API.jl` - Reference implementation - [Clang.jl Documentation](https://github.com/JuliaInterop/Clang.jl) diff --git a/README.md b/README.md index 6a67b99..bb41ef1 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,38 @@ # RustToolChainExamples.jl -このリポジトリは、JuliaからRustコードを呼び出す方法を示すサンプルプロジェクトのコレクションです。 +This repository is a collection of sample projects demonstrating how to call Rust code from Julia. -## プロジェクト構成 +## Project Structure -### メインプロジェクト +### Main Projects -- **`calcpi-rs/`** - Rustで実装されたMonte Carlo法によるπ計算ライブラリ -- **`CalcPi.jl/`** - `calcpi-rs`をJuliaから呼び出すためのJuliaパッケージ +- **`calcpi-rs/`** - Rust library implementing π calculation using the Monte Carlo method +- **`CalcPi.jl/`** - Julia package for calling `calcpi-rs` from Julia -### サンプルプロジェクト +### Sample Projects -- **`cargo_example/`** - Cargoを使ったRustプロジェクトの例 -- **`rustc_example/`** - rustcを直接使ったRustプロジェクトの例 +- **`cargo_example/`** - Example of a Rust project using Cargo +- **`rustc_example/`** - Example of a Rust project using rustc directly -## セットアップ +## Setup -### 前提条件 +### Prerequisites -- Julia 1.6以上 +- Julia 1.10 or later - Rust toolchain (rustc, cargo) -- [RustToolChain.jl](https://github.com/AtelierArith/RustToolChain.jl) パッケージ +- [RustToolChain.jl](https://github.com/AtelierArith/RustToolChain.jl) package -### インストール +### Installation ```julia using Pkg Pkg.add("RustToolChain") ``` -## 使い方 +## Usage -各サンプルプロジェクトのREADMEを参照してください。 +Please refer to the README of each sample project. -## ライセンス +## License -このプロジェクトのライセンス情報については、各サブディレクトリのREADMEを参照してください。 +For license information about this project, please refer to the README in each subdirectory. diff --git a/calcpi-rs/README.md b/calcpi-rs/README.md index 70221eb..c2c8971 100644 --- a/calcpi-rs/README.md +++ b/calcpi-rs/README.md @@ -1,57 +1,57 @@ # calcpi-rs -Monte Carlo法を使用してπ(円周率)を計算するRustライブラリです。 +A Rust library for calculating π (pi) using the Monte Carlo method. -## 概要 +## Overview -このライブラリは、Monte Carlo法を用いてπの値を推定します。ランダムに生成した点が単位円内に含まれる確率からπを計算します。 +This library estimates the value of π using the Monte Carlo method. It calculates π from the probability that randomly generated points fall within a unit circle. -## ビルド +## Building -### 通常のビルド +### Standard Build ```bash cargo build --release ``` -### Cヘッダーファイルの生成 +### C Header File Generation -ビルド時に`cbindgen`が自動的にCヘッダーファイル(`include/calcpi.h`)を生成します。 +The C header file (`include/calcpi.h`) is automatically generated by `cbindgen` during the build process. -## 出力ファイル +## Output Files -ビルド後、以下のファイルが生成されます: +After building, the following files are generated: -- **ライブラリファイル**: +- **Library files**: - Linux: `target/release/libcalcpi_rs.so` - macOS: `target/release/libcalcpi_rs.dylib` - Windows: `target/release/calcpi_rs.dll` -- **Cヘッダーファイル**: `include/calcpi.h` +- **C header file**: `include/calcpi.h` -## ライブラリタイプ +## Library Types -このプロジェクトは以下の3つのライブラリタイプを生成します: +This project generates the following three library types: -- `cdylib` - C互換の動的ライブラリ(Juliaから呼び出すために使用) -- `staticlib` - 静的ライブラリ -- `rlib` - Rustライブラリ +- `cdylib` - C-compatible dynamic library (used for calling from Julia) +- `staticlib` - Static library +- `rlib` - Rust library -## 依存関係 +## Dependencies -- `rand = "0.8"` - 乱数生成 -- `cbindgen = "0.29"` - Cヘッダーファイル生成(ビルド時のみ) +- `rand = "0.8"` - Random number generation +- `cbindgen = "0.29"` - C header file generation (build-time only) -## Juliaパッケージとの連携 +## Integration with Julia Package -このライブラリは`CalcPi.jl`パッケージから使用されます。詳細は`../CalcPi.jl/README.md`を参照してください。 +This library is used by the `CalcPi.jl` package. For details, see `../CalcPi.jl/README.md`. -## テスト +## Testing ```bash cargo test ``` -## ライセンス +## License -このプロジェクトのライセンス情報については、ルートディレクトリのREADMEを参照してください。 +For license information about this project, please refer to the README in the root directory. diff --git a/cargo_example/README.md b/cargo_example/README.md index c015a6a..2824963 100644 --- a/cargo_example/README.md +++ b/cargo_example/README.md @@ -1,47 +1,47 @@ # cargo_example -Cargoを使用してRustプロジェクトをビルドし、Juliaから実行する例です。 +An example of building and running a Rust project using Cargo from Julia. -## 概要 +## Overview -このサンプルは、Cargoで管理されたRustプロジェクトをJuliaからビルド・実行する方法を示します。 +This sample demonstrates how to build and run a Cargo-managed Rust project from Julia. -## プロジェクト構造 +## Project Structure ``` cargo_example/ -├── Cargo.toml # Rustプロジェクトの設定 -├── Project.toml # Juliaプロジェクトの設定 -├── run.jl # 実行スクリプト +├── Cargo.toml # Rust project configuration +├── Project.toml # Julia project configuration +├── run.jl # Execution script └── src/ - └── main.rs # Rustのメインコード + └── main.rs # Rust main code ``` -## 使い方 +## Usage -### 実行 +### Running ```bash julia run.jl ``` -または、Julia REPLから: +Or from the Julia REPL: ```julia include("run.jl") ``` -## 動作の仕組み +## How It Works -1. `RustToolChain.jl`の`cargo()`関数を使用してCargoコマンドを取得 -2. `cargo build --release`でRustプロジェクトをビルド -3. ビルドされたバイナリを実行 +1. Uses the `cargo()` function from `RustToolChain.jl` to get the Cargo command +2. Builds the Rust project with `cargo build --release` +3. Executes the built binary -## 依存関係 +## Dependencies -- `RustToolChain.jl` - Rust toolchainの管理 +- `RustToolChain.jl` - Rust toolchain management -## 関連プロジェクト +## Related Projects -- `rustc_example/` - rustcを直接使用する例 -- `calcpi-rs/` - より複雑なライブラリプロジェクトの例 +- `rustc_example/` - Example using rustc directly +- `calcpi-rs/` - Example of a more complex library project diff --git a/rustc_example/README.md b/rustc_example/README.md index 4a180e3..b3af405 100644 --- a/rustc_example/README.md +++ b/rustc_example/README.md @@ -1,50 +1,50 @@ # rustc_example -rustcを直接使用してRustコードをコンパイルし、Juliaから実行する例です。 +An example of compiling Rust code using rustc directly and running it from Julia. -## 概要 +## Overview -このサンプルは、Cargoを使わずにrustcを直接使用してRustコードをコンパイル・実行する方法を示します。シンプルな単一ファイルのRustプログラムに適しています。 +This sample demonstrates how to compile and run Rust code using rustc directly without Cargo. Suitable for simple single-file Rust programs. -## プロジェクト構造 +## Project Structure ``` rustc_example/ -├── main.rs # Rustのソースコード -├── main.jl # Juliaの実行スクリプト -└── Project.toml # Juliaプロジェクトの設定 +├── main.rs # Rust source code +├── main.jl # Julia execution script +└── Project.toml # Julia project configuration ``` -## 使い方 +## Usage -### 実行 +### Running ```bash julia main.jl ``` -または、Julia REPLから: +Or from the Julia REPL: ```julia include("main.jl") ``` -## 動作の仕組み +## How It Works -1. `RustToolChain.jl`の`rustc()`関数を使用してrustcコマンドを取得 -2. `rustc main.rs`でRustコードをコンパイル(`main`という実行ファイルが生成される) -3. コンパイルされたバイナリ(`./main`)を実行 +1. Uses the `rustc()` function from `RustToolChain.jl` to get the rustc command +2. Compiles the Rust code with `rustc main.rs` (generates an executable named `main`) +3. Executes the compiled binary (`./main`) -## Cargoとの違い +## Differences from Cargo -- **rustc**: 単一ファイルのコンパイルに適している。依存関係管理なし。 -- **Cargo**: プロジェクト管理、依存関係管理、ビルドシステムを含む。 +- **rustc**: Suitable for compiling single files. No dependency management. +- **Cargo**: Includes project management, dependency management, and build system. -## 依存関係 +## Dependencies -- `RustToolChain.jl` - Rust toolchainの管理 +- `RustToolChain.jl` - Rust toolchain management -## 関連プロジェクト +## Related Projects -- `cargo_example/` - Cargoを使用する例 -- `calcpi-rs/` - より複雑なライブラリプロジェクトの例 +- `cargo_example/` - Example using Cargo +- `calcpi-rs/` - Example of a more complex library project