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 an optional js feature #86

Closed
wants to merge 3 commits into from
Closed

Conversation

ninegua
Copy link
Contributor

@ninegua ninegua commented Jan 2, 2025

When the target is wasm32, the current configuration would by default enable the "js" feature of getrandom.
But this won't work well with projects that cannot enable the "js" feature (e.g., those use the "custom" feature).

Because cargo features are additive, it is best to avoid setting the "js" feature as default, but instead make it optional.

@@ -16,6 +16,7 @@ repository = "https://github.com/dylanhart/ulid-rs"
default = ["std"]
std = ["rand"]
postgres = ["dep:postgres-types", "dep:bytes"]
js = ["getrandom/js"]
Copy link
Owner

Choose a reason for hiding this comment

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

Needs documentation in README

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added a line to the README. Please have a look, thanks!

@@ -16,6 +16,7 @@ repository = "https://github.com/dylanhart/ulid-rs"
default = ["std"]
std = ["rand"]
postgres = ["dep:postgres-types", "dep:bytes"]
js = ["getrandom/js"]
Copy link
Owner

Choose a reason for hiding this comment

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

Should this be a default feature? It seems odd to have a feature that needs to be enabled when compiling for JS targets. Does this break the library when turned off?

The existing WASM target was contributed and I'm not really sure on the best practices here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it should be a default feature, because for example tower-request-id currently uses ulid, and for any code that uses towers-request-id, it is impossible to turn off getrandom/js feature due to the additive nature of cargo features.

If on the other hand, this is not default, for those that uses tower-request-id and also wants getrandom/js, they can easily add getrandom to their Cargo.toml with the js feature enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think it is best to remove dependency on getrandom. This crate in no way imports the getrandom crate, and I suspect the only reason getrandom/js feature was enabled was due to the need to run wasm-pack in CI. But this is can be easily fixed. I'll submit another PR for you to have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR is here #87

I'll close this one if you think #87 is more appropriate. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another workaround is to move getrandom to a dev dependency #88 , which has the minimum change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm closing this and #87 in favor of #88. Please feel free to re-open if you think otherwise.

@ninegua ninegua closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants