Skip to content

Commit

Permalink
rust: add start-group/end-group arguments for libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Dec 19, 2024
1 parent 191fa33 commit 37d1945
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mesonbuild/compilers/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import re
import typing as T

from .. import arglist
from .. import options
from ..linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

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

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

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

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged
from ..options import OptionKey
from .compilers import Compiler, clike_debug_args
from .mixins.clike import GROUP_FLAGS

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

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

if T.TYPE_CHECKING:
from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
Expand Down Expand Up @@ -62,6 +65,33 @@ def get_rustup_run_and_args(exelist: T.List[str]) -> T.Optional[T.Tuple[T.List[s
except StopIteration:
return None


class RustcCompilerArgs(arglist.CompilerArgs):

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'CompilerArgs' may not be defined if module
mesonbuild.arglist
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompilerArgs occurs after the cyclic
import
of mesonbuild.compilers.rust.
def to_native_inplace(self):
# Check if we need to add --start/end-group for circular dependencies
# between static libraries, and for recursively searching for symbols
# needed by static libraries that are provided by object files or
# shared libraries.
# This covers all ld.bfd, ld.gold, ld.gold, and xild on Linux, which
# all act like (or are) gnu ld
# TODO: this could probably be added to the DynamicLinker instead
if isinstance(self.compiler.linker, (GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker)):
group_start = -1
group_end = -1
for i, each in enumerate(self):
if not GROUP_FLAGS.search(each):
continue
group_end = i
if group_start < 0:
# First occurrence of a library
group_start = i
# Only add groups if there are multiple libraries.
if group_end > group_start >= 0:
# Last occurrence of a library
self.insert(group_end + 1, '-Clink-arg=-Wl,--end-group')
self.insert(group_start, '-Clink-arg=-Wl,--start-group')


class RustCompiler(Compiler):

# rustc doesn't invoke the compiler itself, it doesn't need a LINKER_PREFIX
Expand Down Expand Up @@ -100,6 +130,10 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic
self.base_options.add(OptionKey('b_vscrt'))
self.native_static_libs: T.List[str] = []

def compiler_args(self, args: T.Optional[T.Iterable[str]] = None) -> RustcCompilerArgs:
# This is correct, mypy just doesn't understand co-operative inheritance
return RustcCompilerArgs(self, args)

def needs_static_linker(self) -> bool:
return False

Expand Down

0 comments on commit 37d1945

Please sign in to comment.