Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "objects" support to Rust targets #14031

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions docs/markdown/snippets/rust-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
== `objects` added correctly to Rust executables ==

Any objects included in a Rust executable were previously ignored. They
are now added correctly.
10 changes: 10 additions & 0 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ def relpath(todir: str, fromdir: str) -> str:
return os.path.relpath(os.path.join('dummyprefixdir', todir),
os.path.join('dummyprefixdir', fromdir))

def get_compiler_order_deps(self, target: build.BuildTarget, compiler: Compiler) -> T.List[str]:
return [
os.path.join(self.get_target_dir(lt), lt.get_filename())
for lt in compiler.get_extra_order_deps(target)
]

def get_fortran_order_deps(self, deps: T.List[build.BuildTarget]) -> T.List[File]:
return [File(True, *os.path.split(self.get_target_filename(t))) for t in deps
if t.uses_fortran()]

def flatten_object_list(self, target: build.BuildTarget, proj_dir_to_build_root: str = ''
) -> T.Tuple[T.List[str], T.List[build.BuildTargetTypes]]:
obj_list, deps = self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root)
Expand Down
183 changes: 87 additions & 96 deletions mesonbuild/backend/ninjabackend.py

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

if T.TYPE_CHECKING:
from .. import coredata
from ..build import BuildTarget, DFeatures
from ..build import BuildTarget, BuildTargetTypes, DFeatures

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.compilers.

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, a

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
, as the
definition
of DFeatures occurs after the cyclic
import
of mesonbuild.compilers.compilers.
'DFeatures' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.compilers
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
Expand Down Expand Up @@ -1218,6 +1218,9 @@
def module_name_to_filename(self, module_name: str) -> str:
raise EnvironmentException(f'{self.id} does not implement module_name_to_filename')

def get_extra_order_deps(self, target: BuildTarget) -> T.Iterable[BuildTargetTypes]:
return []

def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
"""Arguments to pass the compiler and/or linker for checks.

Expand Down
11 changes: 11 additions & 0 deletions mesonbuild/compilers/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import typing as T
import functools
import itertools
import os

from .. import options
from .. import mesonlib
from .compilers import (

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.fortran.
clike_debug_args,

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.fortran.
Compiler,

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'CompileCheckMode' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of CompileCheckMode occurs after the cyclic
import
of mesonbuild.compilers.fortran.
CompileCheckMode,
)
from .mixins.clike import CLikeCompiler
Expand All @@ -27,6 +28,7 @@
)

if T.TYPE_CHECKING:
from ..build import BuildTarget, BuildTargetTypes

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTarget' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTarget occurs after the cyclic
import
of mesonbuild.compilers.fortran.

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
'BuildTargetTypes' may not be defined if module
mesonbuild.build
is imported before module
mesonbuild.compilers.fortran
, as the
definition
of BuildTargetTypes occurs after the cyclic
import
of mesonbuild.compilers.fortran.
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
from ..dependencies import Dependency
from ..envconfig import MachineInfo
Expand Down Expand Up @@ -80,6 +82,15 @@
def get_module_outdir_args(self, path: str) -> T.List[str]:
return ['-module', path]

# Fortran is a bit weird (again). When you link against a library, just compiling a source file
# requires the mod files that are output when single files are built. To do this right we would need to
# scan all inputs and write out explicit deps for each file. That is too slow and too much effort so
# instead just have an ordered dependency on the library. This ensures all required mod files are created.
# The real deps are then detected via dep file generation from the compiler. This breaks on compilers that
# produce incorrect dep files but such is life.
def get_extra_order_deps(self, target: BuildTarget) -> T.Iterable[BuildTargetTypes]:
return itertools.chain(target.link_targets, target.link_whole_targets)

def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
build_dir: str) -> T.List[str]:
for idx, i in enumerate(parameter_list):
Expand Down
42 changes: 38 additions & 4 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .. import options
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged
from ..options import OptionKey
from .compilers import Compiler, clike_debug_args

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.
'Compiler' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of Compiler occurs after the cyclic
import
of mesonbuild.compilers.rust.

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.
'clike_debug_args' may not be defined if module
mesonbuild.compilers.compilers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of clike_debug_args occurs after the cyclic
import
of mesonbuild.compilers.rust.

if T.TYPE_CHECKING:
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
Expand Down Expand Up @@ -170,7 +170,10 @@
self.native_static_libs = [i for i in match.group(1).split() if i not in exclude]

def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return ['--dep-info', outfile]
return ['--emit', f'dep-info={outfile}']

def get_output_args(self, outputname: str) -> T.List[str]:
return ['--emit', f'link={outputname}']

@functools.lru_cache(maxsize=None)
def get_sysroot(self) -> str:
Expand All @@ -196,6 +199,20 @@
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return rust_optimization_args[optimization_level]

def build_rpath_args(self, env: 'Environment', build_dir: str, from_dir: str,
rpath_paths: T.Tuple[str, ...], build_rpath: str,
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
args, to_remove = super().build_rpath_args(env, build_dir, from_dir, rpath_paths,
build_rpath, install_rpath)

# ... but then add rustc's sysroot to account for rustup
# installations
rustc_rpath_args = []
for arg in args:
rustc_rpath_args.append('-C')
rustc_rpath_args.append('link-arg=' + arg + ':' + self.get_target_libdir())
return rustc_rpath_args, to_remove

def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
build_dir: str) -> T.List[str]:
for idx, i in enumerate(parameter_list):
Expand All @@ -208,9 +225,6 @@

return parameter_list

def get_output_args(self, outputname: str) -> T.List[str]:
return ['-o', outputname]

@classmethod
def use_linker_args(cls, linker: str, version: str) -> T.List[str]:
return ['-C', f'linker={linker}']
Expand Down Expand Up @@ -256,6 +270,8 @@

def get_linker_always_args(self) -> T.List[str]:
args: T.List[str] = []
# Rust is super annoying, calling -C link-arg foo does not work, it has
# to be -C link-arg=foo
for a in super().get_linker_always_args():
args.extend(['-C', f'link-arg={a}'])
return args
Expand Down Expand Up @@ -310,3 +326,21 @@
"""

id = 'clippy-driver rustc'


class RustdocTestCompiler(RustCompiler):

"""We invoke Rustdoc to run doctests. Some of the flags
are different from rustc and some (e.g. --emit link) are
ignored."""

id = 'rustdoc --test'

def get_debug_args(self, is_debug: bool) -> T.List[str]:
return []

def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return []

def get_output_args(self, outputname: str) -> T.List[str]:
return []
2 changes: 2 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,8 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs

target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, objs,
self.environment, self.compilers[for_machine], kwargs)
if objs and target.uses_rust():
FeatureNew.single_use('objects in Rust targets', '1.7.0', self.subproject)

self.add_target(name, target)
self.project_args_frozen = True
Expand Down
11 changes: 11 additions & 0 deletions test cases/rust/27 objects/lib1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>
#include "lib1.h"
#include "lib2.h"

void from_lib2(void) {
printf("hello world");
}

void c_func(void) {
from_lib1();
}
4 changes: 4 additions & 0 deletions test cases/rust/27 objects/lib1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void from_lib2(void);
void c_func(void);
8 changes: 8 additions & 0 deletions test cases/rust/27 objects/lib2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>
#include "lib1.h"
#include "lib2.h"

void from_lib1(void)
{
from_lib2();
}
3 changes: 3 additions & 0 deletions test cases/rust/27 objects/lib2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void from_lib1(void);
9 changes: 9 additions & 0 deletions test cases/rust/27 objects/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extern "C" {
fn c_func();
}

fn main() {
unsafe {
c_func();
}
}
16 changes: 16 additions & 0 deletions test cases/rust/27 objects/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project('staticlib group', 'c', 'rust', meson_version: '>=1.7.0')

lib1 = static_library('lib1', 'lib1.c')
lib2 = static_library('lib2', 'lib2.c')
executable('lib1objs', 'main.rs',
objects: lib1.extract_all_objects(recursive: false),
link_with: lib2)
executable('lib2objs', 'main.rs',
objects: lib2.extract_all_objects(recursive: false),
link_with: lib1)
executable('lib1objs_as_dep', 'main.rs',
dependencies: declare_dependency(objects: lib1.extract_all_objects(recursive: false)),
link_with: lib2)
executable('lib2objs_as_dep', 'main.rs',
dependencies: declare_dependency(objects: lib2.extract_all_objects(recursive: false)),
link_with: lib1)
Loading