Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make overwritable experimental behind a cargo feature #160

Merged
merged 3 commits into from
Oct 27, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/ISSUE_TEMPLATE/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@




<!-- Please keep this note for the community at the end of the issue -->

### A note for the community from the maintainers

Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ jobs:

- 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
- run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable
- run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,alloc
- run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,implied-bounds
- run: cd bon && cargo test --locked --no-default-features --features=experimental-overwritable,alloc,implied-bounds

test-msrv:
runs-on: ${{ matrix.os }}-latest
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/compilation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"
version = "0.1.0"

[dependencies]
bon = { path = "../../bon", optional = true }
bon = { path = "../../bon", optional = true, features = ["experimental-overwritable"] }
cfg-if = "1.0"
derive_builder = { version = "0.20", optional = true }
typed-builder = { version = "0.20", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions bon-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ rustversion = "1.0"
[features]
default = []

# See the docs on this feature in the `bon`'s crate `Cargo.toml`
experimental-overwritable = []

Comment on lines +66 to +68
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Documentation reference in comment is misleading

The comment states "See the docs on this feature in the bon's crate Cargo.toml", but the bon crate's Cargo.toml only contains the feature declaration without any documentation. The feature is used in the codebase:

  • Declared in bon-macros/Cargo.toml
  • Referenced in bon/Cargo.toml for feature forwarding
  • Used in runtime checks in bon-macros/src/builder/builder_gen/ files
  • Used in e2e tests

Consider either:

  • Removing the misleading documentation reference comment, or
  • Adding actual documentation about this experimental feature in bon/Cargo.toml
🔗 Analysis chain

LGTM! Feature flag implementation looks correct.

The implementation of the experimental-overwritable feature flag follows Rust's best practices:

  • Empty feature flag is appropriate for compile-time toggles
  • Clear documentation reference helps maintainability
  • Not included in default features, which is correct for experimental features

Let's verify the feature documentation reference:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the referenced documentation exists in bon's Cargo.toml
# Expected: Find documentation about the experimental-overwritable feature

rg -A 5 "experimental-overwritable" ../bon/Cargo.toml

Length of output: 111


Script:

#!/bin/bash
# Let's first check if the bon crate exists in the repository
fd -t d "bon$"

# Then let's check all Cargo.toml files for the feature documentation
fd "Cargo.toml" -x rg -A 5 "experimental-overwritable" {}

# Also search for any documentation about this feature in other common places
rg -i "experimental.?overwritable" -g "!target/" -g "*.{md,rs,toml}"

Length of output: 1330

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file bon/Cargo.toml contains the feature declaration as well, and it contains an extensive comment that documents that feature right on top of the feature declaration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veetaha, thank you for the clarification. I see that the bon/Cargo.toml file does contain extensive documentation for the experimental-overwritable feature as you mentioned. I've noted this information for future reviews.

(・ω・)ゞ


✏️ Learnings added
Learnt from: Veetaha
PR: elastio/bon#160
File: bon-macros/Cargo.toml:66-68
Timestamp: 2024-10-27T15:42:41.282Z
Learning: In the `bon` crate, the `bon/Cargo.toml` file contains extensive documentation for the `experimental-overwritable` feature above its feature declaration.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

# See the docs on this feature in the `bon`'s crate `Cargo.toml`
implied-bounds = []

Expand Down
14 changes: 14 additions & 0 deletions bon-macros/src/builder/builder_gen/member/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ impl MemberConfig {
}

pub(crate) fn validate(&self, origin: MemberOrigin) -> Result {
if !cfg!(feature = "experimental-overwritable") && self.overwritable.is_present() {
bail!(
&self.overwritable.span(),
"🔬 `overwritable` attribute is experimental and requires \
\"experimental-overwritable\" cargo feature to be enabled; \
we would be glad to make this attribute stable if you find it useful; \
please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 \
to help us measure the demand for this feature; it would be \
double-awesome if you could also describe your use case in \
a comment under the issue for us to understand how it's used \
in practice",
);
}

if self.start_fn.is_present() {
self.validate_mutually_allowed(
ParamName::StartFn,
Expand Down
14 changes: 14 additions & 0 deletions bon-macros/src/builder/builder_gen/top_level_config/on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ impl Parse for OnConfig {

let parsed = Parsed::from_meta(&syn::parse_quote!(on(#rest)))?;

if !cfg!(feature = "experimental-overwritable") && parsed.overwritable.is_present() {
return Err(syn::Error::new(
parsed.overwritable.span(),
"🔬 `overwritable` attribute is experimental and requires \
\"experimental-overwritable\" cargo feature to be enabled; \
we would be glad to make this attribute stable if you find it useful; \
please leave a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 \
to help us measure the demand for this feature; it would be \
double-awesome if you could also describe your use case in \
a comment under the issue for us to understand how it's used \
in practice",
));
}

{
// Validate that at least some option was enabled.
// This lives in a separate block to make sure that if a new
Expand Down
16 changes: 16 additions & 0 deletions bon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,19 @@ std = ["alloc"]
#
# Huge thanks to @harudagondi for suggesting the name of this cargo feature!
implied-bounds = ["bon-macros/implied-bounds"]

# 🔬 Experimental! There may be breaking changes to this feature between *minor* releases,
# however, compatibility within patch releases is guaranteed though.
#
# This feature enables the #[builder(overwritable)] attribute that can be used to
# allow overwriting already set fields in the builder. Without this attribute it's
# not possible to set the same member twice in the builder, a compile error would be
# generated.
#
# See more info at https://bon-rs.com/reference/builder/top-level/overwritable.
#
# We are considering stabilizing this attribute if you have a use for it. Please leave
# a 👍 reaction under the issue https://github.com/elastio/bon/issues/149 if you need
# this attribute. It would also be cool if you could leave a comment under that issue
# describing your use case for it.
experimental-overwritable = ["bon-macros/experimental-overwritable"]
2 changes: 1 addition & 1 deletion e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ edition = "2021"
workspace = true

[dependencies]
bon = { path = "../bon" }
bon = { path = "../bon", features = ["experimental-overwritable"] }

[dev-dependencies]
anyhow = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-msrv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ step cargo update -p windows-sys --precise 0.52.0

export RUSTFLAGS="${RUSTFLAGS:-} --allow unknown-lints"

step cargo clippy --all-targets --locked
step cargo clippy --all-targets --locked --features=experimental-overwritable

test_args=(
--locked
Expand All @@ -57,4 +57,4 @@ test_args=(
--skip ui::ui
)

step cargo test "${test_args[@]}"
step cargo test --features=experimental-overwritable "${test_args[@]}"
1 change: 1 addition & 0 deletions website/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ All the breaking changes are very unlikely to actually break your code that was

- Add graceful internal panic handling. If some `bon` macro panics due to an internal bug, the macro will try to still generate a fallback for IDEs to still provide intellisense ([#145](https://github.com/elastio/bon/pull/145))
- Switch from `elastio.github.io/bon` to a custom domain `bon-rs.com` ([#158](https://github.com/elastio/bon/pull/158))
- Add anonymous stats with [`umami`](https://umami.is/) for the docs website ([#158](https://github.com/elastio/bon/pull/158))

## [2.3.0](https://github.com/elastio/bon/compare/v2.2.1...v2.3.0) - 2024-09-14

Expand Down
32 changes: 31 additions & 1 deletion website/infra/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# umami backend

This directory contains the deployment code for our [umami](https://umami.is/) backend used for collecting anonymous statics about the usage of our documentation website. The code for this lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner).
This directory contains the deployment code for our [umami](https://umami.is/) backend, used for collecting anonymous statistics about the usage of our documentation website. This code lives here in the open for the sake of transparency and sharing (in case if you want to self-host your own umami instance on Hetzner).

It is a simple Hetzner VPS that runs a docker-compose cluster with the umami service and Postgres. The data is stored on a separate volume. The server is allocated a static IPv4.

## Deployment

Prerequisites:
- [Terraform CLI](https://developer.hashicorp.com/terraform/install)
- [Account at hetzner.com/cloud](https://hetzner.com/cloud)

Create a `terraform.tfvars` file in this directory. Here is an example below, make sure to replace all `{...}` placeholders with your values.

```tf
hcloud_token = "{token_value}"

allowed_ssh_ips = ["{your_ip_here}/32"]

pg_password = "{pg_password_value}"

umami_app_secret = "{umami_app_secret_value}"
```

Initialize terraform plugin directory and modules:

```bash
terraform init
```

Run the deployment:

```bash
terraform apply
```
Loading