Skip to content

Commit

Permalink
Flexible builder extension and type signature API (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Veetaha authored Oct 20, 2024
1 parent eb39001 commit aed7148
Show file tree
Hide file tree
Showing 168 changed files with 12,025 additions and 3,197 deletions.
44 changes: 38 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

jobs:
# Sanity-check that benchmarks work
benchmarks:
runtime-benchmarks:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -41,7 +41,16 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1

- run: sudo apt-get install -y valgrind
- run: ./benchmarks/run.sh ${{ matrix.benchmark }}
- run: cd ./benchmarks/runtime && ./run.sh ${{ matrix.benchmark }}

compilation-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: ./scripts/install/hyperfine.sh

- run: cd ./benchmarks/compilation && ./run.sh

cargo-lock:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -75,13 +84,21 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# rust-src is required to make sure compile errors on CI are rendered
# the same as locally. The `rust-src` component is installed by default
# locally, and with its presence compile error messages can show snippets
# of rust standard library code.
components: rust-src

- run: cargo clippy --all-features --all-targets --locked

- run: cargo test --locked --all-features --all-targets
- run: cargo test --locked --all-features --doc
- run: cd bon && cargo test --locked --no-default-features --features=
- run: cd bon && cargo test --locked --no-default-features --features=alloc
- run: cd bon && cargo test --locked --no-default-features --features=implied-bounds
- run: cd bon && cargo test --locked --no-default-features --features=alloc,implied-bounds

test-msrv:
runs-on: ${{ matrix.os }}-latest
Expand Down Expand Up @@ -119,13 +136,28 @@ jobs:
toolchain: ${{ matrix.toolchain }}
components: clippy

- run: cargo +${{ matrix.toolchain }} clippy --all-features --all-targets --locked
- run: |
cargo +${{ matrix.toolchain }} clippy --all-features --all-targets --locked \
-- \
--allow edition-2024-expr-fragment-specifier \
--allow impl-trait-overcaptures
cargo-miri:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2024-10-14
components: miri

- run: |
cargo miri test --locked --all-features --all-targets \
--workspace --exclude runtime-benchmarks
env:
# There is no need for us to stick with the edition 2021 meaning for
# the `expr` fragment in macro rules.
RUSTFLAGS: >-
--deny warnings
--allow unknown-lints
--allow edition-2024-expr-fragment-specifier
--allow impl-trait-overcaptures
Expand Down
114 changes: 98 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[workspace]
members = ["benchmarks", "bon", "bon-cli", "bon-macros", "e2e-tests"]
members = [
"benchmarks/compilation",
"benchmarks/compilation/codegen",
"benchmarks/runtime",
"bon",
"bon-cli",
"bon-macros",
"e2e-tests",
]
resolver = "2"

# This config is used for the benchmarks
Expand Down Expand Up @@ -130,8 +138,7 @@ wildcard_dependencies = "warn"
zero_sized_map_values = "warn"

# Priorities are used not because we override lints from these lint groups
# but just to order them in order from the less noisy to the more noisy in
# the output
# but just to order them from the less noisy to the more noisy in the output
nursery = { level = "warn", priority = -2 }
pedantic = { level = "warn", priority = -1 }

Expand Down Expand Up @@ -176,5 +183,5 @@ rust_2024_compatibility = { level = "warn", priority = 1 }
# [workspace.lints.rust]
# must_not_suspend = "warn"
# rust_2024_incompatible_pat = "warn"
# lossy_provenance_casts = "warn"
# fuzzy_provenance_casts = "warn"
# lossy_provenance_casts = "warn"
# fuzzy_provenance_casts = "warn"
28 changes: 28 additions & 0 deletions benchmarks/compilation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "compilation-benchmarks"

publish = false

description = """
Crate for benchmarking of the compilation time of code generated by
proc-macros in the `bon` crate and other alternatives.
"""

edition = "2021"
version = "0.1.0"

[dependencies]
bon = { path = "../../bon", optional = true }
cfg-if = "1.0"
derive_builder = { version = "0.20", optional = true }
typed-builder = { version = "0.20", optional = true }

[lints]
workspace = true

[features]
bon-overwritable = ["bon"]
default = []

structs_100_fields_10 = []
structs_10_fields_50 = []
25 changes: 25 additions & 0 deletions benchmarks/compilation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Benchmarks

This is a collection of compilation time benchmarks for the code generated by `bon` crate and some other alternative builder macro crates.

## Dependencies

If you'd like to run the benchmarks yourself, first you need to install the following:

- [`hyperfine`](https://github.com/sharkdp/hyperfine) CLI

If you are on Linux, just run the following commands to install the dependencies:

```bash
./scripts/install/hyperfine.sh
```

## Running the benchmarks

Once you have all the [dependencies](#dependencies) installed you can run the selected benchmark from this directory like this:

```bash
./run.sh {benchmark_name}
```

The `{benchmark_name}` corresponds to the modules in this crate.
16 changes: 16 additions & 0 deletions benchmarks/compilation/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "compilation-benchmarks-codegen"

publish = false

description = """
Generates code for the compilation benchmarks.
"""

edition = "2021"
version = "0.1.0"

[dependencies]
anyhow = "1.0"
proc-macro2 = "1.0"
quote = "1.0"
Loading

0 comments on commit aed7148

Please sign in to comment.