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

Use environment variable for force rustup toolchain version #322

Merged
merged 5 commits into from
Mar 23, 2017

Conversation

alevy
Copy link
Member

@alevy alevy commented Mar 22, 2017

rustup looks at the RUSTUP_TOOLCHAIN variable first to figure out
which toolchain to use (e.g. nightly-2017-01-25). Using this
environment variable avoids requiring developers building the kernel to
configure toolchain themselves.

Solves #321

@alevy alevy requested a review from ppannuto March 22, 2017 18:30
Makefile.common Outdated
@@ -33,7 +35,7 @@ endif

# Check that rustc is the right nightly - warn not error if wrong, sometimes useful to test others
RUSTC_VERSION_STRING := rustc 1.16.0-nightly (83c2d9523 2017-01-24)
ifneq ($(shell rustc --version),$(RUSTC_VERSION_STRING))
ifneq ($(shell RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustc --version),$(RUSTC_VERSION_STRING))
$(warning Unexpected rustc version. Expected $(RUSTC_VERSION_STRING) got $(shell rustc --version))
$(warning You may experience unexpected compilation warnings or errors)
$(warning To fix, run `rustup override set nightly-2017-01-25`)
Copy link
Member

Choose a reason for hiding this comment

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

Should we change this line to just suggest installing rustup instead of suggesting running override?

Also, if I've done an override and this env variable is set - who wins? Importantly, if the env variable wins, we need to have an escape hatch to let people try building with different versions briefly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an escape hatch (will squash the commit):

$ make RUSTUP_VERSION=some-other-version

Copy link
Member

Choose a reason for hiding this comment

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

Suggest some best practice in place of the To fix language?

something like - "To fix Install rustup. Remove any overrides you may have set if rustup was previously installed"

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, but I just pointed to https://rustup.rs for installation. RUSTUP_TOOLCHAIN takes precedence over rustup override.

@ppannuto
Copy link
Member

Leaving this note here for the annals of history. In make $(shell's do not inherit exported environment variables, but recipe commands do:

http://stackoverflow.com/questions/2838715/makefile-variable-initialization-and-export

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

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

Seems to work great for me.

@bradjc
Copy link
Contributor

bradjc commented Mar 22, 2017

You should update getting_started

@ppannuto
Copy link
Member

Really all of these:

$ git grep override
doc/Getting_Started.md:Then override the default version of Rust to use for Tock by running the
doc/Getting_Started.md:$ rustup override set nightly-2017-01-25
vagrant/Vagrantfile:    source ~/.profile && cd /tock && rustup override set nightly-2017-01-25

`rustup` looks at the `RUSTUP_TOOLCHAIN` variable first to figure out
which toolchain to use (e.g. `nightly-2017-01-25`). Using this
environment variable avoids requiring developers building the kernel to
configure toolchain themselves.
@alevy
Copy link
Member Author

alevy commented Mar 22, 2017

Done, but it turns out not to be as sweet as we thought, you still need to manually install that version (which override does automatically). It's still nice that you don't have to get the override in the exact right directory and the failure mode is a bit less baffling, so probably still useful.

@bradjc
Copy link
Contributor

bradjc commented Mar 22, 2017

Can't make run rustup for you?

@alevy
Copy link
Member Author

alevy commented Mar 22, 2017

OK, how's that?

Makefile.common Outdated
ifneq ($(shell rustc --version),$(RUSTC_VERSION_STRING))
$(warning Unexpected rustc version. Expected $(RUSTC_VERSION_STRING) got $(shell rustc --version))
ifeq ($(shell rustup -V &> /dev/null && echo success),success)
DUMMY := $(shell rustup install $(RUSTUP_TOOLCHAIN))
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to fail / bail out here somehow if the install fails. Make doesn't care if the sub $(shell exits with an error code:

$ cat Makefile
FOO := /bin/false

all:
	echo hi
[-bash] Wed 22 Mar 16:21 [/tmp/m]
$ make
echo hi
hi

Copy link
Member Author

Choose a reason for hiding this comment

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

any thoughts on how to do this?

Copy link
Member Author

Choose a reason for hiding this comment

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

How about this:

RUSTC_VERSION_STRING := rustc 1.16.0-nightly (83c2d9523 2017-01-24)
ifneq ($(shell rustup -V &> /dev/null && rustup install $(RUSTUP_TOOLCHAIN) 1>&2 && echo success),success)
  ifneq ($(shell RUST_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustc --version), $(RUSTC_VERSION_STRING))
    $(warning You do not have the correct version of `rustc` configured, and `rustup` is not installed.)
    $(warning Expected `rustc` version "$(RUSTC_VERSION_STRING)" but got "$(shell rustc --version)")
    $(warning You may experience unexpected compilation warnings or errors)
    $(warning To fix, install `rustup` from https://rustup.rs/, then run: `rustup install $(RUSTUP_TOOLCHAIN)`)
  endif
endif

Copy link
Member

Choose a reason for hiding this comment

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

Like the new language

It's a bit hacky, but the solution that jumps to mind is to just nest the checks:

ifeq ($(shell rustup -V &> /dev/null && echo success),success)
    DUMMY := $(shell rustup install $(RUSTUP_TOOLCHAIN))
    ifneq ($(shell RUST_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustc --version), $(RUSTC_VERSION_STRING))
        $(error rustup failed. SAD)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oic... how about this:

the logic is:

  1. check to see if the expected version of rustc is installed (we don't care how, on the path? cool. from rustup? cool).
  2. if not, just blindly try installing with rustup.
  3. check again
  4. if after all that, it's not installed, spit out the warning.

It involves the same check twice, but meh...

RUSTC_VERSION_STRING := rustc 1.16.0-nightly (83c2d9523 2017-01-24)
ifneq ($(shell RUST_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustc --version), $(RUSTC_VERSION_STRING))
  DUMMY := $(shell rustup install $(RUSTUP_TOOLCHAIN))
  ifneq ($(shell RUST_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) rustc --version), $(RUSTC_VERSION_STRING))
    $(warning You do not have the correct version of `rustc` configured, and `rustup` is not installed.)
    $(warning Expected `rustc` version "$(RUSTC_VERSION_STRING)" but got "$(shell rustc --version)")
    $(warning You may experience unexpected compilation warnings or errors)
    $(warning To fix, install `rustup` from https://rustup.rs/, then run: `rustup install $(RUSTUP_TOOLCHAIN)`)
  endif
endif

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that looks perfect

@bradjc
Copy link
Contributor

bradjc commented Mar 22, 2017

What if we make our getting_started specify that rustup is the dependency, and not rust. The we can update just with the makefile.

@alevy
Copy link
Member Author

alevy commented Mar 23, 2017

OK, took another pass. Whoever merges, if it's ready, please squash the commits?

@bradjc bradjc merged commit 050d9f1 into tock:master Mar 23, 2017
@ppannuto
Copy link
Member

Nice @alevy, thanks -- sorry to turn a two-line change into so much work 🤕

@alevy alevy deleted the rustup branch March 23, 2017 19:59
@ppannuto ppannuto mentioned this pull request Mar 24, 2017
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