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

Update getting-started.sh to install the specific rust version specified in .github/env file #5317

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

Wolfenheimm
Copy link

@Wolfenheimm Wolfenheimm commented Aug 12, 2024

Description

Add a means to fetch and install the expected rust version defined in .github/env for the getting-started script, as requested in Issue #5263. Discussions were made and the use of a rust-toolchain.toml file was decided.

Integration

The implementation relies on fetching the rust-toolchain.toml found within the polkadot-sdk repo.

Review Notes

  • Currently, there is no such rust-toolchain.toml file - but an issue has been made to create one #5335. The file has been added to this PR with basic requirements.
  • This PR is intended to resolve #5263 and #5335

Checklist

  • My PR includes a detailed description as outlined in the "Description" and its two subsections above.
  • My PR follows the labeling requirements of this project (at minimum one label for T
    required)
    • External contributors: ask maintainers to put the right label on your PR.
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Aug 12, 2024

User @Wolfenheimm, please sign the CLA here.

@bkchr bkchr requested a review from kianenigma August 12, 2024 18:35
@bkchr bkchr added the R0-silent Changes should not be mentioned in any release notes label Aug 12, 2024
@Wolfenheimm
Copy link
Author

Wolfenheimm commented Aug 12, 2024

Updated the code to include installing the latest version of rust if the required version wasn't found.

I've chosen to do a check on the version that is retrieved for an empty string or if the string doesn't contain dots - if the variable passes those constraints, it just defaults to the latest version of rust. My original fix didn't take into account for a bad version fetch.

@@ -114,8 +114,16 @@ if command -v rustc >/dev/null 2>&1; then
echo "\n✅︎🦀 Rust already installed."
else
if prompt_default_yes "\n🦀 Rust is not installed. Install it?"; then
echo "🦀 Installing via rustup."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
version=`cat ../.github/env | grep IMAGE | cut -d'-' -f3`
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems flaky to me, any change to the other file will break this.

I think the nicer thing to do is to store this in a nicely discover-able variable, and have it be used in both places.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect @alvicsam to know if my worry here is real or not, perhaps it is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine as a temporary solution for now, in the future it should be switched to using rust-toolchain.toml

Copy link
Contributor

Choose a reason for hiding this comment

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

in the future it should be switched to using rust-toolchain.toml

is this tracked in an issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, here: #5335

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for @alvicsam for chiming in.

Copy link

Review required! Latest push from author must always be reviewed

@Wolfenheimm
Copy link
Author

@alvicsam & @kianenigma, sorry for the inconvenience here, I just wanted to keep the branch updated and clear some fails - will refrain from touching it from now on.

@@ -114,8 +114,16 @@ if command -v rustc >/dev/null 2>&1; then
echo "\n✅︎🦀 Rust already installed."
else
if prompt_default_yes "\n🦀 Rust is not installed. Install it?"; then
echo "🦀 Installing via rustup."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
version=`cat ../.github/env | grep IMAGE | cut -d'-' -f3`
Copy link
Contributor

Choose a reason for hiding this comment

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

But also, this won't if you are not in the polkadot sdk repo right? this .github/env is not available otherwise.

In other words, have you tried the outcome, and does it actually works?

Copy link
Author

@Wolfenheimm Wolfenheimm Aug 19, 2024

Choose a reason for hiding this comment

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

I'm just now noticing that the curl, even if the version is defined, will always grab latest.

It requires something like:
rustup default 1.77.0

I pushed some changes.

Also you are right in that if you run this script from outside the repo, you will not get the required version, and it will default to using latest, tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would argue that 99% of the users running this script are outside of the repo (recall the script is meant to onboard a new user), so I think the solution presented here is really marginally better than not having it.

I think that having a rust-toolchain file is probably the better approach. In that case all devs can inspect this file and adjust their rust versions accordingly. Hopefully IDEs can even automatically warn you about it.

Copy link
Author

@Wolfenheimm Wolfenheimm Aug 20, 2024

Choose a reason for hiding this comment

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

True, and it could create complications if my proposed script (God forbid) finds "1.2.0" and installs + uses that version.

It might then be useful to add the following line to fetch the toml file directly from polkadot-sdk, once it's added in:

curl -s -H "Accept:application/vnd.github.v3.raw" https://api.github.com/repos/paritytech/polkadot-sdk/contents/rust-toolchain.toml | grep 'channel =' | awk -F'"' '{print $2}'

I pushed an example of this.

Copy link
Author

Choose a reason for hiding this comment

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

@kianenigma - After some guidance from Nazar, a decision was made to pull the rust-toolchain.toml from polkadot-sdk straight into the minimal-template fetched at the end of the script, which should satisfy the requirement. This PR now contains a base toml file with the required version to support this.

echo "🦀 Setting up Rust environment."
rustup default stable
rustup default $version
Copy link
Contributor

@nazar-pc nazar-pc Aug 20, 2024

Choose a reason for hiding this comment

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

This command is not necessary at all, it'll use version from rust-toolchain.toml. In fact by running this command you revert the effect of rust-toolchain.toml, inviting user confusion down the line as the version in rust-toolchain.toml keeps changing, while this override stays the same.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, I originally decided to pull the toml file in completely, however Kian raised a point earlier that folks could grab this script and run it from anywhere, not necessarily in their project, but simply as a means to set up their dev env. Suppose that they don't have a rust-toolchain.toml in their project, then it would use the latest stable - which we want to avoid.

Copy link
Author

Choose a reason for hiding this comment

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

But you're right, since the script potentially brings in the minimal template, maybe the rust-toolchain.toml could be added to the minimal template as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Again, having this line alone defeats the purpose of having rust-toolchain.toml completely. They will get an unexpected version of the toolchain and if they are really as unexperienced as this script assumes, they will have no idea why.

Maybe consider copying rust-toolchain.toml if it does not yet exists or something, though except for contributions to polkadot-sdk they don't have to use the same exact version, any current or newer stable toolchain will work just fine, hence suggestion to remove this completely.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for all the input, I've pushed some changes to accommodate that. It will pull the toml directly into the minimal template folder that gets generated by the script.

rust-toolchain.toml Outdated Show resolved Hide resolved
echo "🦀 Setting up Rust environment."
rustup default $version
rustup default stable
Copy link
Contributor

@nazar-pc nazar-pc Aug 20, 2024

Choose a reason for hiding this comment

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

But this is still setting default toolchain 😕

This line should not be necessary, just like the rest of commands in this block, rust-toolchain.toml will take care of it all.

Copy link
Author

Choose a reason for hiding this comment

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

I was so sure I fixed that... One moment

Copy link
Author

Choose a reason for hiding this comment

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

Removed the entire block, as discussed

@github-actions github-actions bot requested a review from nazar-pc August 20, 2024 15:03
@Wolfenheimm
Copy link
Author

Wolfenheimm commented Aug 24, 2024

Good morning @kianenigma & @alvicsam,

You two and @nazar-pc have all raised some fantastic points when I picked this up, big thanks to all of you -> I believe this solves both issues (#5263 and #5335). I tested the fetch via test on a different repo that had a rust-toolchain.toml. Please let me know if there is anything missing or perhaps some changes to be made, looking forward to hearing from you!

@Wolfenheimm
Copy link
Author

@kianenigma would you need any extra features for this?

Changed the rust version to reflect  [paritytech#5676](paritytech#5676)
@Wolfenheimm
Copy link
Author

Wolfenheimm commented Sep 26, 2024

  • Update to accommodate changes made to getting-started.sh in main.
  • Changed Rust version to 1.81.0 in the toolchain in preparation for #5676 (Unmerged)

We need another review @nazar-pc, @alvicsam, @kianenigma, but perhaps we wait for #5676👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Startup script: Use the CI rust version of polkadot-sdk
5 participants