8000 Create configuration conditional "bench" by tcharding · Pull Request #1092 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Create configuration conditional "bench" #1092

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

Merged
merged 4 commits into from
Jul 17, 2022

Conversation

tcharding
Copy link
Member
@tcharding tcharding commented Jul 10, 2022

Currently we are unable to build with all features enabled with a non-nightly toolchain, this is because of the use of

`#![cfg_attr(all(test, feature = "unstable"), feature(test))]`

which causes the following error when building:

error[E0554]: #![feature] may not be used on the stable release channel

The "unstable" feature is used to guard bench mark modules, this is widely suggested online but there is a better way.

When running the bench marks use the following incantation:

`RUSTFLAGS='--cfg=bench' cargo bench`

This creates a configuration conditional "bench" that can be used to guard the bench mark modules.

#[cfg(bench)]
mod benches {
    ...
}

@tcharding tcharding mentioned this pull request Jul 10, 2022
@tcharding tcharding force-pushed the 07-11-cfg-nightly branch from 64aae19 to 9d14723 Compare July 11, 2022 01:50
@apoelstra
Copy link
Member

What if you also add cfg=test?

@Kixunil
Copy link
Collaborator
Kixunil commented Jul 11, 2022

Perhaps #[cfg(bench)] extern crate test;?

@tcharding tcharding force-pushed the 07-11-cfg-nightly branch 2 times, most recently from af36b06 to 5605011 Compare July 12, 2022 00:09
@tcharding tcharding changed the title WIP: Attempt to use --cfg=bench Create configuration conditional "bench" Jul 12, 2022
@tcharding tcharding marked this pull request as ready for review July 12, 2022 00:28
@apoelstra
Copy link
Member

Very nice! Would be nice to also mention this in the README -- and we should move all the crates in the ecosystem over to this scheme.

apoelstra
apoelstra previously approved these changes Jul 12, 2022
Copy link
Member
@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 56050115770b51f299258335fbd253566dff82cd

if [ "$DO_BENCH" = true ]
then
cargo bench --features unstable
RUSTFLAGS='--cfg=bench' cargo bench
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe cargo +nightly bench?

Copy link
Member

Choose a reason for hiding this comment

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

This would make it impossible to use specific toolchains for benching, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you have multiple nightlies, yes (is that even possible?) Also I think +beta is also possible. Stable can't work because extern crate test is experimental.

Copy link
Member

Choose a reason for hiding this comment

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

You can definitely have multiple nightlies; you specify them by date. This is sometimes useful for bisecting when a nightly broke things.

Understood that stable won't work...we should, I suppose, check whether the user has specified a toolchain and provide a helpful error message if he hasn't.

Copy link
Member Author
@tcharding tcharding Jul 12, 2022

Choose a reason for hiding this comment

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

By 'specify' you mean by using TOOLCHAIN=foo, right? We don't do that in test.sh so I don't think we should warn
for not being set.

Copy link
Member

Choose a reason for hiding this comment

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

That is what I mean, and I don't understand what you mean by "we don't do that". We have a check for it on line 6.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I mean we never set the TOOLCHAIN env variable in CI. We could check if TOOLCHAIN is set, and check what toolchain is being used, then output an error message if TOOLCHAIN is set and current toolchain is not nightly.

Copy link
Member Author
@tcharding tcharding Jul 14, 2022

Choose a reason for hiding this comment

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

I've added error output to the DO_BENCH code block (as a separate preparatory patch). Its untested because

  1. I'm so confident in my bash foo ;)
  2. The is no DO_FEATURE_MATRIX in rust-bitcoin version of the script so running it (and testing it) takes ages [0]

I started hacking it apart but backed out and started a discussion on the CI scripts: #1096

[0] - I'm sure someone wise once said that if tests are too hard to run they are never run.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see, in CI we just install nightly and don't bother with the TOOLCHAIN variable ... ok, that's fine. I don't see any sensible way to output a warning here.

@tcharding
Copy link
Member Author
tcharding commented Jul 13, 2022

Changes in force push:

  • Mentioned beta in comment: # Bench if told to, only works with non-stable toolchain (nightly, beta).

@tcharding
Copy link
Member Author

Perhaps #[cfg(bench)] extern crate test;?

Forgot to say the other day, you were right @Kixunil, thanks man!

@tcharding
Copy link
Member Author

Woops, readme suggestion still to come ...

In markdown triple ticks go on a line of their own. This change does not
effect the rendering in GitHub which is managing to parse this section
correctly already.
@tcharding tcharding force-pushed the 07-11-cfg-nightly branch from 7174117 to 58334cf Compare July 13, 2022 00:10
@tcharding
Copy link
Member Author
tcharding commented Jul 13, 2022

Now includes readme section (and an initial patch fixing up a trivial markdown issue in the readme file). I put it as a sub section of the Building section.

tcharding added a commit to tcharding/rust-secp256k1 that referenced this pull request Jul 13, 2022
As we did in rust-bitcoin [0] create a configuration conditional `bench`
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with `--all-features`
with a stable toolchain (currently this fails because of our use of the
`test` crate).

Please note, this patch maintains the current behaviour of turning on
the `recovery` and `rand-std` features when benching although I was
unable to ascertain why this is needed.

[0] - rust-bitcoin/rust-bitcoin#1092
@tcharding tcharding force-pushed the 07-11-cfg-nightly branch from 58334cf to 64d50b9 Compare July 13, 2022 04:50
@tcharding
Copy link
Member Author

I thought that cfg_docs was not an experimental feature but I was wrong: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html

Force push puts the comment about experimental features back to how it was and groups cfg_docs together with test as it was.

tcharding added a commit to tcharding/rust-secp256k1 that referenced this pull request Jul 13, 2022
As we did in rust-bitcoin [0] create a configuration conditional `bench`
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with `--all-features`
with a stable toolchain (currently this fails because of our use of the
`test` crate).

Please note, this patch maintains the current behaviour of turning on
the `recovery` and `rand-std` features when benching although I was
unable to ascertain why this is needed.

[0] - rust-bitcoin/rust-bitcoin#1092
tcharding added a commit to tcharding/bitcoin_hashes that referenced this pull request Jul 13, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

[0] - rust-bitcoin/rust-bitcoin#1092
tcharding added a commit to tcharding/rust-miniscript that referenced this pull request Jul 13, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

Please note, this patch maintains the current behaviour of turning on
the recovery and rand-std features when benching although I was
unable to ascertain why this is needed.

Maintains the use of `--features=compiler` in `test.sh` and in the
suggested incantation in `README.md`.

[0] - rust-bitcoin/rust-bitcoin#1092
apoelstra
apoelstra previously approved these changes Jul 13, 2022
Copy link
Member
@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 64d50b9a7a187f56a1713c36effd10ea7c45385c

tcharding added a commit to tcharding/rust-secp256k1 that referenced this pull request Jul 13, 2022
As we did in rust-bitcoin [0] create a configuration conditional `bench`
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with `--all-features`
with a stable toolchain (currently this fails because of our use of the
`test` crate).

[0] - rust-bitcoin/rust-bitcoin#1092
Add trivial calls to `cargo` and `rustc` as sanity checks before
starting the script proper.
If CI script is run with `DO_BENCH=true` and `TOOLCHAIN` set to a
non-nightly toolchain the build will fail with a less than meaningful
error. To assist runners of the script output an informative error
message if an attempt is made at using the wrong toolchain.
Currently we are unable to build with all features enabled with a
non-nightly toolchain, this is because of the use of

    `#![cfg_attr(all(test, feature = "unstable"), feature(test))]`

which causes the following error when building:

 error[E0554]: `#![feature]` may not be used on the stable release
 channel

The "unstable" feature is used to guard bench mark modules, this is
widely suggested online but there is a better way.

When running the bench marks use the following incantation:

    `RUSTFLAGS='--cfg=bench' cargo bench`

This creates a configuration conditional "bench" that can be used to
guard the bench mark modules.

    #[cfg(bench)]
    mod benches {
        ...
    }
Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK f3b2120

BTW if we renamed TOOLCHAIN to RUSTUP_TOOLCHAIN we could get rid of alias and possibly it'd be more obvious what it does/how it works.

@tcharding
Copy link
Member Author
tcharding commented Jul 14, 2022

BTW if we renamed TOOLCHAIN to RUSTUP_TOOLCHAIN we could get rid of alias and possibly it'd be more obvious what it does/how it works.

Cool! Added to my todo list as I work on improving CI.

Copy link
Member
@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK f3b2120

@apoelstra
Copy link
Member

@tcharding anything more you wanna add to this PR, or should we merge it?

@tcharding
Copy link
Member Author

Its good to go mate.

@apoelstra apoelstra merged commit bd8d9af into rust-bitcoin:master Jul 17, 2022
@tcharding tcharding deleted the 07-11-cfg-nightly branch July 18, 2022 05:39
apoelstra added a commit to rust-bitcoin/rust-secp256k1 that referenced this pull request Jul 19, 2022
a431edb Create configuration conditional bench (Tobin C. Harding)
2a1c9ab Remove rand-std feature from unstable (Tobin C. Harding)
ddc108c Increase heading size (Tobin C. Harding)
596adff Remove unneeded whitespace (Tobin C. Harding)

Pull request description:

  As we did in rust-bitcoin [0] create a configuration conditional `bench`
  that we can use to guard bench mark code. This has the benefit of
  making our features additive i.e., we can now test with `--all-features`
  with a stable toolchain (currently this fails because of our use of the
  `test` crate).

  Please note, this patch maintains the current behaviour of turning on
  the `recovery` and `rand-std` features when benching although I was
  unable to ascertain why this is needed.

  [0] - rust-bitcoin/rust-bitcoin#1092

ACKs for top commit:
  sanket1729:
    ACK a431edb.
  apoelstra:
    ACK a431edb

Tree-SHA512: 913f5fbe0da08ec649081bf237c1d31cee58dacdac251d6030afabb99d455286c6d1dbdb6b2ac892b5d3c24584933254d1cfeec8e12f531cc420bd9d455a6531
tcharding added a commit to tcharding/bitcoin_hashes that referenced this pull request Jul 20, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

[0] - rust-bitcoin/rust-bitcoin#1092
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
…l "bench"

f3b2120 Create configuration conditional bench (Tobin C. Harding)
f60c92c Add informative error message to DO_BENCH (Tobin C. Harding)
c6d5a12 Add cargo/rustc sanity calls (Tobin C. Harding)
34d5a31 Put triple ticks on their own line (Tobin C. Harding)

Pull request description:

  Currently we are unable to build with all features enabled with a non-nightly toolchain, this is because of the use of

      `#![cfg_attr(all(test, feature = "unstable"), feature(test))]`

  which causes the following error when building:

   error[E0554]: `#![feature]` may not be used on the stable release channel

  The "unstable" feature is used to guard bench mark modules, this is widely suggested online but there is a better way.

  When running the bench marks use the following incantation:

      `RUSTFLAGS='--cfg=bench' cargo bench`

  This creates a configuration conditional "bench" that can be used to guard the bench mark modules.

  ```
  #[cfg(bench)]
  mod benches {
      ...
  }
  ```

ACKs for top commit:
  Kixunil:
    ACK f3b2120
  apoelstra:
    ACK f3b2120

Tree-SHA512: 7ec2a501a30bfe2ce72601077cd675cf5e5ac2f0f93f97fc7e83cb7401606b69ae909b35bfc0ace8bd1ea771ca4fba70e2ad9ac9ba26f2b6e371494cf694c0a8
@Kixunil Kixunil added the Tests label Aug 1, 2022
@Kixunil Kixunil added this to the 0.29.0 milestone Aug 1, 2022
tcharding added a commit to tcharding/bitcoin_hashes that referenced this pull request Aug 9, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

[0] - rust-bitcoin/rust-bitcoin#1092
tcharding added a commit to tcharding/bitcoin_hashes that referenced this pull request Sep 6, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

[0] - rust-bitcoin/rust-bitcoin#1092
apoelstra added a commit to rust-bitcoin/bitcoin_hashes that referenced this pull request Sep 6, 2022
a7b7bed Create configuration conditional bench (Tobin C. Harding)
5f6c7ad Remove unneeded line of whitespace (Tobin C. Harding)

Pull request description:

  As we did in rust-bitcoin [0] create a configuration conditional bench
  that we can use to guard bench mark code. This has the benefit of
  making our features additive i.e., we can now test with --all-features
  with a stable toolchain (currently this fails because of our use of the
  test crate).

  [0] - rust-bitcoin/rust-bitcoin#1092

ACKs for top commit:
  apoelstra:
    ACK a7b7bed

Tree-SHA512: a451e970a543597bd3714e7e9a57cb6325700ff9c3f5e68347a40a37263f95ea16aeaf8beeca0463a27a5f63430d48c2db5b86f7e21f9ee196cf49a9a38c1730
tcharding added a commit to tcharding/rust-miniscript that referenced this pull request Sep 11, 2022
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

Please note, this patch maintains the current behaviour of turning on
the recovery and rand-std features when benching although I was
unable to ascertain why this is needed.

Maintains the use of `--features=compiler` in `test.sh` and in the
suggested incantation in `README.md`.

[0] - rust-bitcoin/rust-bitcoin#1092
arremoEngervetl added a commit to arremoEngervetl/bitcoin_hashes that referenced this pull request Aug 10, 2024
As we did in rust-bitcoin [0] create a configuration conditional bench
that we can use to guard bench mark code. This has the benefit of
making our features additive i.e., we can now test with --all-features
with a stable toolchain (currently this fails because of our use of the
test crate).

[0] - rust-bitcoin/rust-bitcoin#1092
arremoEngervetl added a commit to arremoEngervetl/bitcoin_hashes that referenced this pull request Aug 10, 2024
…al "bench"

79ccdc4 Create configuration conditional bench (Tobin C. Harding)
5335135 Remove unneeded line of whitespace (Tobin C. Harding)

Pull request description:

  As we did in rust-bitcoin [0] create a configuration conditional bench
  that we can use to guard bench mark code. This has the benefit of
  making our features additive i.e., we can now test with --all-features
  with a stable toolchain (currently this fails because of our use of the
  test crate).

  [0] - rust-bitcoin/rust-bitcoin#1092

ACKs for top commit:
  apoelstra:
    ACK 79ccdc4

Tree-SHA512: a451e970a543597bd3714e7e9a57cb6325700ff9c3f5e68347a40a37263f95ea16aeaf8beeca0463a27a5f63430d48c2db5b86f7e21f9ee196cf49a9a38c1730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0