Bug 1499196 - Always use the topobjdir to output rust library dependencies. r=ted,firefox-build-system-reviewers
Differential Revision:
https://phabricator.services.mozilla.com/D9039
--- a/build/templates.mozbuild
+++ b/build/templates.mozbuild
@@ -57,35 +57,32 @@ def Library(name):
def AllowCompilerWarnings():
COMPILE_FLAGS['WARNINGS_AS_ERRORS'] = []
@template
def DisableCompilerWarnings():
COMPILE_FLAGS['WARNINGS_CFLAGS'] = []
@template
-def RustLibrary(name, features=None, target_dir=None, output_category=None):
+def RustLibrary(name, features=None, output_category=None):
'''Template for Rust libraries.'''
Library(name)
IS_RUST_LIBRARY = True
# Some Rust build scripts compile C/C++ sources, don't error on warnings for them.
AllowCompilerWarnings()
# And furthermore, don't even show warnings for them, so they don't regress
# the Compiler Warnings build metric
# <https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Automated_Performance_Testing_and_Sheriffing/Build_Metrics#compiler_warnings>.
DisableCompilerWarnings()
if features:
RUST_LIBRARY_FEATURES = features
- if target_dir:
- RUST_LIBRARY_TARGET_DIR = target_dir
-
if output_category:
RUST_LIBRARY_OUTPUT_CATEGORY = output_category
@template
def SharedLibrary(name, output_category=None):
'''Template for shared libraries.'''
Library(name)
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -524,17 +524,17 @@ class TreeMetadataEmitter(LoggingMixin):
context)
crate_type = crate_type[0]
if crate_type != 'staticlib':
raise SandboxValidationError(
'crate-type %s is not permitted for %s' % (crate_type, libname),
context)
- cargo_target_dir = context.get('RUST_LIBRARY_TARGET_DIR', '.')
+ cargo_target_dir = context.config.topobjdir
dependencies = set(config.get('dependencies', {}).iterkeys())
features = context.get(cls.FEATURES_VAR, [])
unique_features = set(features)
if len(features) != len(unique_features):
raise SandboxValidationError(
'features for %s should not contain duplicates: %s' % (libname, features),
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -832,51 +832,51 @@ class TestRecursiveMakeBackend(BackendTe
env = self._consume('rust-library', RecursiveMakeBackend)
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]
# Strip out computed flags, they're a PITA to test.
if not l.startswith('COMPUTED_')]
expected = [
- 'RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libtest_library.a',
+ 'RUST_LIBRARY_FILE := %s/x86_64-unknown-linux-gnu/release/libtest_library.a' % env.topobjdir,
'CARGO_FILE := $(srcdir)/Cargo.toml',
'CARGO_TARGET_DIR := %s' % env.topobjdir,
]
self.assertEqual(lines, expected)
def test_host_rust_library(self):
"""Test that a Rust library is written to backend.mk correctly."""
env = self._consume('host-rust-library', RecursiveMakeBackend)
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]
# Strip out computed flags, they're a PITA to test.
if not l.startswith('COMPUTED_')]
expected = [
- 'HOST_RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libhostrusttool.a',
+ 'HOST_RUST_LIBRARY_FILE := %s/x86_64-unknown-linux-gnu/release/libhostrusttool.a' % env.topobjdir,
'CARGO_FILE := $(srcdir)/Cargo.toml',
'CARGO_TARGET_DIR := %s' % env.topobjdir,
]
self.assertEqual(lines, expected)
def test_host_rust_library_with_features(self):
"""Test that a host Rust library with features is written to backend.mk correctly."""
env = self._consume('host-rust-library-features', RecursiveMakeBackend)
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]
# Strip out computed flags, they're a PITA to test.
if not l.startswith('COMPUTED_')]
expected = [
- 'HOST_RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libhostrusttool.a',
+ 'HOST_RUST_LIBRARY_FILE := %s/x86_64-unknown-linux-gnu/release/libhostrusttool.a' % env.topobjdir,
'CARGO_FILE := $(srcdir)/Cargo.toml',
'CARGO_TARGET_DIR := %s' % env.topobjdir,
'HOST_RUST_LIBRARY_FEATURES := musthave cantlivewithout',
]
self.assertEqual(lines, expected)
def test_rust_library_with_features(self):
@@ -884,17 +884,17 @@ class TestRecursiveMakeBackend(BackendTe
env = self._consume('rust-library-features', RecursiveMakeBackend)
backend_path = mozpath.join(env.topobjdir, 'backend.mk')
lines = [l.strip() for l in open(backend_path, 'rt').readlines()[2:]
# Strip out computed flags, they're a PITA to test.
if not l.startswith('COMPUTED_')]
expected = [
- 'RUST_LIBRARY_FILE := ./x86_64-unknown-linux-gnu/release/libfeature_library.a',
+ 'RUST_LIBRARY_FILE := %s/x86_64-unknown-linux-gnu/release/libfeature_library.a' % env.topobjdir,
'CARGO_FILE := $(srcdir)/Cargo.toml',
'CARGO_TARGET_DIR := %s' % env.topobjdir,
'RUST_LIBRARY_FEATURES := musthave cantlivewithout',
]
self.assertEqual(lines, expected)
def test_rust_programs(self):
--- a/toolkit/library/gtest/rust/moz.build
+++ b/toolkit/library/gtest/rust/moz.build
@@ -1,10 +1,10 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# 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/.
include('../../rust/gkrust-features.mozbuild')
-RustLibrary('gkrust-gtest', gkrust_features, '../..',
+RustLibrary('gkrust-gtest', gkrust_features,
output_category=None if CONFIG['LINK_GTEST_DURING_COMPILE'] else 'gtest')
--- a/toolkit/library/rust/moz.build
+++ b/toolkit/library/rust/moz.build
@@ -1,17 +1,17 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# 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/.
include('gkrust-features.mozbuild')
-RustLibrary('gkrust', gkrust_features, '..')
+RustLibrary('gkrust', gkrust_features)
# Target directory doesn't matter a lot here, since we can't share panic=abort
# compilation artifacts with gkrust.
RUST_TESTS = [
'selectors',
'servo_arc',
'stylo_tests',
]