Skip to content

Commit

Permalink
servo: Merge #18325 - Switch back to pinning Rust by Nightly date ins…
Browse files Browse the repository at this point in the history
…tead of commit hash… (from servo:rustup-toolchain); r=nox

… this time using a `rust-toolchain` file compatible with rustup: https://github.com/rust-lang-nursery/rustup.rs/#the-toolchain-file

And upgrade to rustc 1.21.0-nightly (c11f689d2 2017-08-29)

----

Now if both `system-rust` and `system-cargo` are set to `true` in `.servobuild`’s `[tools]` section, and the corresponding `rustc` and `cargo` binaries are in fact rustup’s wrappers, then rustup will use the correct version based on `rust-toolchain`.

CC servo/servo#11361

Unlike servo/servo#17927, this does not make mach use rustup directly. That should wait until rust-lang/rustup#1099 is fixed.

Source-Repo: https://github.com/servo/servo
Source-Revision: c4800a6c83e6fdabaf7c4eff70a24487d16f18ff
  • Loading branch information
SimonSapin committed Aug 31, 2017
1 parent d490142 commit e96dc8b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 87 deletions.
2 changes: 1 addition & 1 deletion servo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Servo's build system automatically downloads a Rust compiler to build itself.
This is normally a specific revision of Rust upstream, but sometimes has a
backported patch or two.
If you'd like to know which nightly build of Rust we use, see
[`rust-commit-hash`](https://github.com/servo/servo/blob/master/rust-commit-hash).
[`rust-toolchain`](https://github.com/servo/servo/blob/master/rust-toolchain).

## Building

Expand Down
4 changes: 2 additions & 2 deletions servo/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ branches:
- master

cache:
- .servo -> rust-commit-hash
- .cargo -> rust-commit-hash
- .servo -> rust-toolchain
- .cargo -> rust-toolchain
- .ccache

# Uncomment these lines to expose RDP access information to the build machine in the build log.
Expand Down
74 changes: 36 additions & 38 deletions servo/python/servo/bootstrap_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,10 @@ def bootstrap(self, force=False):
help='Use stable rustc version')
def bootstrap_rustc(self, force=False, target=[], stable=False):
self.set_use_stable_rust(stable)
version = self.rust_version()
rust_path = self.rust_path()
rust_dir = path.join(self.context.sharedir, "rust", rust_path)
install_dir = path.join(self.context.sharedir, "rust", version)
if not self.config["build"]["llvm-assertions"]:
if not self.use_stable_rust():
install_dir += "-alt"
rust_dir = path.join(self.context.sharedir, "rust", self.rust_path())
install_dir = path.join(self.context.sharedir, "rust", self.rust_install_dir())
version = self.rust_stable_version() if stable else "nightly"
static_s3 = "https://static-rust-lang-org.s3.amazonaws.com/dist"

if not force and path.exists(path.join(rust_dir, "rustc", "bin", "rustc" + BIN_SUFFIX)):
print("Rust compiler already downloaded.", end=" ")
Expand All @@ -90,16 +87,23 @@ def bootstrap_rustc(self, force=False, target=[], stable=False):
# giving a directory name that will be the same as the tarball name (rustc is
# in that directory).
if stable:
tarball = "rustc-%s-%s.tar.gz" % (version, host_triple())
rustc_url = "https://static-rust-lang-org.s3.amazonaws.com/dist/" + tarball
base_url = static_s3
else:
tarball = "%s/rustc-nightly-%s.tar.gz" % (version, host_triple())
import toml
import re
channel = "%s/%s/channel-rust-nightly.toml" % (static_s3, self.rust_nightly_date())
version_string = toml.load(urllib2.urlopen(channel))["pkg"]["rustc"]["version"]
short_commit = re.search("\(([0-9a-f]+) ", version_string).group(1)
commit_api = "https://api.github.com/repos/rust-lang/rust/commits/" + short_commit
nightly_commit_hash = json.load(urllib2.urlopen(commit_api))["sha"]

base_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds"
if not self.config["build"]["llvm-assertions"]:
base_url += "-alt"
rustc_url = base_url + "/" + tarball
tgz_file = rust_dir + '-rustc.tar.gz'
base_url += "/" + nightly_commit_hash

rustc_url = base_url + "/rustc-%s-%s.tar.gz" % (version, host_triple())
tgz_file = rust_dir + '-rustc.tar.gz'
download_file("Rust compiler", rustc_url, tgz_file)

print("Extracting Rust compiler...")
Expand All @@ -111,10 +115,8 @@ def bootstrap_rustc(self, force=False, target=[], stable=False):
# a directory of the name `rust-std-TRIPLE` inside and then a `lib` directory.
# This `lib` directory needs to be extracted and merged with the `rustc/lib`
# directory from the host compiler above.
nightly_suffix = "" if stable else "-nightly"
stable_version = "-{}".format(version) if stable else ""
lib_dir = path.join(install_dir,
"rustc{}{}-{}".format(nightly_suffix, stable_version, host_triple()),
"rustc-%s-%s" % (version, host_triple()),
"rustc", "lib", "rustlib")

# ensure that the libs for the host's target is downloaded
Expand All @@ -130,26 +132,25 @@ def bootstrap_rustc(self, force=False, target=[], stable=False):
print("Use |bootstrap-rust --force| to download again.")
continue

tarball = "rust-std-%s-%s.tar.gz" % (version, target_triple)
tgz_file = path.join(install_dir, tarball)
if self.use_stable_rust():
std_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/rust-std-%s-%s.tar.gz"
% (version, target_triple))
tgz_file = install_dir + ('rust-std-%s-%s.tar.gz' % (version, target_triple))
std_url = static_s3 + "/" + tarball
else:
std_url = ("https://s3.amazonaws.com/rust-lang-ci/rustc-builds/%s/rust-std-nightly-%s.tar.gz"
% (version, target_triple))
tgz_file = install_dir + ('rust-std-nightly-%s.tar.gz' % target_triple)
std_url = static_s3 + "/" + self.rust_nightly_date() + "/" + tarball

download_file("Host rust library for target %s" % target_triple, std_url, tgz_file)
print("Extracting Rust stdlib for target %s..." % target_triple)
extract(tgz_file, install_dir)
shutil.copytree(path.join(install_dir,
"rust-std%s%s-%s" % (nightly_suffix, stable_version, target_triple),
"rust-std-%s" % target_triple, "lib", "rustlib", target_triple),
"rust-std-%s-%s" % (version, target_triple),
"rust-std-%s" % target_triple,
"lib", "rustlib", target_triple),
path.join(install_dir,
"rustc%s%s-%s" % (nightly_suffix, stable_version, host_triple()),
"rustc", "lib", "rustlib", target_triple))
shutil.rmtree(path.join(install_dir,
"rust-std%s%s-%s" % (nightly_suffix, stable_version, target_triple)))
"rustc-%s-%s" % (version, host_triple()),
"rustc",
"lib", "rustlib", target_triple))
shutil.rmtree(path.join(install_dir, "rust-std-%s-%s" % (version, target_triple)))

print("Rust {} libs ready.".format(target_triple))

Expand All @@ -171,8 +172,8 @@ def bootstrap_rustc_docs(self, force=False):
if path.isdir(docs_dir):
shutil.rmtree(docs_dir)
docs_name = self.rust_path().replace("rustc-", "rust-docs-")
docs_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/rust-docs-nightly-%s.tar.gz"
% host_triple())
docs_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/%s/rust-docs-nightly-%s.tar.gz"
% (self.rust_nightly_date(), host_triple()))
tgz_file = path.join(rust_root, 'doc.tar.gz')

download_file("Rust docs", docs_url, tgz_file)
Expand All @@ -195,8 +196,7 @@ def bootstrap_rustc_docs(self, force=False):
action='store_true',
help='Force download even if cargo already exists')
def bootstrap_cargo(self, force=False):
cargo_dir = path.join(self.context.sharedir, "cargo",
self.cargo_build_id())
cargo_dir = path.join(self.context.sharedir, "cargo", self.rust_nightly_date())
if not force and path.exists(path.join(cargo_dir, "cargo", "bin", "cargo" + BIN_SUFFIX)):
print("Cargo already downloaded.", end=" ")
print("Use |bootstrap-cargo --force| to download again.")
Expand All @@ -207,8 +207,8 @@ def bootstrap_cargo(self, force=False):
os.makedirs(cargo_dir)

tgz_file = "cargo-nightly-%s.tar.gz" % host_triple()
nightly_url = "https://s3.amazonaws.com/rust-lang-ci/rustc-builds/%s/%s" % \
(self.cargo_build_id()[len("rust-"):], tgz_file)
nightly_url = "https://static-rust-lang-org.s3.amazonaws.com/dist/%s/%s" % \
(self.rust_nightly_date(), tgz_file)

download_file("Cargo nightly", nightly_url, tgz_file)

Expand Down Expand Up @@ -291,10 +291,8 @@ def bootstrap_pub_suffix(self, force=False):
default='1',
help='Keep up to this many most recent nightlies')
def clean_nightlies(self, force=False, keep=None):
self.set_use_stable_rust(False)
rust_current_nightly = self.rust_version()
self.set_use_stable_rust(True)
rust_current_stable = self.rust_version()
rust_current_nightly = self.rust_nightly_date()
rust_current_stable = self.rust_stable_version()
print("Current Rust nightly version: {}".format(rust_current_nightly))
print("Current Rust stable version: {}".format(rust_current_stable))
to_keep = set()
Expand All @@ -303,7 +301,7 @@ def clean_nightlies(self, force=False, keep=None):
to_keep.add(rust_current_nightly)
to_keep.add(rust_current_stable)
else:
for version_file in ['rust-commit-hash', 'rust-stable-version']:
for version_file in ['rust-toolchain', 'rust-stable-version']:
cmd = subprocess.Popen(
['git', 'log', '--oneline', '--no-color', '-n', keep, '--patch', version_file],
stdout=subprocess.PIPE,
Expand Down
54 changes: 32 additions & 22 deletions servo/python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,13 @@ def resolverelative(category, key):
self.set_use_stable_rust(False)

_use_stable_rust = False
_rust_version = None
_rust_version_is_stable = False
_cargo_build_id = None
_rust_stable_version = None
_rust_nightly_date = None

def set_cargo_root(self):
if not self.config["tools"]["system-cargo"]:
self.config["tools"]["cargo-root"] = path.join(
self.context.sharedir, "cargo", self.cargo_build_id())
self.context.sharedir, "cargo", self.rust_nightly_date())

def set_use_stable_rust(self, use_stable_rust=True):
self._use_stable_rust = use_stable_rust
Expand All @@ -308,28 +307,39 @@ def set_use_stable_rust(self, use_stable_rust=True):
def use_stable_rust(self):
return self._use_stable_rust

def rust_install_dir(self):
if self._use_stable_rust:
return self.rust_stable_version()
elif not self.config["build"]["llvm-assertions"]:
return self.rust_nightly_date() + "-alt"
else:
return self.rust_nightly_date()

def rust_path(self):
version = self.rust_version()
if self._use_stable_rust:
return os.path.join(version, "rustc-%s-%s" % (version, host_triple()))
if not self.config["build"]["llvm-assertions"]:
version += "-alt"
return os.path.join(version, "rustc-nightly-%s" % (host_triple()))

def rust_version(self):
if self._rust_version is None or self._use_stable_rust != self._rust_version_is_stable:
filename = path.join(self.context.topdir,
"rust-stable-version" if self._use_stable_rust else "rust-commit-hash")
version = self.rust_stable_version()
else:
version = "nightly"

subdir = "rustc-%s-%s" % (version, host_triple())
return os.path.join(self.rust_install_dir(), subdir)

def rust_stable_version(self):
if self._rust_stable_version is None:
filename = path.join("rust-stable-version")
with open(filename) as f:
self._rust_version = f.read().strip()
return self._rust_version
self._rust_stable_version = f.read().strip()
return self._rust_stable_version

def cargo_build_id(self):
if self._cargo_build_id is None:
filename = path.join(self.context.topdir, "rust-commit-hash")
def rust_nightly_date(self):
if self._rust_nightly_date is None:
filename = path.join(self.context.topdir, "rust-toolchain")
with open(filename) as f:
self._cargo_build_id = "rust-" + f.read().strip()
return self._cargo_build_id
toolchain = f.read().strip()
prefix = "nightly-"
assert toolchain.startswith(prefix)
self._rust_nightly_date = toolchain[len(prefix):]
return self._rust_nightly_date

def get_top_dir(self):
return self.context.topdir
Expand Down Expand Up @@ -587,7 +597,7 @@ def ensure_bootstrapped(self, target=None):
Registrar.dispatch("bootstrap", context=self.context)

if not (self.config['tools']['system-rust'] or (rustc_binary_exists and target_exists)):
print("looking for rustc at %s" % (rustc_path))
print("Looking for rustc at %s" % (rustc_path))
Registrar.dispatch("bootstrap-rust", context=self.context, target=filter(None, [target]),
stable=self._use_stable_rust)

Expand Down
30 changes: 7 additions & 23 deletions servo/python/servo/devenv_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def update_cargo(self, params=None, package=None, all_packages=None, dry_run=Non

if dry_run:
import toml
import json
import httplib
import colorama

Expand Down Expand Up @@ -262,31 +261,16 @@ def grep(self, params):
@Command('rustup',
description='Update the Rust version to latest Nightly',
category='devenv')
@CommandArgument('--master',
action='store_true',
help='Use the latest commit of the "master" branch')
def rustup(self, master=False):
if master:
url = "https://api.github.com/repos/rust-lang/rust/git/refs/heads/master"
commit = json.load(urllib2.urlopen(url))["object"]["sha"]
else:
import toml
import re
url = "https://static.rust-lang.org/dist/channel-rust-nightly.toml"
version = toml.load(urllib2.urlopen(url))["pkg"]["rustc"]["version"]
short_commit = re.search("\(([0-9a-f]+) ", version).group(1)
url = "https://api.github.com/repos/rust-lang/rust/commits/" + short_commit
commit = json.load(urllib2.urlopen(url))["sha"]
filename = path.join(self.context.topdir, "rust-commit-hash")
def rustup(self):
url = "https://static.rust-lang.org/dist/channel-rust-nightly-date.txt"
nightly_date = urllib2.urlopen(url).read()
filename = path.join(self.context.topdir, "rust-toolchain")
with open(filename, "w") as f:
f.write(commit + "\n")
f.write("nightly-%s\n" % nightly_date)

# Reset self.config["tools"]["rust-root"]
self._rust_version = None
# Reset self.config["tools"]["rust-root"] and self.config["tools"]["cargo-root"]
self._rust_nightly_date = None
self.set_use_stable_rust(False)

# Reset self.config["tools"]["cargo-root"]
self._cargo_build_id = None
self.set_cargo_root()

self.fetch()
Expand Down
1 change: 0 additions & 1 deletion servo/rust-commit-hash

This file was deleted.

1 change: 1 addition & 0 deletions servo/rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly-2017-08-30

0 comments on commit e96dc8b

Please sign in to comment.