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

move: build writes toolchain version to Move.lock #15166

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

rvantonder
Copy link
Contributor

@rvantonder rvantonder commented Dec 3, 2023

Description

As in title, see inline for more.

Test Plan

Updated tests.


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Toolchain version is now written to a package's Move.lock file on build.

Copy link

vercel bot commented Dec 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2023 2:32am
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2023 2:32am
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2023 2:32am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Dec 8, 2023 2:32am
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Dec 8, 2023 2:32am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Dec 8, 2023 2:32am

@rvantonder rvantonder marked this pull request as ready for review December 3, 2023 06:35
@@ -1,6 +1,6 @@
[package]
name = "sui-move-build"
version = "0.0.0"
version.workspace = true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposes the binary / root crate version in env!("CARGO_PKG_VERSION")

Comment on lines +190 to +196
if modified || install_dir_set {
// (1) Write the Move.lock file if the existing one is `modified`, or
// (2) `install_dir` is set explicitly, which may be a different directory, and where a Move.lock does not exist yet.
Copy link
Contributor Author

@rvantonder rvantonder Dec 4, 2023

Choose a reason for hiding this comment

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

This addresses what I consider a bug: this block writes Move.lock to install_dir when it is modified. If install_dir is set to something other than the current directory (let's say /tmp/foo) and run build, then Move.lock would only be written to install_dir if Move.lock changed. So /tmp/foo would be empty if we build again and a Move.lock exists and is the same as before, but if Move.lock does not exist or changed, then it would be written to /tmp/foo.

We should be writing to /tmp/foo if it install_dir is set (i.e., ensure Move.lock is written when we're not on the default package path). Tests helpfully rely on checking the Move.lock file in install_dir (1) so if the Move.lock doesn't exist there, things break.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reasonable! We should arguably be also looking in the install dir for the lock file that DependencyGraph reads as well, to completely fix this bug, but the difference in behaviour in what you have here vs that is likely an un-exercised edge case, so all good.

Comment on lines +193 to +194
file.set_len(0)?;
file.rewind()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small fix: we need to truncate the file to erase all previous content when updating these values, now covered by test.

Comment on lines +199 to +163
if let Ok(ref compiled) = result {
compiled
.package
.compiled_package_info
.build_flags
.update_lock_file_toolchain_version(&path, env!("CARGO_PKG_VERSION").into())
.map_err(|e| SuiError::ModuleBuildFailure {
error: format!("Failed to update Move.lock toolchain version: {e}"),
})?;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main change.

This is the best place to write lock file logic right now. It is the top level function for source verification and should have all the context we care about before building.

I say "right now" because I'd love to flatten things and have these build steps happen in the external-crates move-package, in one place, which we can do at a later stage.

@rvantonder rvantonder requested review from amnn and a team December 4, 2023 20:53
@rvantonder rvantonder changed the title move: build writes toolchain version into to Move.lock move: build writes toolchain version to Move.lock Dec 5, 2023
Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Comment on lines +190 to +196
if modified || install_dir_set {
// (1) Write the Move.lock file if the existing one is `modified`, or
// (2) `install_dir` is set explicitly, which may be a different directory, and where a Move.lock does not exist yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

Reasonable! We should arguably be also looking in the install dir for the lock file that DependencyGraph reads as well, to completely fix this bug, but the difference in behaviour in what you have here vs that is likely an un-exercised edge case, so all good.

@rvantonder rvantonder merged commit 02f783c into main Dec 8, 2023
39 checks passed
@rvantonder rvantonder deleted the rvt/write-lock-file-3 branch December 8, 2023 23:31
gdanezis pushed a commit that referenced this pull request Dec 15, 2023
## Description 

As in title, see inline for more.

## Test Plan 

Updated tests.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [x] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

- The `Move.lock` file will update with `[move.toolchain-version]` fields when building a package (e.g., with `sui move build`). Please check in and commit changes to the `Move.lock` file as usual.
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