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
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions CalcPi.jl/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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/`

Expand All @@ -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
```

Expand All @@ -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
```

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CalcPi.jl/deps/README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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.<ext>`
4. **Generates C-API bindings**: Runs `utils/generate_C_API.jl` to regenerate `src/C_API.jl`
Expand Down
2 changes: 1 addition & 1 deletion CalcPi.jl/deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.<ext> to deps/.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions CalcPi.jl/src/C_API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down
10 changes: 5 additions & 5 deletions CalcPi.jl/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CalcPi.jl/utils/generate_C_API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions CalcPi.jl/utils/prologue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down