diff options
-rw-r--r-- | ports/stable-rust/.gitignore | 1 | ||||
-rw-r--r-- | ports/stable-rust/Cargo.toml | 6 | ||||
-rw-r--r-- | ports/stable-rust/src/lib.rs | 10 | ||||
-rw-r--r-- | python/servo/bootstrap_commands.py | 58 | ||||
-rw-r--r-- | python/servo/build_commands.py | 37 | ||||
-rw-r--r-- | python/servo/command_base.py | 40 | ||||
-rw-r--r-- | rust-stable-version | 1 |
7 files changed, 125 insertions, 28 deletions
diff --git a/ports/stable-rust/.gitignore b/ports/stable-rust/.gitignore new file mode 100644 index 00000000000..ea8c4bf7f35 --- /dev/null +++ b/ports/stable-rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/ports/stable-rust/Cargo.toml b/ports/stable-rust/Cargo.toml new file mode 100644 index 00000000000..6240d6e0632 --- /dev/null +++ b/ports/stable-rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "stable-rust" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[dependencies] diff --git a/ports/stable-rust/src/lib.rs b/ports/stable-rust/src/lib.rs new file mode 100644 index 00000000000..6bbd4e4ce37 --- /dev/null +++ b/ports/stable-rust/src/lib.rs @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#[cfg(test)] +mod test { + #[test] + fn it_works() { + } +} diff --git a/python/servo/bootstrap_commands.py b/python/servo/bootstrap_commands.py index 373dc4ebbf0..27ac96ff97d 100644 --- a/python/servo/bootstrap_commands.py +++ b/python/servo/bootstrap_commands.py @@ -131,11 +131,20 @@ class MachCommands(CommandBase): action='append', default=[], help='Download rust stdlib for specified target') - def bootstrap_rustc(self, force=False, target=[]): - rust_dir = path.join( - self.context.sharedir, "rust", self.rust_path()) - date = self.rust_path().split("/")[0] - install_dir = path.join(self.context.sharedir, "rust", date) + @CommandArgument('--stable', + action='store_true', + 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() + if stable: + rust_dir = path.join( + self.context.sharedir, "rust", version, rust_path) + else: + rust_dir = path.join( + self.context.sharedir, "rust", rust_path) + install_dir = path.join(self.context.sharedir, "rust", version) if not force and path.exists(path.join(rust_dir, "rustc", "bin", "rustc" + BIN_SUFFIX)): print("Rust compiler already downloaded.", end=" ") @@ -145,12 +154,15 @@ class MachCommands(CommandBase): shutil.rmtree(rust_dir) os.makedirs(rust_dir) - # The Rust compiler is hosted on the nightly server under the date with a name - # rustc-nightly-HOST-TRIPLE.tar.gz. We just need to pull down and extract it, + # The nightly Rust compiler is hosted on the nightly server under the date with a name + # rustc-nightly-HOST-TRIPLE.tar.gz, whereas the stable compiler is named + # rustc-VERSION-HOST-TRIPLE.tar.gz. We just need to pull down and extract it, # giving a directory name that will be the same as the tarball name (rustc is # in that directory). - rustc_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/%s.tar.gz" - % self.rust_path()) + if stable: + rustc_url = "https://static.rust-lang.org/dist/%s.tar.gz" % rust_path + else: + rustc_url = "https://static-rust-lang-org.s3.amazonaws.com/dist/%s.tar.gz" % rust_path tgz_file = rust_dir + '-rustc.tar.gz' download_file("Rust compiler", rustc_url, tgz_file) @@ -159,11 +171,15 @@ class MachCommands(CommandBase): extract(tgz_file, install_dir) print("Rust compiler ready.") - # Each Rust stdlib has a name of the form `rust-std-nightly-TRIPLE.tar.gz`, with + # Each Rust stdlib has a name of the form `rust-std-nightly-TRIPLE.tar.gz` for the nightly + # releases, or rust-std-VERSION-TRIPLE.tar.gz for stable releases, with # 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. - lib_dir = path.join(install_dir, "rustc-nightly-{}".format(host_triple()), + 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", "lib", "rustlib") # ensure that the libs for the host's target is downloaded @@ -179,18 +195,26 @@ class MachCommands(CommandBase): print("Use |bootstrap-rust --force| to download again.") continue - std_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/%s/rust-std-nightly-%s.tar.gz" - % (date, target_triple)) - tgz_file = install_dir + ('rust-std-nightly-%s.tar.gz' % target_triple) + if self.use_stable_rust(): + std_url = ("https://static.rust-lang.org/dist/rust-std-%s-%s.tar.gz" + % (version, target_triple)) + tgz_file = install_dir + ('rust-std-%s-%s.tar.gz' % (version, target_triple)) + else: + std_url = ("https://static-rust-lang-org.s3.amazonaws.com/dist/%s/rust-std-nightly-%s.tar.gz" + % (version, target_triple)) + tgz_file = install_dir + ('rust-std-nightly-%s.tar.gz' % target_triple) 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-nightly-%s" % target_triple, + 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), - path.join(install_dir, "rustc-nightly-%s" % host_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-nightly-%s" % target_triple)) + shutil.rmtree(path.join(install_dir, + "rust-std%s%s-%s" % (nightly_suffix, stable_version, target_triple))) print("Rust {} libs ready.".format(target_triple)) diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py index 1d4931dc78c..f43f234a3a2 100644 --- a/python/servo/build_commands.py +++ b/python/servo/build_commands.py @@ -265,6 +265,43 @@ class MachCommands(CommandBase): print("Build completed in %s" % format_duration(elapsed)) return status + @Command('build-stable', + description='Build Servo using stable rustc', + category='build') + @CommandArgument('--target', '-t', + default=None, + help='Cross compile for given target platform') + @CommandArgument('--release', '-r', + action='store_true', + help='Build in release mode') + @CommandArgument('--dev', '-d', + action='store_true', + help='Build in development mode') + @CommandArgument('--jobs', '-j', + default=None, + help='Number of jobs to run in parallel') + @CommandArgument('--features', + default=None, + help='Space-separated list of features to also build', + nargs='+') + @CommandArgument('--android', + default=None, + action='store_true', + help='Build for Android') + @CommandArgument('--debug-mozjs', + default=None, + action='store_true', + help='Enable debug assertions in mozjs') + @CommandArgument('--verbose', '-v', + action='store_true', + help='Print verbose output') + @CommandArgument('params', nargs='...', + help="Command-line arguments to be passed through to Cargo") + def build_stable(self, target=None, release=False, dev=False, jobs=None, + features=None, android=None, verbose=False, debug_mozjs=False, params=None): + self.set_use_stable_rust() + self.build(target, release, dev, jobs, features, android, verbose, debug_mozjs, params) + @Command('build-cef', description='Build the Chromium Embedding Framework library', category='build') diff --git a/python/servo/command_base.py b/python/servo/command_base.py index 990bc9a586c..9f4f9096316 100644 --- a/python/servo/command_base.py +++ b/python/servo/command_base.py @@ -184,9 +184,7 @@ class CommandBase(object): self.config["tools"].setdefault("system-cargo", False) self.config["tools"].setdefault("rust-root", "") self.config["tools"].setdefault("cargo-root", "") - if not self.config["tools"]["system-rust"]: - self.config["tools"]["rust-root"] = path.join( - context.sharedir, "rust", self.rust_path()) + self.set_use_stable_rust(False) if not self.config["tools"]["system-cargo"]: self.config["tools"]["cargo-root"] = path.join( context.sharedir, "cargo", self.cargo_build_id()) @@ -205,16 +203,33 @@ class CommandBase(object): self.config["android"].setdefault("platform", "android-18") self.config["android"].setdefault("target", "arm-linux-androideabi") - _rust_path = None + _use_stable_rust = False + _rust_version = None + _rust_version_is_stable = False _cargo_build_id = None + def set_use_stable_rust(self, use_stable_rust=True): + self._use_stable_rust = use_stable_rust + if not self.config["tools"]["system-rust"]: + self.config["tools"]["rust-root"] = path.join( + self.context.sharedir, "rust", self.rust_path()) + + def use_stable_rust(self): + return self._use_stable_rust + def rust_path(self): - if self._rust_path is None: - filename = path.join(self.context.topdir, "rust-nightly-date") + if self._use_stable_rust: + return "rustc-%s-%s" % (self.rust_version(), host_triple()) + else: + return "%s/rustc-nightly-%s" % (self.rust_version(), 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-nightly-date") with open(filename) as f: - date = f.read().strip() - self._rust_path = ("%s/rustc-nightly-%s" % (date, host_triple())) - return self._rust_path + self._rust_version = f.read().strip() + return self._rust_version def cargo_build_id(self): if self._cargo_build_id is None: @@ -317,7 +332,9 @@ class CommandBase(object): env["CARGO_HOME"] = self.config["tools"]["cargo-home-dir"] - if "CARGO_TARGET_DIR" not in env: + if self.use_stable_rust(): + env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "ports/stable-rust/target") + elif "CARGO_TARGET_DIR" not in env: env["CARGO_TARGET_DIR"] = path.join(self.context.topdir, "target") if extra_lib: @@ -426,7 +443,8 @@ class CommandBase(object): if not (self.config['tools']['system-rust'] or (rustc_binary_exists and target_exists)): print("looking for rustc at %s" % (rustc_path)) - Registrar.dispatch("bootstrap-rust", context=self.context, target=filter(None, [target])) + Registrar.dispatch("bootstrap-rust", context=self.context, target=filter(None, [target]), + stable=self._use_stable_rust) cargo_path = path.join(self.config["tools"]["cargo-root"], "cargo", "bin", "cargo" + BIN_SUFFIX) diff --git a/rust-stable-version b/rust-stable-version new file mode 100644 index 00000000000..f8e233b2733 --- /dev/null +++ b/rust-stable-version @@ -0,0 +1 @@ +1.9.0 |