Skip to content

Initial Rust no_std support.#153

Closed
dot-asm wants to merge 4 commits intosupranational:masterfrom
dot-asm:no_std
Closed

Initial Rust no_std support.#153
dot-asm wants to merge 4 commits intosupranational:masterfrom
dot-asm:no_std

Conversation

@dot-asm
Copy link
Collaborator

@dot-asm dot-asm commented Mar 10, 2023

No description provided.

This was referenced Mar 10, 2023
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#![cfg_attr(not(feature = "std"), no_std)]

Choose a reason for hiding this comment

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

You should define features in Cargo.toml. Even though it will work like that, it is not easily discoverable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a conscious choice. There is no reason to make it discoverable. If user attempts to compile on a bare-metal platform it's simply engaged in the build script.

Choose a reason for hiding this comment

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

But why should blst be unlike any other ordinary Rust crate? There is an established pattern in the ecosystem how this things are done, what is the point of deviating from it?

Choose a reason for hiding this comment

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

Without having this feature defined in Cargo.toml and set by default you essentially compile no_std version for ALL PLATFORMS. Users will have to set std feature to avoid this, but due to "conscious choice" they will have a hard time knowing it exists in the first place.

You can probably define it from within build.rs but you've literally fighting the best practices in the ecosystem for the sake of confusing users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you essentially compile no_std version for ALL PLATFORMS.

No. build.rs enables std feature on ALL PLATFORMS but bare-metal ones.

Users will have to set std feature to avoid this,

No. Users won't have to do anything. Nor would they have to do anything special when using blst as dependency on a bare-metal platform.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They may want to have no threads either because for their use case threading makes more sense on higher level

And they can do that. Nobody actually did to my knowledge, defaulting to multi-threading appears to be generally appreciated.

and blst would just cause quadratic number of threads only making things worse.

This is not true. blst uses a private fixed-sized threadpool.

Choose a reason for hiding this comment

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

blst is about what actually works, not what might work.

What I'm trying to say is blst can't possibly know and doesn't really need to know what works and what doesn't. I have given a few examples like support for threads where you think there isn't such support and forcing std on users that can, but don't want to depend on it. Both of those are not possible to achieve with current design of the library.

Simply offering two features enabled by default (std and threads) allows any imaginable supported platform will work under full control of the developer using the library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And what I'm saying is that if we don't know something, we make no assumptions and don't really want users to make such assumptions either. [As effectively reflected in README.md.] But as already said, it's not right spot to discuss this. Why-not-this-way is off-topic in this specific context. Open an issue or choose another channel to communicate with supranational.

Copy link
Contributor

@huitseeker huitseeker Aug 9, 2023

Choose a reason for hiding this comment

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

They may want to have no threads either because for their use case threading makes more sense on higher level

And they can do that. Nobody actually did to my knowledge, defaulting to multi-threading appears to be generally appreciated.

For the record (just to volunteer relevant info, I don’t have a horse in this race), MystenLabs/fastcrypto#176

Copy link

Choose a reason for hiding this comment

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

I was thinking to replace manual thread pool management with rayon, which inherits thread pool from outer context and that way you can change number of threads from the outside (or not bother and use global default thread pool), but didn't have time to do the change and bench it.

fi
cargo test --release
cargo test --release --features=no-threads
env BLST_TEST_NO_STD= cargo test --release

Choose a reason for hiding this comment

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

This is not how Rust ecosystem does it. It should be controlled by features (there is --no-default-features for instance). See #150 on how to do it in idiomatic way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not how Rust ecosystem does it.

I don't really care. I want to exercise the no_std build on an std platform without offering an idiomatic way.

Choose a reason for hiding this comment

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

What is the point? It just confuses the heck out of people.

I get that in other languages that might be a norm, but in Rust there are conventions that make like so much easier, I don't quite understand the rationale behind deliberately making it harder instead 😕

IMHO Rust API should look like idiomatic Rust, Golang API should look like idiomatic Golang and so on for every language to the degree possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What is the point?

??? It says just one line above, "exercise the no_std build on an std platform." It's not for users, but for us as a way to ensure that no_std doesn't go under the CI radar unchecked.

Choose a reason for hiding this comment

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

My question was about your comment. What is the point of intentionally doing non-idiomatic way with environment variables and other trickery if you can just use idiomatic --no-default-features like most other projects do.

We plan to use this package in Subspace and I care about the quality of Rust binding and willing to help, so seeing deliberately non-idiomatic code is confusing to me and doesn't make sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you can just use idiomatic --no-default-features

To do what? To run the test. But what do I tell no_std, a.k.a. bare-metal platform users who want to use blst as dependency? Or let me rephrase. Provided that I don't actually have to tell them anything special, why would I want to?

We plan to use this package in Subspace

Just in case, quoting README.md, "Problem reports for these [non-x86_64 and ARM64 hardware platforms] will be considered and are likely to be addressed."

Choose a reason for hiding this comment

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

To do what? To run the test. But what do I tell no_std, a.k.a. bare-metal platform users who want to use blst as dependency? Or let me rephrase. Provided that I don't actually have to tell them anything special, why would I want to?

Because it is up to the user whether they want to use std or not (it is not free, they might run on a platform where they don't want to pull std even if they technically could from CPU architecture point of view). This might include use cases like building a static library. By forcing decisions that you don't want to tell and don't want to expose you're locking them out of ability to use the library like they use any other idiomatic Rust library.

Just in case, quoting README.md, "Problem reports for these [non-x86_64 and ARM64 hardware platforms] will be considered and are likely to be addressed."

It is certainly appreciated, but my point is that if you create a typical idiomatic Rust crate you don't even need to have that in the readme. The beauty of Rust ecosystem is that most of the packages follow the same versioning, naming and features conventions and everyone knows what it is and how to use it. By default. No extra docs necessary.

Comment on lines 107 to 130
pippenger_mult_impl!(
p1_affines,
blst_p1,
blst_p1_affine,
blst_p1s_to_affine,
blst_p1s_mult_pippenger_scratch_sizeof,
blst_p1s_mult_pippenger,
blst_p1s_tile_pippenger,
blst_p1_add_or_double,
blst_p1_double,
p1_multi_scalar,
blst_p1_generator,
blst_p1_mult,
);

Choose a reason for hiding this comment

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

These should really be generics and type aliases for convenience rather than macros. Macros destroy IDE support and make it hard to debug things when something goes wrong both for maintainers and users. This crate seems to go to extreme by having almost all code under macros, which is a big usability issue.

@dot-asm
Copy link
Collaborator Author

dot-asm commented Mar 18, 2023

Just in case. Questions/rants that go beyond the specific subject matter will remain unanswered. The subject is that the suggested method is deemed to work reliably. Without disrupting current users and providing a straightforward path for potential no_std users.

@nazar-pc
Copy link

Without disrupting current users and providing a straightforward path for potential no_std users.

#150 is also fully backwords compatible and supports no_std for 100% of APIs at the same time 🤷‍♂️

@rupansh
Copy link

rupansh commented Jun 2, 2023

Hello are there any plans to merge this soon?

@dot-asm dot-asm force-pushed the no_std branch 4 times, most recently from 7ed2b4d to 734c562 Compare June 16, 2023 11:30
@dot-asm dot-asm force-pushed the no_std branch 2 times, most recently from be64c71 to d3dbaab Compare June 16, 2023 17:39
@dot-asm
Copy link
Collaborator Author

dot-asm commented Jun 16, 2023

Merged.

@dot-asm dot-asm closed this Jun 16, 2023
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.

4 participants