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

Build determinism in CI #324

Merged
merged 3 commits into from
Aug 3, 2020
Merged

Build determinism in CI #324

merged 3 commits into from
Aug 3, 2020

Conversation

kylefleming
Copy link
Contributor

@kylefleming kylefleming commented Jul 28, 2020

Motivation

Cargo build caches build artifacts so that successive invocations won't rebuild the parts of the code that haven't changed. Currently our project is experiencing spurious rebuilds even when nothing has changed. This leads to slower development cycles.

On top of the spurious rebuilds, the build is also experience build non-determinism. Crate feature selection doesn't appear to be consistent across multiple successive builds under certain circumstances (e.g. when building more than a single package at a time). This is a problem because it means that we might be encountering bugs related to incorrect feature configuration. This also has the potential to mask bugs for the same reason.

In this PR

This PR addresses several of the issues causing spurious rebuilds and build non-determinism:

  • mc-util-build-enclave emits rerun-if-changed directives based on files in the filesystem. However, currently the files aren't sorted, leading Cargo to think that the build inputs have changed, thus invoking a rebuild. This PR adds sorting to the file iteration so that they're always printed in the same order.
  • Cargo's new resolver feature allows isolating feature unification between build dependencies, target dependencies, and dev dependencies. However, there is a bug within Cargo stemming from overeager caching of feature configuration, leading to incorrect feature selection under certain circumstances. See MC-1731 and Non-deterministic builds with new resolver rust-lang/cargo#8549 for more detail. This PR adds the suggested workaround to our CI builds, which is to add --target when invoking cargo.
  • Additionally, there is a similar issue when running cargo test with the default settings, where feature unification appears to be non-deterministic. A workaround for this is applied to CI, which is to add --tests when calling cargo test. Typically, when calling cargo test with the default settings, cargo will build the project in a number of different ways (see https://doc.rust-lang.org/cargo/commands/cargo-test.html), and then test the tests. By specifying --tests, Cargo is instructed to build only the tests, and then run them. This prevents feature configuration from other types of builds from being impacted by this bug and affecting the feature selection of the test build.

Future Work

@kylefleming kylefleming force-pushed the fix-build-determinism branch 26 times, most recently from 923eff9 to 8e476b3 Compare July 30, 2020 09:03
@kylefleming kylefleming force-pushed the fix-build-determinism branch 2 times, most recently from aad85d3 to e493a8b Compare July 31, 2020 08:10
@kylefleming kylefleming force-pushed the fix-build-determinism branch from e493a8b to d940e08 Compare July 31, 2020 17:22
@kylefleming kylefleming changed the title [WIP] Build determinism in CI Build determinism in CI Jul 31, 2020
@kylefleming kylefleming requested review from sugargoat, eranrund, joekottke and a team July 31, 2020 18:09
@kylefleming kylefleming marked this pull request as ready for review July 31, 2020 18:09
Copy link
Contributor

@eranrund eranrund left a comment

Choose a reason for hiding this comment

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

Nice!

@kylefleming kylefleming merged commit d201dff into master Aug 3, 2020
@kylefleming kylefleming deleted the fix-build-determinism branch August 3, 2020 17:41
@kylefleming kylefleming restored the fix-build-determinism branch August 3, 2020 17:41
@kylefleming kylefleming deleted the fix-build-determinism branch August 3, 2020 17:41
@kylefleming kylefleming restored the fix-build-determinism branch August 3, 2020 17:42
@kylefleming kylefleming deleted the fix-build-determinism branch August 3, 2020 17:42
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.

3 participants