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-11-27 17:57:49 +03:00
|
|
|
|
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.
|
2018-08-02 15:27:11 +03:00
|
|
|
js_option(env='RUSTC', nargs=1, help='Path to the rust compiler')
|
|
|
|
js_option(env='CARGO', nargs=1, help='Path to the Cargo package manager')
|
|
|
|
|
2019-05-14 08:43:19 +03:00
|
|
|
rustc = check_prog('_RUSTC', ['rustc'], what='rustc',
|
|
|
|
paths=toolchain_search_path, input='RUSTC',
|
|
|
|
allow_missing=True)
|
2019-04-12 01:25:51 +03:00
|
|
|
cargo = check_prog('_CARGO', ['cargo'], what='cargo',
|
|
|
|
paths=toolchain_search_path, input='CARGO',
|
|
|
|
allow_missing=True)
|
|
|
|
|
|
|
|
|
2019-05-14 08:43:19 +03:00
|
|
|
@template
|
|
|
|
def unwrap_rustup(prog, name):
|
|
|
|
# rustc and cargo can either be rustup wrappers, or they can be the actual,
|
|
|
|
# plain executables. For cargo, on OSX, rustup sets DYLD_LIBRARY_PATH (at
|
|
|
|
# least until https://github.com/rust-lang/rustup.rs/pull/1752 is merged
|
|
|
|
# and shipped) and that can wreak havoc (see bug 1536486). Similarly, for
|
|
|
|
# rustc, rustup silently honors toolchain overrides set by vendored crates
|
|
|
|
# (see bug 1547196).
|
2019-04-12 01:25:51 +03:00
|
|
|
#
|
2019-05-14 08:43:19 +03:00
|
|
|
# In either case, we need to find the plain executables.
|
2019-04-12 01:25:51 +03:00
|
|
|
#
|
2019-05-14 08:43:19 +03:00
|
|
|
# To achieve that, try to run `PROG +stable`. When the rustup wrapper is in
|
|
|
|
# use, it either prints PROG's help and exits with status 0, or prints
|
2019-04-12 01:25:51 +03:00
|
|
|
# an error message (error: toolchain 'stable' is not installed) and exits
|
2019-05-14 08:43:19 +03:00
|
|
|
# with status 1. In the cargo case, when plain cargo is in use, it exits
|
|
|
|
# with a different error message (e.g. "error: no such subcommand:
|
|
|
|
# `+stable`"), and exits with status 101.
|
|
|
|
#
|
|
|
|
# Unfortunately, in the rustc case, when plain rustc is in use,
|
|
|
|
# `rustc +stable` will exit with status 1, complaining about a missing
|
|
|
|
# "+stable" file. We'll examine the error output to try and distinguish
|
|
|
|
# between failing rustup and failing rustc.
|
|
|
|
@depends(prog, dependable(name))
|
|
|
|
@imports(_from='__builtin__', _import='open')
|
|
|
|
@imports('os')
|
|
|
|
def unwrap(prog, name):
|
|
|
|
def from_rustup_which():
|
|
|
|
out = check_cmd_output('rustup', 'which', name,
|
|
|
|
executable=prog).rstrip()
|
2019-04-12 01:25:51 +03:00
|
|
|
# If for some reason the above failed to return something, keep the
|
2019-05-14 08:43:19 +03:00
|
|
|
# PROG we found originally.
|
2019-04-12 01:25:51 +03:00
|
|
|
if out:
|
2019-05-14 08:43:19 +03:00
|
|
|
log.info('Actually using \'%s\'', out)
|
|
|
|
return out
|
|
|
|
|
|
|
|
log.info('No `rustup which` output, using \'%s\'', prog)
|
|
|
|
return prog
|
|
|
|
|
|
|
|
(retcode, stdout, stderr) = get_cmd_output(prog, '+stable')
|
|
|
|
|
|
|
|
if name == 'cargo' and retcode != 101:
|
|
|
|
prog = from_rustup_which()
|
|
|
|
elif name == 'rustc':
|
|
|
|
if retcode == 0:
|
|
|
|
prog = from_rustup_which()
|
|
|
|
elif "+stable" in stderr:
|
|
|
|
# PROG looks like plain `rustc`.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Assume PROG looks like `rustup`. This case is a little weird,
|
|
|
|
# insofar as the user doesn't have the "stable" toolchain
|
|
|
|
# installed, but go ahead and unwrap anyway: the user might
|
|
|
|
# have only certain versions, beta, or nightly installed, and
|
|
|
|
# we'll catch invalid versions later.
|
|
|
|
prog = from_rustup_which()
|
|
|
|
|
|
|
|
return prog
|
|
|
|
|
|
|
|
return unwrap
|
|
|
|
|
|
|
|
rustc = unwrap_rustup(rustc, 'rustc')
|
|
|
|
cargo = unwrap_rustup(cargo, 'cargo')
|
2019-04-12 01:25:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
set_config('CARGO', cargo)
|
2019-05-14 08:43:19 +03:00
|
|
|
set_config('RUSTC', rustc)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
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'),
|
2017-12-14 19:20:33 +03:00
|
|
|
host=info['host'],
|
2019-07-25 23:45:34 +03:00
|
|
|
llvm_version=Version(info.get('LLVM version', '0')),
|
2017-02-13 18:42:33 +03:00
|
|
|
)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2019-01-23 23:15:14 +03:00
|
|
|
set_config('RUSTC_VERSION', depends(rustc_info)(lambda info: str(info.version)))
|
2017-10-12 16:22:59 +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-10-12 16:22:59 +03:00
|
|
|
|
2019-04-12 02:24:21 +03:00
|
|
|
@depends(rustc_info, cargo_info, build_project)
|
2016-05-16 22:27:37 +03:00
|
|
|
@imports(_from='textwrap', _import='dedent')
|
2019-04-12 02:24:21 +03:00
|
|
|
def rust_compiler(rustc_info, cargo_info, build_project):
|
2017-02-25 07:11:26 +03:00
|
|
|
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/
|
|
|
|
'''))
|
2019-02-14 12:00:38 +03:00
|
|
|
if build_project == 'tools/crashreporter':
|
2019-07-06 01:01:23 +03:00
|
|
|
rustc_min_version = Version('1.31.0')
|
2019-02-14 12:00:38 +03:00
|
|
|
else:
|
2019-09-04 22:08:28 +03:00
|
|
|
rustc_min_version = Version('1.37.0')
|
2019-07-06 01:01:23 +03:00
|
|
|
cargo_min_version = rustc_min_version
|
2017-02-13 18:42:33 +03:00
|
|
|
|
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
|
|
|
|
2017-10-05 10:10:45 +03:00
|
|
|
|
|
|
|
@depends(rustc, when=rust_compiler)
|
2019-08-22 02:22:24 +03:00
|
|
|
@imports(_from='__builtin__', _import='ValueError')
|
2017-10-05 10:10:45 +03:00
|
|
|
def rust_supported_targets(rustc):
|
|
|
|
out = check_cmd_output(rustc, '--print', 'target-list').splitlines()
|
2019-08-22 02:22:24 +03:00
|
|
|
data = {}
|
2017-10-05 10:10:45 +03:00
|
|
|
for t in out:
|
2019-08-22 02:22:24 +03:00
|
|
|
try:
|
|
|
|
info = split_triplet(t)
|
|
|
|
except ValueError:
|
|
|
|
if t.startswith('thumb'):
|
|
|
|
cpu, rest = t.split('-', 1)
|
|
|
|
retry = '-'.join(('arm', rest))
|
|
|
|
elif t.endswith('-windows-msvc'):
|
|
|
|
retry = t[:-len('windows-msvc')] + 'mingw32'
|
|
|
|
elif t.endswith('-windows-gnu'):
|
|
|
|
retry = t[:-len('windows-gnu')] + 'mingw32'
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
info = split_triplet(retry)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
key = (info.cpu, info.endianness, info.os)
|
|
|
|
data.setdefault(key, []).append(namespace(rust_target=t, target=info))
|
|
|
|
return data
|
2017-10-05 10:10:45 +03:00
|
|
|
|
|
|
|
|
2016-11-28 19:20:39 +03:00
|
|
|
@template
|
2019-07-08 13:35:31 +03:00
|
|
|
def rust_triple_alias(host_or_target, host_or_target_c_compiler):
|
2016-11-28 19:20:39 +03:00
|
|
|
"""Template defining the alias used for rustc's --target flag.
|
|
|
|
`host_or_target` is either `host` or `target` (the @depends functions
|
|
|
|
from init.configure).
|
|
|
|
"""
|
2018-10-12 16:44:08 +03:00
|
|
|
assert host_or_target in {host, target}
|
2016-11-28 19:20:39 +03:00
|
|
|
|
2019-03-22 02:36:00 +03:00
|
|
|
host_or_target_str = {host: 'host', target: 'target'}[host_or_target]
|
|
|
|
|
2019-07-08 13:35:31 +03:00
|
|
|
@depends(rustc, host_or_target, host_or_target_c_compiler,
|
|
|
|
rust_supported_targets, arm_target, when=rust_compiler)
|
2019-03-22 02:36:00 +03:00
|
|
|
@checking('for rust %s triplet' % host_or_target_str)
|
2016-11-28 19:20:39 +03:00
|
|
|
@imports('os')
|
|
|
|
@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')
|
2018-06-25 20:57:43 +03:00
|
|
|
def rust_target(rustc, host_or_target, compiler_info,
|
2019-03-22 02:36:49 +03:00
|
|
|
rust_supported_targets, arm_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.
|
2017-10-05 10:10:45 +03:00
|
|
|
# We correlate the autoconf-derived targets with the list of targets
|
|
|
|
# rustc gives us with --print target-list.
|
2019-08-22 02:22:24 +03:00
|
|
|
candidates = rust_supported_targets.get(
|
|
|
|
(host_or_target.cpu, host_or_target.endianness, host_or_target.os), [])
|
|
|
|
|
|
|
|
def find_candidate(candidates):
|
|
|
|
if len(candidates) == 1:
|
|
|
|
return candidates[0].rust_target
|
|
|
|
elif not candidates:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# We have multiple candidates. There are two cases where we can try to
|
|
|
|
# narrow further down using extra information from the build system.
|
|
|
|
# - For windows targets, correlate with the C compiler type
|
|
|
|
if host_or_target.kernel == 'WINNT':
|
|
|
|
if compiler_info.type in ('gcc', 'clang'):
|
|
|
|
suffix = 'windows-gnu'
|
|
|
|
else:
|
|
|
|
suffix = 'windows-msvc'
|
|
|
|
narrowed = [c for c in candidates if c.rust_target.endswith('-{}'.format(suffix))]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
elif narrowed:
|
|
|
|
candidates = narrowed
|
|
|
|
|
2019-10-17 01:16:13 +03:00
|
|
|
vendor_aliases = {'pc': 'w64'}
|
|
|
|
narrowed = [c for c in candidates
|
|
|
|
if vendor_aliases.get(c.target.vendor) == host_or_target.vendor]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
|
2019-08-22 02:22:24 +03:00
|
|
|
# - For arm targets, correlate with arm_target
|
|
|
|
# we could be more thorough with the supported rust targets, but they
|
|
|
|
# don't support OSes that are supported to build Gecko anyways.
|
|
|
|
# Also, sadly, the only interface to check the rust target cpu features
|
|
|
|
# is --print target-spec-json, and it's unstable, so we have to rely on
|
|
|
|
# our own knowledge of what each arm target means.
|
|
|
|
if host_or_target.cpu == 'arm' and host_or_target.endianness == 'little':
|
|
|
|
prefixes = []
|
|
|
|
if arm_target.arm_arch >= 7:
|
|
|
|
if arm_target.thumb2 and arm_target.fpu == 'neon':
|
|
|
|
prefixes.append('thumbv7neon')
|
|
|
|
if arm_target.thumb2:
|
|
|
|
prefixes.append('thumbv7a')
|
|
|
|
prefixes.append('armv7')
|
|
|
|
if arm_target.arm_arch >= 6:
|
|
|
|
prefixes.append('armv6')
|
|
|
|
if host_or_target.os != 'Android':
|
|
|
|
# arm-* rust targets are armv6... except arm-linux-androideabi
|
|
|
|
prefixes.append('arm')
|
|
|
|
if arm_target.arm_arch >= 5:
|
|
|
|
prefixes.append('armv5te')
|
|
|
|
if host_or_target.os == 'Android':
|
|
|
|
# arm-* rust targets are armv6... except arm-linux-androideabi
|
|
|
|
prefixes.append('arm')
|
|
|
|
if arm_target.arm_arch >= 4:
|
|
|
|
prefixes.append('armv4t')
|
|
|
|
# rust freebsd targets are the only ones that don't have a 'hf' suffix
|
|
|
|
# for hard-float. Technically, that means if the float abi ever is not
|
|
|
|
# hard-float, this will pick a wrong target, but since rust only
|
|
|
|
# supports hard-float, let's assume that means freebsd only support
|
|
|
|
# hard-float.
|
|
|
|
if arm_target.float_abi == 'hard' and host_or_target.os != 'FreeBSD':
|
|
|
|
suffix = 'hf'
|
|
|
|
else:
|
|
|
|
suffix = ''
|
|
|
|
for p in prefixes:
|
|
|
|
for c in candidates:
|
|
|
|
if c.rust_target.startswith('{}-'.format(p)) and \
|
|
|
|
c.rust_target.endswith(suffix):
|
|
|
|
return c.rust_target
|
|
|
|
|
|
|
|
# See if we can narrow down on the exact alias
|
|
|
|
narrowed = [c for c in candidates if c.target.alias == host_or_target.alias]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
elif narrowed:
|
|
|
|
candidates = narrowed
|
|
|
|
|
|
|
|
# See if we can narrow down with the raw OS
|
|
|
|
narrowed = [c for c in candidates if c.target.raw_os == host_or_target.raw_os]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
elif narrowed:
|
|
|
|
candidates = narrowed
|
|
|
|
|
|
|
|
# See if we can narrow down with the raw OS and raw CPU
|
|
|
|
narrowed = [
|
|
|
|
c for c in candidates
|
|
|
|
if c.target.raw_os == host_or_target.raw_os and
|
|
|
|
c.target.raw_cpu == host_or_target.raw_cpu
|
|
|
|
]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
|
2019-10-17 01:16:13 +03:00
|
|
|
# Finally, see if the vendor can be used to disambiguate.
|
|
|
|
narrowed = [
|
|
|
|
c for c in candidates
|
|
|
|
if c.target.vendor == host_or_target.vendor
|
|
|
|
]
|
|
|
|
if len(narrowed) == 1:
|
|
|
|
return narrowed[0].rust_target
|
|
|
|
|
2019-08-22 02:22:24 +03:00
|
|
|
return None
|
|
|
|
|
|
|
|
rustc_target = find_candidate(candidates)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
|
|
|
if rustc_target is None:
|
2017-10-12 16:22:59 +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.
|
2019-08-22 02:22:24 +03:00
|
|
|
target_arg = '--target=' + rustc_target
|
2016-05-16 22:27:37 +03:00
|
|
|
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,
|
|
|
|
]
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-05-16 22:27:37 +03:00
|
|
|
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 {}
|
2019-08-22 02:22:24 +03:00
|
|
|
'''.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.
|
2019-08-22 02:22:24 +03:00
|
|
|
return rustc_target
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2016-11-28 19:20:39 +03:00
|
|
|
return rust_target
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2019-07-08 13:35:31 +03:00
|
|
|
rust_target_triple = rust_triple_alias(target, c_compiler)
|
|
|
|
rust_host_triple = rust_triple_alias(host, host_c_compiler)
|
2016-11-28 19:20:39 +03:00
|
|
|
|
2019-01-29 04:15:16 +03:00
|
|
|
|
|
|
|
@depends(host, rust_host_triple, rustc_info.host)
|
|
|
|
def validate_rust_host_triple(host, rust_host, rustc_host):
|
|
|
|
if rust_host != rustc_host:
|
|
|
|
if host.alias == rust_host:
|
2019-02-08 19:56:13 +03:00
|
|
|
configure_host = host.alias
|
2019-01-29 04:15:16 +03:00
|
|
|
else:
|
|
|
|
configure_host = '{}/{}'.format(host.alias, rust_host)
|
|
|
|
die("The rust compiler host ({}) is not suitable for the configure host ({})."
|
|
|
|
.format(rustc_host, configure_host))
|
|
|
|
|
|
|
|
|
2016-11-28 19:20:39 +03:00
|
|
|
set_config('RUST_TARGET', rust_target_triple)
|
|
|
|
set_config('RUST_HOST_TARGET', rust_host_triple)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-06-23 23:19:49 +03:00
|
|
|
# This is used for putting source info into symbol files.
|
|
|
|
set_config('RUSTC_COMMIT', depends(rustc_info)(lambda i: i.commit))
|
|
|
|
|
2018-05-02 13:02:04 +03:00
|
|
|
# Rustdoc is required by Rust tests below.
|
2018-08-02 15:27:11 +03:00
|
|
|
js_option(env='RUSTDOC', nargs=1, help='Path to the rustdoc program')
|
|
|
|
|
2019-01-11 18:48:20 +03:00
|
|
|
rustdoc = check_prog('RUSTDOC', ['rustdoc'], paths=toolchain_search_path,
|
2018-08-02 15:27:11 +03:00
|
|
|
input='RUSTDOC', allow_missing=True)
|
2018-05-02 13:02:04 +03:00
|
|
|
|
2017-10-02 16:21:22 +03:00
|
|
|
# This option is separate from --enable-tests because Rust tests are particularly
|
|
|
|
# expensive in terms of compile time (especially for code in libxul).
|
|
|
|
option('--enable-rust-tests',
|
2018-11-10 17:59:39 +03:00
|
|
|
help='Enable building and running of Rust tests during `make check`')
|
2017-10-02 16:21:22 +03:00
|
|
|
|
2018-05-02 13:02:04 +03:00
|
|
|
|
|
|
|
@depends('--enable-rust-tests', rustdoc)
|
|
|
|
def rust_tests(enable_rust_tests, rustdoc):
|
|
|
|
if enable_rust_tests and not rustdoc:
|
|
|
|
die('--enable-rust-tests requires rustdoc')
|
|
|
|
return bool(enable_rust_tests)
|
|
|
|
|
|
|
|
|
|
|
|
set_config('MOZ_RUST_TESTS', rust_tests)
|
2017-12-14 19:20:33 +03:00
|
|
|
|
|
|
|
|
2019-01-15 16:56:07 +03:00
|
|
|
@depends(target, c_compiler, rustc)
|
|
|
|
@imports('os')
|
|
|
|
def rustc_natvis_ldflags(target, compiler_info, rustc):
|
2019-02-15 00:45:27 +03:00
|
|
|
if target.kernel == 'WINNT' and compiler_info.type == 'clang-cl':
|
2019-01-15 16:56:07 +03:00
|
|
|
sysroot = check_cmd_output(rustc, '--print', 'sysroot').strip()
|
|
|
|
etc = os.path.join(sysroot, 'lib/rustlib/etc')
|
|
|
|
ldflags = []
|
|
|
|
for f in os.listdir(etc):
|
|
|
|
if f.endswith('.natvis'):
|
|
|
|
ldflags.append('-NATVIS:' + normsep(os.path.join(etc, f)))
|
|
|
|
return ldflags
|
|
|
|
|
|
|
|
|
|
|
|
set_config('RUSTC_NATVIS_LDFLAGS', rustc_natvis_ldflags)
|