2016-07-14 19:16:42 +03:00
|
|
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
2016-05-16 22:27:37 +03:00
|
|
|
# vim: set filetype=python:
|
|
|
|
# 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/.
|
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
# Rust is required by `rust_compiler` below. We allow_missing here
|
|
|
|
# to propagate failures to the better error message there.
|
|
|
|
rustc = check_prog('RUSTC', ['rustc'], allow_missing=True)
|
|
|
|
cargo = check_prog('CARGO', ['cargo'], allow_missing=True)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
@depends_if(rustc)
|
2016-07-05 00:12:04 +03:00
|
|
|
@checking('rustc version', lambda info: info.version)
|
|
|
|
def rustc_info(rustc):
|
2017-02-13 18:42:33 +03:00
|
|
|
out = check_cmd_output(rustc, '--version', '--verbose').splitlines()
|
|
|
|
info = dict((s.strip() for s in line.split(':', 1)) for line in out[1:])
|
|
|
|
return namespace(
|
|
|
|
version=Version(info.get('release', '0')),
|
|
|
|
commit=info.get('commit-hash', 'unknown'),
|
|
|
|
)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2017-02-13 18:42:33 +03:00
|
|
|
@depends_if(cargo)
|
|
|
|
@checking('cargo version', lambda info: info.version)
|
|
|
|
@imports('re')
|
|
|
|
def cargo_info(cargo):
|
2017-02-15 05:22:34 +03:00
|
|
|
out = check_cmd_output(cargo, '--version', '--verbose').splitlines()
|
|
|
|
info = dict((s.strip() for s in line.split(':', 1)) for line in out[1:])
|
|
|
|
version = info.get('release')
|
|
|
|
# Older versions of cargo didn't support --verbose, in which case, they
|
|
|
|
# only output a not-really-pleasant-to-parse output. Fortunately, they
|
|
|
|
# don't error out, so we can just try some regexp matching on the output
|
|
|
|
# we already got.
|
|
|
|
if version is None:
|
|
|
|
VERSION_FORMAT = r'^cargo (\d\.\d+\.\d+).*'
|
2017-02-13 18:42:33 +03:00
|
|
|
|
2017-02-15 05:22:34 +03:00
|
|
|
m = re.search(VERSION_FORMAT, out[0])
|
|
|
|
# Fail fast if cargo changes its output on us.
|
|
|
|
if not m:
|
|
|
|
die('Could not determine cargo version from output: %s', out)
|
|
|
|
version = m.group(1)
|
2017-02-13 18:42:33 +03:00
|
|
|
|
|
|
|
return namespace(
|
2017-02-15 05:22:34 +03:00
|
|
|
version=Version(version),
|
2017-02-13 18:42:33 +03:00
|
|
|
)
|
|
|
|
|
2017-02-25 07:11:26 +03:00
|
|
|
@depends(rustc_info, cargo_info)
|
2016-05-16 22:27:37 +03:00
|
|
|
@imports(_from='textwrap', _import='dedent')
|
2017-02-25 07:11:26 +03:00
|
|
|
def rust_compiler(rustc_info, cargo_info):
|
|
|
|
if not rustc_info:
|
2017-02-02 02:38:49 +03:00
|
|
|
die(dedent('''\
|
|
|
|
Rust compiler not found.
|
|
|
|
To compile rust language sources, you must have 'rustc' in your path.
|
2017-04-21 10:43:14 +03:00
|
|
|
See https://www.rust-lang.org/ for more information.
|
2016-12-02 04:01:55 +03:00
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
You can install rust by running './mach bootstrap'
|
|
|
|
or by directly running the installer from https://rustup.rs/
|
|
|
|
'''))
|
2017-02-13 18:42:33 +03:00
|
|
|
rustc_min_version = Version('1.15.1')
|
|
|
|
cargo_min_version = Version('0.{}'.format(rustc_min_version.minor + 1))
|
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
version = rustc_info.version
|
2017-02-13 18:42:33 +03:00
|
|
|
if version < rustc_min_version:
|
2017-02-02 02:38:49 +03:00
|
|
|
die(dedent('''\
|
|
|
|
Rust compiler {} is too old.
|
2016-12-02 04:01:55 +03:00
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
To compile Rust language sources please install at least
|
|
|
|
version {} of the 'rustc' toolchain and make sure it is
|
|
|
|
first in your path.
|
2016-12-02 04:01:55 +03:00
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
You can verify this by typing 'rustc --version'.
|
2016-12-02 04:01:55 +03:00
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
If you have the 'rustup' tool installed you can upgrade
|
|
|
|
to the latest release by typing 'rustup update'. The
|
|
|
|
installer is available from https://rustup.rs/
|
2017-02-13 18:42:33 +03:00
|
|
|
'''.format(version, rustc_min_version)))
|
|
|
|
|
2017-02-25 07:11:26 +03:00
|
|
|
if not cargo_info:
|
|
|
|
die(dedent('''\
|
|
|
|
Cargo package manager not found.
|
|
|
|
To compile Rust language sources, you must have 'cargo' in your path.
|
|
|
|
See https://www.rust-lang.org/ for more information.
|
|
|
|
|
|
|
|
You can install cargo by running './mach bootstrap'
|
|
|
|
or by directly running the installer from https://rustup.rs/
|
|
|
|
'''))
|
|
|
|
|
|
|
|
version = cargo_info.version
|
|
|
|
if version < cargo_min_version:
|
|
|
|
die(dedent('''\
|
|
|
|
Cargo package manager {} is too old.
|
|
|
|
|
|
|
|
To compile Rust language sources please install at least
|
|
|
|
version {} of 'cargo' and make sure it is first in your path.
|
|
|
|
|
|
|
|
You can verify this by typing 'cargo --version'.
|
|
|
|
''').format(version, cargo_min_version))
|
|
|
|
|
2017-02-02 02:38:49 +03:00
|
|
|
return True
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
set_config('MOZ_RUST', rust_compiler)
|
|
|
|
|
2016-11-28 19:20:39 +03:00
|
|
|
@template
|
|
|
|
def rust_triple_alias(host_or_target):
|
|
|
|
"""Template defining the alias used for rustc's --target flag.
|
|
|
|
`host_or_target` is either `host` or `target` (the @depends functions
|
|
|
|
from init.configure).
|
|
|
|
"""
|
|
|
|
assert host_or_target in (host, target)
|
|
|
|
|
|
|
|
@depends(rustc, host_or_target, when=rust_compiler)
|
|
|
|
@imports('os')
|
|
|
|
@imports('subprocess')
|
|
|
|
@imports(_from='mozbuild.configure.util', _import='LineIO')
|
|
|
|
@imports(_from='mozbuild.shellutil', _import='quote')
|
|
|
|
@imports(_from='tempfile', _import='mkstemp')
|
2016-11-28 21:51:59 +03:00
|
|
|
@imports(_from='textwrap', _import='dedent')
|
2016-11-28 19:20:39 +03:00
|
|
|
def rust_target(rustc, host_or_target):
|
2016-05-16 22:27:37 +03:00
|
|
|
# Rust's --target options are similar to, but not exactly the same
|
|
|
|
# as, the autoconf-derived targets we use. An example would be that
|
|
|
|
# Rust uses distinct target triples for targetting the GNU C++ ABI
|
|
|
|
# and the MSVC C++ ABI on Win32, whereas autoconf has a single
|
|
|
|
# triple and relies on the user to ensure that everything is
|
|
|
|
# compiled for the appropriate ABI. We need to perform appropriate
|
|
|
|
# munging to get the correct option to rustc.
|
|
|
|
#
|
|
|
|
# The canonical list of targets supported can be derived from:
|
|
|
|
#
|
2017-02-13 22:08:53 +03:00
|
|
|
# https://github.com/rust-lang/rust/blob/master/src/librustc_back/target/mod.rs
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
# Avoid having to write out os+kernel for all the platforms where
|
|
|
|
# they don't differ.
|
2016-11-28 19:20:39 +03:00
|
|
|
os_or_kernel = host_or_target.kernel if host_or_target.kernel == 'Linux' and host_or_target.os != 'Android' else host_or_target.os
|
2016-05-16 22:27:37 +03:00
|
|
|
rustc_target = {
|
|
|
|
# DragonFly
|
2016-07-08 09:36:11 +03:00
|
|
|
('x86_64', 'DragonFly'): 'x86_64-unknown-dragonfly',
|
|
|
|
# FreeBSD
|
2017-02-13 22:08:53 +03:00
|
|
|
('aarch64', 'FreeBSD'): 'aarch64-unknown-freebsd',
|
2016-05-16 22:27:37 +03:00
|
|
|
('x86', 'FreeBSD'): 'i686-unknown-freebsd',
|
|
|
|
('x86_64', 'FreeBSD'): 'x86_64-unknown-freebsd',
|
|
|
|
# NetBSD
|
2017-02-13 22:08:53 +03:00
|
|
|
('sparc64', 'NetBSD'): 'sparc64-unknown-netbsd',
|
|
|
|
('x86', 'NetBSD'): 'i686-unknown-netbsd',
|
2016-05-16 22:27:37 +03:00
|
|
|
('x86_64', 'NetBSD'): 'x86_64-unknown-netbsd',
|
|
|
|
# OpenBSD
|
2017-02-05 20:36:00 +03:00
|
|
|
('x86', 'OpenBSD'): 'i686-unknown-openbsd',
|
2016-05-16 22:27:37 +03:00
|
|
|
('x86_64', 'OpenBSD'): 'x86_64-unknown-openbsd',
|
|
|
|
# Linux
|
2017-02-13 22:08:53 +03:00
|
|
|
('aarch64', 'Linux'): 'aarch64-unknown-linux-gnu',
|
|
|
|
('arm', 'Linux'): 'armv7-unknown-linux-gnueabihf',
|
|
|
|
('sparc64', 'Linux'): 'sparc64-unknown-linux-gnu',
|
2016-11-28 20:17:11 +03:00
|
|
|
('x86', 'Linux'): 'i686-unknown-linux-gnu',
|
2016-05-16 22:27:37 +03:00
|
|
|
('x86_64', 'Linux'): 'x86_64-unknown-linux-gnu',
|
2017-02-13 22:08:53 +03:00
|
|
|
# OS X
|
2016-05-16 22:27:37 +03:00
|
|
|
('x86', 'OSX'): 'i686-apple-darwin',
|
|
|
|
('x86_64', 'OSX'): 'x86_64-apple-darwin',
|
2017-02-13 22:08:53 +03:00
|
|
|
# iOS
|
|
|
|
('aarch64', 'iOS'): 'aarch64-apple-ios',
|
|
|
|
('arm', 'iOS'): 'armv7s-apple-ios',
|
|
|
|
('x86', 'iOS'): 'i386-apple-ios',
|
|
|
|
('x86_64', 'iOS'): 'x86_64-apple-ios',
|
2016-05-16 22:27:37 +03:00
|
|
|
# Android
|
2016-12-21 08:44:11 +03:00
|
|
|
('aarch64', 'Android'): 'aarch64-linux-android',
|
2017-02-13 22:08:53 +03:00
|
|
|
('arm', 'Android'): 'armv7-linux-androideabi',
|
|
|
|
('x86', 'Android'): 'i686-linux-android',
|
2016-05-16 22:27:37 +03:00
|
|
|
# Windows
|
|
|
|
# XXX better detection of CXX needed here, to figure out whether
|
|
|
|
# we need i686-pc-windows-gnu instead, since mingw32 builds work.
|
|
|
|
('x86', 'WINNT'): 'i686-pc-windows-msvc',
|
|
|
|
('x86_64', 'WINNT'): 'x86_64-pc-windows-msvc',
|
2016-11-28 19:20:39 +03:00
|
|
|
}.get((host_or_target.cpu, os_or_kernel), None)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
if rustc_target is None:
|
2016-11-28 19:20:39 +03:00
|
|
|
die("Don't know how to translate {} for rustc".format(host_or_target.alias))
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
# Check to see whether our rustc has a reasonably functional stdlib
|
|
|
|
# for our chosen target.
|
|
|
|
target_arg = '--target=' + rustc_target
|
|
|
|
in_fd, in_path = mkstemp(prefix='conftest', suffix='.rs')
|
|
|
|
out_fd, out_path = mkstemp(prefix='conftest', suffix='.rlib')
|
|
|
|
os.close(out_fd)
|
|
|
|
try:
|
|
|
|
source = 'pub extern fn hello() { println!("Hello world"); }'
|
|
|
|
log.debug('Creating `%s` with content:', in_path)
|
|
|
|
with LineIO(lambda l: log.debug('| %s', l)) as out:
|
|
|
|
out.write(source)
|
|
|
|
|
|
|
|
os.write(in_fd, source)
|
|
|
|
os.close(in_fd)
|
|
|
|
|
|
|
|
cmd = [
|
|
|
|
rustc,
|
|
|
|
'--crate-type', 'staticlib',
|
|
|
|
target_arg,
|
|
|
|
'-o', out_path,
|
|
|
|
in_path,
|
|
|
|
]
|
|
|
|
def failed():
|
2016-11-28 21:51:59 +03:00
|
|
|
die(dedent('''\
|
|
|
|
Cannot compile for {} with {}
|
|
|
|
The target may be unsupported, or you may not have
|
|
|
|
a rust std library for that target installed. Try:
|
|
|
|
|
|
|
|
rustup target add {}
|
|
|
|
'''.format(host_or_target.alias, rustc, rustc_target)))
|
2016-05-16 22:27:37 +03:00
|
|
|
check_cmd_output(*cmd, onerror=failed)
|
|
|
|
if not os.path.exists(out_path) or os.path.getsize(out_path) == 0:
|
|
|
|
failed()
|
|
|
|
finally:
|
|
|
|
os.remove(in_path)
|
|
|
|
os.remove(out_path)
|
2016-11-28 19:20:39 +03:00
|
|
|
|
2016-05-16 22:27:37 +03:00
|
|
|
# This target is usable.
|
2016-08-06 07:49:26 +03:00
|
|
|
return rustc_target
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2016-11-28 19:20:39 +03:00
|
|
|
return rust_target
|
|
|
|
|
|
|
|
rust_target_triple = rust_triple_alias(target)
|
|
|
|
rust_host_triple = rust_triple_alias(host)
|
|
|
|
|
|
|
|
set_config('RUST_TARGET', rust_target_triple)
|
|
|
|
set_config('RUST_HOST_TARGET', rust_host_triple)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
# Until we remove all the other Rust checks in old-configure.
|
|
|
|
add_old_configure_assignment('MOZ_RUST', rust_compiler)
|
|
|
|
add_old_configure_assignment('RUSTC', rustc)
|
2016-11-28 19:20:39 +03:00
|
|
|
add_old_configure_assignment('RUST_TARGET', rust_target_triple)
|