From 995ebe144009082c04fa35be5475790cac93e7fd Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Thu, 8 Jan 2026 16:26:53 +0900 Subject: [PATCH 1/4] Move calcpi-rs into CalcPi.jl/deps directory This reorganizes the project structure by moving the calcpi-rs Rust library into CalcPi.jl/deps/calcpi-rs, making it a dependency of the Julia package rather than a sibling directory. --- {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/.gitignore | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/Cargo.lock | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/Cargo.toml | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/README.md | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/build.rs | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/cbindgen.toml | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/include/calcpi.h | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/c_api.rs | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/lib.rs | 0 {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/main.rs | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/.gitignore (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/Cargo.lock (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/Cargo.toml (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/README.md (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/build.rs (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/cbindgen.toml (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/include/calcpi.h (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/c_api.rs (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/lib.rs (100%) rename {calcpi-rs => CalcPi.jl/deps/calcpi-rs}/src/main.rs (100%) diff --git a/calcpi-rs/.gitignore b/CalcPi.jl/deps/calcpi-rs/.gitignore similarity index 100% rename from calcpi-rs/.gitignore rename to CalcPi.jl/deps/calcpi-rs/.gitignore diff --git a/calcpi-rs/Cargo.lock b/CalcPi.jl/deps/calcpi-rs/Cargo.lock similarity index 100% rename from calcpi-rs/Cargo.lock rename to CalcPi.jl/deps/calcpi-rs/Cargo.lock diff --git a/calcpi-rs/Cargo.toml b/CalcPi.jl/deps/calcpi-rs/Cargo.toml similarity index 100% rename from calcpi-rs/Cargo.toml rename to CalcPi.jl/deps/calcpi-rs/Cargo.toml diff --git a/calcpi-rs/README.md b/CalcPi.jl/deps/calcpi-rs/README.md similarity index 100% rename from calcpi-rs/README.md rename to CalcPi.jl/deps/calcpi-rs/README.md diff --git a/calcpi-rs/build.rs b/CalcPi.jl/deps/calcpi-rs/build.rs similarity index 100% rename from calcpi-rs/build.rs rename to CalcPi.jl/deps/calcpi-rs/build.rs diff --git a/calcpi-rs/cbindgen.toml b/CalcPi.jl/deps/calcpi-rs/cbindgen.toml similarity index 100% rename from calcpi-rs/cbindgen.toml rename to CalcPi.jl/deps/calcpi-rs/cbindgen.toml diff --git a/calcpi-rs/include/calcpi.h b/CalcPi.jl/deps/calcpi-rs/include/calcpi.h similarity index 100% rename from calcpi-rs/include/calcpi.h rename to CalcPi.jl/deps/calcpi-rs/include/calcpi.h diff --git a/calcpi-rs/src/c_api.rs b/CalcPi.jl/deps/calcpi-rs/src/c_api.rs similarity index 100% rename from calcpi-rs/src/c_api.rs rename to CalcPi.jl/deps/calcpi-rs/src/c_api.rs diff --git a/calcpi-rs/src/lib.rs b/CalcPi.jl/deps/calcpi-rs/src/lib.rs similarity index 100% rename from calcpi-rs/src/lib.rs rename to CalcPi.jl/deps/calcpi-rs/src/lib.rs diff --git a/calcpi-rs/src/main.rs b/CalcPi.jl/deps/calcpi-rs/src/main.rs similarity index 100% rename from calcpi-rs/src/main.rs rename to CalcPi.jl/deps/calcpi-rs/src/main.rs From 4b0fbf20a181c8338c121c56e3640214be8555be Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Thu, 8 Jan 2026 16:26:56 +0900 Subject: [PATCH 2/4] Update path references to calcpi-rs in build scripts and library loading - Update build.jl to use deps/calcpi-rs instead of ../calcpi-rs - Update generate_C_API.jl default path to ../deps/calcpi-rs - Update prologue.jl and C_API.jl to search for library in deps/calcpi-rs/target --- CalcPi.jl/deps/build.jl | 2 +- CalcPi.jl/src/C_API.jl | 4 ++-- CalcPi.jl/utils/generate_C_API.jl | 6 +++--- CalcPi.jl/utils/prologue.jl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CalcPi.jl/deps/build.jl b/CalcPi.jl/deps/build.jl index 7ae979d..bb05556 100644 --- a/CalcPi.jl/deps/build.jl +++ b/CalcPi.jl/deps/build.jl @@ -2,7 +2,7 @@ using Pkg using Libdl: dlext using RustToolChain: cargo -const DEV_DIR::String = joinpath(dirname(dirname(@__DIR__)), "calcpi-rs") +const DEV_DIR::String = joinpath(@__DIR__, "calcpi-rs") # Check if the calcpi-rs directory exists locally; if not, do nothing. # If it exists, build the Rust project and copy libcalcpi_rs. to deps/. diff --git a/CalcPi.jl/src/C_API.jl b/CalcPi.jl/src/C_API.jl index 9fce600..7eef222 100644 --- a/CalcPi.jl/src/C_API.jl +++ b/CalcPi.jl/src/C_API.jl @@ -12,10 +12,10 @@ function get_libcalcpi_rs() return local_libcalcpi_path end - # Second, try to find local build in calcpi-rs/target/release or debug + # Second, try to find local build in deps/calcpi-rs/target/release or debug # On Windows, Rust produces calcpi_rs.dll (no lib prefix) # On Unix, Rust produces libcalcpi_rs.so or libcalcpi_rs.dylib (with lib prefix) - calcpi_rs_dir = joinpath(dirname(@__DIR__), "..", "calcpi-rs") + calcpi_rs_dir = joinpath(dirname(@__DIR__), "deps", "calcpi-rs") possible_paths = [ joinpath(calcpi_rs_dir, "target", "release", "libcalcpi_rs.$(Libdl.dlext)"), joinpath(calcpi_rs_dir, "target", "release", "calcpi_rs.$(Libdl.dlext)"), diff --git a/CalcPi.jl/utils/generate_C_API.jl b/CalcPi.jl/utils/generate_C_API.jl index 091cc55..735270d 100644 --- a/CalcPi.jl/utils/generate_C_API.jl +++ b/CalcPi.jl/utils/generate_C_API.jl @@ -16,7 +16,7 @@ function print_help() println("Examples:") println(" julia generate_C_API.jl --calcpi-rs-dir /path/to/calcpi-rs") println() - println("Default: Uses ../../calcpi-rs relative to this script") + println("Default: Uses ../deps/calcpi-rs relative to this script") end # Parse command line arguments @@ -38,8 +38,8 @@ end # Get calcpi-rs directory from command line or use default if calcpi_rs_dir === nothing - # Default path - calcpi_rs_dir = normpath(joinpath(@__DIR__, "../../calcpi-rs")) + # Default path (calcpi-rs is now in CalcPi.jl/deps/calcpi-rs) + calcpi_rs_dir = normpath(joinpath(@__DIR__, "../deps/calcpi-rs")) else # Convert to absolute path calcpi_rs_dir = normpath(abspath(calcpi_rs_dir)) diff --git a/CalcPi.jl/utils/prologue.jl b/CalcPi.jl/utils/prologue.jl index 63f6582..342cb11 100644 --- a/CalcPi.jl/utils/prologue.jl +++ b/CalcPi.jl/utils/prologue.jl @@ -10,10 +10,10 @@ function get_libcalcpi_rs() return local_libcalcpi_path end - # Second, try to find local build in calcpi-rs/target/release or debug + # Second, try to find local build in deps/calcpi-rs/target/release or debug # On Windows, Rust produces calcpi_rs.dll (no lib prefix) # On Unix, Rust produces libcalcpi_rs.so or libcalcpi_rs.dylib (with lib prefix) - calcpi_rs_dir = joinpath(dirname(@__DIR__), "..", "calcpi-rs") + calcpi_rs_dir = joinpath(dirname(@__DIR__), "deps", "calcpi-rs") possible_paths = [ joinpath(calcpi_rs_dir, "target", "release", "libcalcpi_rs.$(Libdl.dlext)"), joinpath(calcpi_rs_dir, "target", "release", "calcpi_rs.$(Libdl.dlext)"), From 6fabd022464b48caabf2498753742c53565ea2b3 Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Thu, 8 Jan 2026 16:26:59 +0900 Subject: [PATCH 3/4] Update CI workflows for calcpi-rs location change - Update all working-directory paths from calcpi-rs to CalcPi.jl/deps/calcpi-rs - Update cache paths and keys to reflect new location - Update integration test paths --- .github/workflows/ci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df01ce5..40c6996 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,21 +93,21 @@ jobs: ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ - calcpi-rs/target/ - key: ${{ runner.os }}-cargo-calcpi-rs-${{ hashFiles('calcpi-rs/Cargo.lock') }} + CalcPi.jl/deps/calcpi-rs/target/ + key: ${{ runner.os }}-cargo-calcpi-rs-${{ hashFiles('CalcPi.jl/deps/calcpi-rs/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-calcpi-rs- - name: Build calcpi-rs - working-directory: calcpi-rs + working-directory: CalcPi.jl/deps/calcpi-rs run: cargo build --release - name: Test calcpi-rs - working-directory: calcpi-rs + working-directory: CalcPi.jl/deps/calcpi-rs run: cargo test --release - name: Check generated header - working-directory: calcpi-rs + working-directory: CalcPi.jl/deps/calcpi-rs shell: bash run: | test -f include/calcpi.h || (echo "Header file not generated" && exit 1) @@ -151,13 +151,13 @@ jobs: ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ - calcpi-rs/target/ - key: ${{ runner.os }}-cargo-calcpi-rs-${{ hashFiles('calcpi-rs/Cargo.lock') }} + CalcPi.jl/deps/calcpi-rs/target/ + key: ${{ runner.os }}-cargo-calcpi-rs-${{ hashFiles('CalcPi.jl/deps/calcpi-rs/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-calcpi-rs- - name: Build calcpi-rs (for CalcPi.jl) - working-directory: calcpi-rs + working-directory: CalcPi.jl/deps/calcpi-rs run: cargo build --release - name: Build CalcPi.jl @@ -210,10 +210,10 @@ jobs: cd .. # Build and test calcpi-rs - cd calcpi-rs + cd CalcPi.jl/deps/calcpi-rs cargo build --release cargo test --release - cd .. + cd ../../.. # Build and test CalcPi.jl cd CalcPi.jl From 46815e746a35ef8892e562ff8f1c8831686513c9 Mon Sep 17 00:00:00 2001 From: Satoshi Terasaki Date: Thu, 8 Jan 2026 16:27:02 +0900 Subject: [PATCH 4/4] Update documentation to reflect calcpi-rs location change - Update all path references in documentation from calcpi-rs to CalcPi.jl/deps/calcpi-rs - Update project structure descriptions - Update build instructions and troubleshooting guides --- CalcPi.jl/DEVELOPMENT.md | 14 +++++++------- CalcPi.jl/deps/README.md | 4 ++-- CalcPi.jl/utils/README.md | 10 +++++----- README.md | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CalcPi.jl/DEVELOPMENT.md b/CalcPi.jl/DEVELOPMENT.md index c857883..a8d492b 100644 --- a/CalcPi.jl/DEVELOPMENT.md +++ b/CalcPi.jl/DEVELOPMENT.md @@ -28,7 +28,7 @@ CalcPi.jl/ When you modify the Rust code in `calcpi-rs`: ```bash -cd calcpi-rs +cd CalcPi.jl/deps/calcpi-rs # Edit Rust code ``` @@ -69,7 +69,7 @@ The `prologue.jl` (included in `C_API.jl`) searches for the library in the follo - Local build copied by `Pkg.build()` - Used during development -2. **`calcpi-rs/target/release/libcalcpi_rs.*`** +2. **`deps/calcpi-rs/target/release/libcalcpi_rs.*`** - Directly built library - Fallback when not in `deps/` @@ -94,11 +94,11 @@ If the library is not found: ```bash # 1. Build the Rust library -cd calcpi-rs +cd CalcPi.jl/deps/calcpi-rs cargo build --release # 2. Rebuild the Julia package -cd ../CalcPi.jl +cd ../.. julia --project=. deps/build.jl ``` @@ -111,12 +111,12 @@ To rebuild from a completely clean state: rm -rf CalcPi.jl/deps/libcalcpi_rs.* # 2. Clean build the Rust project -cd calcpi-rs +cd CalcPi.jl/deps/calcpi-rs cargo clean cargo build --release # 3. Rebuild the Julia package -cd ../CalcPi.jl +cd ../.. julia --project=. deps/build.jl ``` @@ -135,7 +135,7 @@ julia --project=. deps/build.jl `deps/build.jl` performs the following: -1. Detect `calcpi-rs` directory +1. Detect `deps/calcpi-rs` directory 2. Build Rust library 3. Copy library to `deps/` 4. Generate C-API bindings diff --git a/CalcPi.jl/deps/README.md b/CalcPi.jl/deps/README.md index 3357aff..c4eb56a 100644 --- a/CalcPi.jl/deps/README.md +++ b/CalcPi.jl/deps/README.md @@ -1,6 +1,6 @@ # deps -The `build.jl` script provides developer-focused support for building the Rust backend required by `CalcPi.jl`. It assumes that the Rust crate `calcpi-rs` is located in the same parent directory as the `CalcPi.jl` package. +The `build.jl` script provides developer-focused support for building the Rust backend required by `CalcPi.jl`. It assumes that the Rust crate `calcpi-rs` is located in `deps/calcpi-rs` within the `CalcPi.jl` package. After making changes to the Rust code, it is assumed that you will rebuild the Julia package as follows: @@ -15,7 +15,7 @@ This process will update `src/C_API.jl` and copy the `libcalcpi_rs.dylib` (or th ## How it works -1. **Detects local Rust crate**: Checks if `../calcpi-rs` directory exists +1. **Detects local Rust crate**: Checks if `deps/calcpi-rs` directory exists 2. **Builds Rust library**: Uses `RustToolChain.jl` to run `cargo build --release` in the Rust crate directory 3. **Copies library**: Copies the built library to `deps/libcalcpi_rs.` 4. **Generates C-API bindings**: Runs `utils/generate_C_API.jl` to regenerate `src/C_API.jl` diff --git a/CalcPi.jl/utils/README.md b/CalcPi.jl/utils/README.md index 18d5358..4a64809 100644 --- a/CalcPi.jl/utils/README.md +++ b/CalcPi.jl/utils/README.md @@ -20,11 +20,11 @@ Based on the mechanism from `SparseIR.jl/utils`, this tool automatically generat First, build the Rust library to generate the header file: ```bash -cd ../../calcpi-rs +cd CalcPi.jl/deps/calcpi-rs cargo build --release ``` -This generates `calcpi-rs/include/calcpi.h`. +This generates `CalcPi.jl/deps/calcpi-rs/include/calcpi.h`. ### 2. Generating Julia Bindings @@ -35,7 +35,7 @@ cd CalcPi.jl/utils julia generate_C_API.jl ``` -By default, it looks for `../../calcpi-rs`. To specify a different path: +By default, it looks for `../deps/calcpi-rs`. To specify a different path: ```bash julia generate_C_API.jl --calcpi-rs-dir /path/to/calcpi-rs @@ -52,7 +52,7 @@ julia generate_C_API.jl --calcpi-rs-dir /path/to/calcpi-rs ## 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` +2. **Directory validation**: Checks for the existence of `deps/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 @@ -82,7 +82,7 @@ Defines the library loading process. It prioritizes local builds and falls back Build the Rust library: ```bash -cd calcpi-rs && cargo build --release +cd CalcPi.jl/deps/calcpi-rs && cargo build --release ``` ### Error: CEnum not found diff --git a/README.md b/README.md index bb41ef1..c4d95ea 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ This repository is a collection of sample projects demonstrating how to call Rus ### Main Projects -- **`calcpi-rs/`** - Rust library implementing π calculation using the Monte Carlo method -- **`CalcPi.jl/`** - Julia package for calling `calcpi-rs` from Julia +- **`CalcPi.jl/`** - Julia package for calling Rust-implemented Monte Carlo π calculation library + - **`CalcPi.jl/deps/calcpi-rs/`** - Rust library implementing π calculation using the Monte Carlo method (embedded in CalcPi.jl) ### Sample Projects