Bug 1381576 - Use a Cargo workspace for rust crates. r=ted
MozReview-Commit-ID: K6B9SifddXu
This commit is contained in:
@@ -531,52 +531,6 @@ class TreeMetadataEmitter(LoggingMixin):
|
||||
'crate-type %s is not permitted for %s' % (crate_type, libname),
|
||||
context)
|
||||
|
||||
# Check that the [profile.{dev,release}.panic] field is "abort"
|
||||
profile_section = config.get('profile', None)
|
||||
if not profile_section:
|
||||
raise SandboxValidationError(
|
||||
'Cargo.toml for %s has no [profile] section' % libname,
|
||||
context)
|
||||
|
||||
for profile_name in ['dev', 'release']:
|
||||
profile = profile_section.get(profile_name, None)
|
||||
if not profile:
|
||||
raise SandboxValidationError(
|
||||
'Cargo.toml for %s has no [profile.%s] section' % (libname, profile_name),
|
||||
context)
|
||||
|
||||
panic = profile.get('panic', None)
|
||||
if panic != 'abort':
|
||||
raise SandboxValidationError(
|
||||
('Cargo.toml for %s does not specify `panic = "abort"`'
|
||||
' in [profile.%s] section') % (libname, profile_name),
|
||||
context)
|
||||
|
||||
# gkrust and gkrust-gtest must have the exact same profile settings
|
||||
# for our almost-workspaces configuration to work properly.
|
||||
if libname in ('gkrust', 'gkrust-gtest'):
|
||||
if profile_name == 'dev':
|
||||
expected_profile = {
|
||||
'opt-level': 1,
|
||||
'rpath': False,
|
||||
'lto': False,
|
||||
'debug-assertions': True,
|
||||
'panic': 'abort',
|
||||
}
|
||||
else:
|
||||
expected_profile = {
|
||||
'opt-level': 2,
|
||||
'rpath': False,
|
||||
'debug-assertions': False,
|
||||
'panic': 'abort',
|
||||
'codegen-units': 1,
|
||||
}
|
||||
|
||||
if profile != expected_profile:
|
||||
raise SandboxValidationError(
|
||||
'Cargo profile.%s for %s is incorrect' % (profile_name, libname),
|
||||
context)
|
||||
|
||||
cargo_target_dir = context.get('RUST_LIBRARY_TARGET_DIR', '.')
|
||||
|
||||
dependencies = set(config.get('dependencies', {}).iterkeys())
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
@@ -1,18 +0,0 @@
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
|
||||
|
||||
RustLibrary('random-crate')
|
||||
@@ -1,14 +0,0 @@
|
||||
[package]
|
||||
name = "random-crate"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Nobody <nobody@mozilla.org>",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[profile.dev]
|
||||
panic = "unwind"
|
||||
|
||||
[profile.release]
|
||||
@@ -1,18 +0,0 @@
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
@template
|
||||
def Library(name):
|
||||
'''Template for libraries.'''
|
||||
LIBRARY_NAME = name
|
||||
|
||||
|
||||
@template
|
||||
def RustLibrary(name):
|
||||
'''Template for Rust libraries.'''
|
||||
Library(name)
|
||||
|
||||
IS_RUST_LIBRARY = True
|
||||
|
||||
|
||||
RustLibrary('random-crate')
|
||||
@@ -1415,13 +1415,6 @@ class TestEmitterBasic(unittest.TestCase):
|
||||
'Cargo.toml for.* has no \\[lib\\] section'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_no_profile_section(self):
|
||||
'''Test that a RustLibrary Cargo.toml with no [profile] section fails.'''
|
||||
reader = self.reader('rust-library-no-profile-section')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'Cargo.toml for.* has no \\[profile\\.dev\\] section'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_invalid_crate_type(self):
|
||||
'''Test that a RustLibrary Cargo.toml has a permitted crate-type.'''
|
||||
reader = self.reader('rust-library-invalid-crate-type')
|
||||
@@ -1429,13 +1422,6 @@ class TestEmitterBasic(unittest.TestCase):
|
||||
'crate-type.* is not permitted'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_non_abort_panic(self):
|
||||
'''Test that a RustLibrary Cargo.toml has `panic = "abort" set'''
|
||||
reader = self.reader('rust-library-non-abort-panic')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'does not specify `panic = "abort"`'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_rust_library_dash_folding(self):
|
||||
'''Test that on-disk names of RustLibrary objects convert dashes to underscores.'''
|
||||
reader = self.reader('rust-library-dash-folding',
|
||||
|
||||
@@ -266,24 +266,12 @@ license file's hash.
|
||||
mozfile.remove(vendor_dir)
|
||||
# Once we require a new enough cargo to switch to workspaces, we can
|
||||
# just do this once on the workspace root crate.
|
||||
crates_and_roots = (
|
||||
('gkrust', 'toolkit/library/rust'),
|
||||
('gkrust-gtest', 'toolkit/library/gtest/rust'),
|
||||
('js', 'js/rust'),
|
||||
('mozjs_sys', 'js/src'),
|
||||
('geckodriver', 'testing/geckodriver'),
|
||||
)
|
||||
|
||||
lockfiles = []
|
||||
for (lib, crate_root) in crates_and_roots:
|
||||
path = mozpath.join(self.topsrcdir, crate_root)
|
||||
# We use check_call instead of mozprocess to ensure errors are displayed.
|
||||
# We do an |update -p| here to regenerate the Cargo.lock file with minimal changes. See bug 1324462
|
||||
subprocess.check_call([cargo, 'update', '--manifest-path', mozpath.join(path, 'Cargo.toml'), '-p', lib], cwd=self.topsrcdir)
|
||||
lockfiles.append('--sync')
|
||||
lockfiles.append(mozpath.join(path, 'Cargo.lock'))
|
||||
# We use check_call instead of mozprocess to ensure errors are displayed.
|
||||
# We do an |update -p| here to regenerate the Cargo.lock file with minimal changes. See bug 1324462
|
||||
subprocess.check_call([cargo, 'update', '-p', 'gkrust'], cwd=self.topsrcdir)
|
||||
|
||||
subprocess.check_call([cargo, 'vendor', '--quiet', '--no-delete'] + lockfiles + [vendor_dir], cwd=self.topsrcdir)
|
||||
subprocess.check_call([cargo, 'vendor', '--quiet', '--no-delete', '--sync', 'Cargo.lock'] + [vendor_dir], cwd=self.topsrcdir)
|
||||
|
||||
if not self._check_licenses(vendor_dir):
|
||||
self.log(logging.ERROR, 'license_check_failed', {},
|
||||
|
||||
Reference in New Issue
Block a user