Skip to content

Commit

Permalink
refactor: create workspace & split examples from core implementation (#8
Browse files Browse the repository at this point in the history
)

* move current lib to inner integraal folder

* add workspace manifest

* move dependencies def to workspace manifest

* convert examples into a proper workspace member

* add missing doc in main crate

* update CI to exclude examples from coverage
  • Loading branch information
imrn99 authored May 9, 2024
1 parent 5ea1b5d commit 30fa7e6
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build crates
run: cargo build --all
- name: Build main crate
run: cargo build -p integraal --all-features
build_examples:
name: Build examples for ${{ matrix.os }}
strategy:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
- uses: Swatinem/rust-cache@v2
# generate raw coverage data
- name: Build code
run: cargo build --all-features
run: cargo build --all-features --workspace --exclude integraal-examples
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "cargo-test-%p-%m.profraw"
- name: Run tests
run: cargo test --all-features
run: cargo test --all-features --workspace --exclude integraal-examples
env:
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "cargo-test-%p-%m.profraw"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:

# Publish
- name: Publish core
run: cargo publish --token ${CIO_TOKEN}
run: cargo publish --package integraal --token ${CIO_TOKEN}
env:
CIO_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run Tests
run: cargo test --all
run: cargo test --all --all-features
59 changes: 15 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[package]
name = "integraal"
[workspace]

resolver = "2"
members = [
"integraal",
"examples"
]

[workspace.package]
version = "0.0.1"
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -11,47 +18,11 @@ categories = ["algorithms", "concurrency", "mathematics", "science"]
keywords = ["algorithms", "analysis", "integration", "numerical-analysis", "numerical-method"]
authors = ["Isaie Muron <[email protected]>"]

[workspace.dependencies]
# members
integraal = { version = "0.0.1", path = "./integraal" }
integraal-examples = { version = "0.0.1", path = "./examples" }

# FEATURES

[features]
montecarlo = ["dep:rand"]

# DEPS

[dependencies]
rand = { version = "0.9.0-alpha.1", features = ["small_rng"], optional = true }

[build-dependencies]
# external
rand = "0.9.0-alpha.1"
rustversion = "1.0.15"

[dev-dependencies]
rand = { version = "0.9.0-alpha.1", features = ["small_rng"] }

# EXAMPLES

[[example]]
name = "rectangle_hardcoded"
path = "examples/rectangle/hardcoded.rs"

[[example]]
name = "rectangle_integraal"
path = "examples/rectangle/integraal.rs"

[[example]]
name = "trapezoid_hardcoded"
path = "examples/trapezoid/hardcoded.rs"

[[example]]
name = "trapezoid_integraal"
path = "examples/trapezoid/integraal.rs"

[[example]]
name = "montecarlo_hardcoded"
path = "examples/montecarlo/hardcoded.rs"
required-features = ["montecarlo"] # not necessary, but enabled for consistency

[[example]]
name = "montecarlo_integraal"
path = "examples/montecarlo/integraal.rs"
required-features = ["montecarlo"]
42 changes: 42 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "integraal-examples"
version = "0.0.1"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://imrn99.github.io/integraal/"
repository = "https://github.com/imrn99/integraal"
readme = "../README.md"
description = "Example of the Integraal crate"
categories = ["algorithms", "concurrency", "mathematics", "science"]
keywords = ["algorithms", "analysis", "integration", "numerical-analysis", "numerical-method"]
authors = ["Isaie Muron <[email protected]>"]

[dependencies]
integraal = { workspace = true, features = ["montecarlo"] }
rand = { workspace = true, features = ["small_rng"] }

# EXAMPLES

[[example]]
name = "rectangle_hardcoded"
path = "examples/rectangle/hardcoded.rs"

[[example]]
name = "rectangle_integraal"
path = "examples/rectangle/integraal.rs"

[[example]]
name = "trapezoid_hardcoded"
path = "examples/trapezoid/hardcoded.rs"

[[example]]
name = "trapezoid_integraal"
path = "examples/trapezoid/integraal.rs"

[[example]]
name = "montecarlo_hardcoded"
path = "examples/montecarlo/hardcoded.rs"

[[example]]
name = "montecarlo_integraal"
path = "examples/montecarlo/integraal.rs"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions integraal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "integraal"
version = "0.0.1"
edition = "2021"
license = "MIT OR Apache-2.0"
homepage = "https://imrn99.github.io/integraal/"
repository = "https://github.com/imrn99/integraal"
readme = "../README.md"
description = "Integral computation, done in Rust! "
categories = ["algorithms", "concurrency", "mathematics", "science"]
keywords = ["algorithms", "analysis", "integration", "numerical-analysis", "numerical-method"]
authors = ["Isaie Muron <[email protected]>"]


# FEATURES

[features]
montecarlo = ["dep:rand"]

# DEPS

[dependencies]
rand = { workspace = true, features = ["small_rng"], optional = true }

[build-dependencies]
rustversion.workspace = true

[dev-dependencies]
rand = { workspace = true, features = ["small_rng"] }
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions src/parameters.rs → integraal/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum ComputeMethod {
/// Trapezoid method [reference](https://en.wikipedia.org/wiki/Trapezoidal_rule)
Trapezoid,
#[cfg(feature = "montecarlo")]
/// MonteCarlo method [reference](https://en.wikipedia.org/wiki/Monte_Carlo_integration)
MonteCarlo { n_sample: usize },
/// Monte-Carlo method [reference](https://en.wikipedia.org/wiki/Monte_Carlo_integration)
MonteCarlo {
/// Number of random number sample per step computation.
n_sample: usize,
},
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 30fa7e6

Please sign in to comment.