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

chore: check each feature works properly #1695

Merged
merged 18 commits into from
Nov 1, 2019
Merged

chore: check each feature works properly #1695

merged 18 commits into from
Nov 1, 2019

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Oct 26, 2019

The current tests for each feature gate do not work properly because the default feature is enabled by dev-dependencies.

The cause of this is rust-lang/cargo#4866, but it seems difficult to fix on the cargo side.
So remove all dev-dependencies in CI to avoid this issue. This is basically the same as rust-lang/futures-rs#1456 (comment). EDIT2 see #1695 (comment)

Also, this change test to run only once with all-features instead of running tests for each feature. EDIT: see #1695 (comment)

Closes #1693

Refs:

@taiki-e
Copy link
Member Author

taiki-e commented Oct 26, 2019

Also, this change test to run only once with all-features instead of running tests for each feature.

Oh, this is not good. It needs to keep the existing one for tests-build.

EDIT: fixed in 3eebedc

@taiki-e
Copy link
Member Author

taiki-e commented Oct 26, 2019

hmm...

error[E0432]: unresolved import `tokio_sync`
 --> tokio/src/net/driver/reactor.rs:4:5
  |
4 | use tokio_sync::AtomicWaker;
  |     ^^^^^^^^^^ use of undeclared type or module `tokio_sync`

error[E0432]: unresolved import `slab`
 --> tokio/src/net/driver/reactor.rs:7:5
  |
7 | use slab::Slab;
  |     ^^^^ help: a similar path exists: `mio::slab`

error[E0432]: unresolved import `crate::io`
 --> tokio/src/net/util/poll_evented.rs:1:12
  |
1 | use crate::io::{AsyncRead, AsyncWrite};
  |            ^^
  |            |
  |            unresolved import
  |            help: a similar path exists: `std::io`

@carllerche
Copy link
Member

Thanks. I haven't reviewed yet. However, I want to quickly point out that tests-build exists to work around the cargo limitations and test the various cargo feature combos. These tests have gone out of date w/ the recent churn though.

@taiki-e
Copy link
Member Author

taiki-e commented Oct 26, 2019

However, I want to quickly point out that tests-build exists to work around the cargo limitations and test the various cargo feature combos. These tests have gone out of date w/ the recent churn though.

tests-build's approach requires all tests to be written manually. Also, we need to write tests for each platform for some crates (see 7aee1f8).

But I'd like to try tests-build as another pr because it seems help reduce CI time.

@carllerche
Copy link
Member

@taiki-e I wasn't making a comment on your PR yet, just providing context :) I will probably review on monday.

@taiki-e
Copy link
Member Author

taiki-e commented Oct 27, 2019

UPDATE: It is very hard to maintain these tests manually, so I'm writing a tool to make these checks run in one line :)

@carllerche
Copy link
Member

👍 Should I merge this then or wait?

@carllerche
Copy link
Member

Also, is the plan to get rid of tests-build or have something else with it?

It is hard to maintain features list manually, so use cargo-hack's
`--each-feature` flag. And cargo-hack provides a workaround for an issue
that dev-dependencies leaking into normal build (`--no-dev-deps` flag),
so removed own ci tool.

Also, compared to running tests on all features, there is not much
advantage in running tests on each feature, so only the default features
and all features are tested.
If the behavior changes depending on the feature, we need to test it as
another job in CI.
this is no longer necessary
It seems rustfmt does not properly format the module in the macro.
@taiki-e
Copy link
Member Author

taiki-e commented Oct 30, 2019

I wrote https://github.com/taiki-e/cargo-hack to improve feature flag testing.
cargo-hack is basically wrapper of cargo that propagates subcommand and provides additional flags to avoid some of the limitations of cargo. e.g.:

By using these two features, you can easily test the feature flag gate:

$ cargo hack check --each-feature --no-dev-deps
output:

("info: running cargo check ... on tokio" shows what command is actually being executed.)

info: running `cargo check` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 23.38s
info: running `cargo check --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
info: running `cargo check --features=executor-core --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.31s
info: running `cargo check --features=blocking --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 1.13s
info: running `cargo check --features=fs --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 1.67s
info: running `cargo check --features=io-traits --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.24s
info: running `cargo check --features=io-util --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.79s
info: running `cargo check --features=io --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.81s
info: running `cargo check --features=macros --no-default-features` on tokio
   Compiling proc-macro2 v1.0.6
   Compiling syn v1.0.7
   Compiling quote v1.0.2
   Compiling tokio-macros v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio-macros)
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 12.47s
info: running `cargo check --features=net-full --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.76s
info: running `cargo check --features=net-driver --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 1.73s
info: running `cargo check --features=rt-current-thread --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.43s
info: running `cargo check --features=rt-full --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 4.50s
info: running `cargo check --features=signal --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 1.79s
info: running `cargo check --features=sync --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 0.94s
info: running `cargo check --features=tcp --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.45s
info: running `cargo check --features=timer --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 1.60s
info: running `cargo check --features=udp --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.41s
info: running `cargo check --features=uds --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.53s
info: running `cargo check --features=process --no-default-features` on tokio
    Checking tokio v0.2.0-alpha.6 (/home/vsts/work/1/s/tokio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.70s

This will remove the need to manually list feature flags and tests-build should no longer be needed.

Many features of current cargo-hack are not available on windows.

Refs: taiki-e/cargo-hack#3
examples: []

# Test compilation failure
# Disable pending: https://github.com/tokio-rs/tokio/pull/1695#issuecomment-547045383
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed :)

displayName: ${{ crate }} - cargo hack check --each-feature
workingDirectory: $(Build.SourcesDirectory)/${{ crate }}
# FIXME(taiki-e): many features of current cargo-hack are not available on windows: https://github.com/taiki-e/cargo-hack/issues/3
condition: not(eq(variables['Agent.OS'], 'Windows_NT'))
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, many features of current cargo-hack are not available on windows. (taiki-e/cargo-hack#3)

Copy link
Member Author

Choose a reason for hiding this comment

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

However, it seems many features are not directly related to OS-specific dependencies (7aee1f8), so for now, I think this is almost all right.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to fix this in taiki-e/cargo-hack#6, but I couldn't fix it completely.

@taiki-e
Copy link
Member Author

taiki-e commented Oct 30, 2019

BTW, another benefit is that CI time is significantly reduced. (see also 6bee4d8)

@taiki-e
Copy link
Member Author

taiki-e commented Oct 31, 2019

@carllerche Updated PR to use cargo-hack. Could you review it again?

@taiki-e taiki-e mentioned this pull request Oct 31, 2019
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

👍 Thanks. We can try it and see how it goes.

I will probably bring back tests-build at some point so we can check that types exist or don't exist w/ various feature flags.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

This seems good to me.

IMO, the CI build is quite complex and it would be good to have some more documentation of what it's actually doing. I don't think that's a blocker, though.

@@ -20,6 +20,11 @@ jobs:
# rust_version: stable
rust_version: ${{ parameters.rust }}

- script: cargo install cargo-hack
Copy link
Member

Choose a reason for hiding this comment

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

This is nitpicky, but it might be helpful to have a comment here explaining what we're using cargo-hack for and why?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote descriptions for 'check' scripts, but if necessary, I'd happy to add a description to the 'install' script.

# Check each specified feature works properly
# * --each-feature - run for each feature which includes --no-default-features and default features of package
# * --no-dev-deps - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- script: cargo hack check --each-feature --no-dev-deps

# Check each specified feature works properly
# * --each-feature - run for each feature which includes --no-default-features and default features of package
# * --no-dev-deps - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- script: cargo hack check --each-feature --no-dev-deps

@carllerche carllerche merged commit 02f7264 into tokio-rs:master Nov 1, 2019
@taiki-e taiki-e deleted the dev-deps branch November 1, 2019 04:30
@taiki-e
Copy link
Member Author

taiki-e commented Nov 1, 2019

@carllerche @hawkw Thanks for the review!

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.

tokio "fs" feature should depend on tokio-io
3 participants